Implement Comparable<Name>. The old compareTo() did funny things if a Name was
being compared with a non-Name but I'm almost certain that never happened and was just Ray being kooky. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4821 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -32,7 +32,7 @@ import com.threerings.io.SimpleStreamableObject;
|
|||||||
* everywhere they are compared.
|
* everywhere they are compared.
|
||||||
*/
|
*/
|
||||||
public class Name extends SimpleStreamableObject
|
public class Name extends SimpleStreamableObject
|
||||||
implements Comparable
|
implements Comparable<Name>
|
||||||
{
|
{
|
||||||
/** A blank name for use in situations where it is needed.
|
/** A blank name for use in situations where it is needed.
|
||||||
* <em>Note:</em> because names are used in distributed applications
|
* <em>Note:</em> because names are used in distributed applications
|
||||||
@@ -40,6 +40,15 @@ public class Name extends SimpleStreamableObject
|
|||||||
* sufficient. You must use <code>BLANK.equals(targetName)</code>. */
|
* sufficient. You must use <code>BLANK.equals(targetName)</code>. */
|
||||||
public static final Name BLANK = new Name("");
|
public static final Name BLANK = new Name("");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if this name is null or blank, false if it contains
|
||||||
|
* useful data. This works on derived classes as well.
|
||||||
|
*/
|
||||||
|
public static boolean isBlank (Name name)
|
||||||
|
{
|
||||||
|
return (name == null || name.toString().equals(BLANK.toString()));
|
||||||
|
}
|
||||||
|
|
||||||
/** Creates a blank instance for unserialization. */
|
/** Creates a blank instance for unserialization. */
|
||||||
public Name ()
|
public Name ()
|
||||||
{
|
{
|
||||||
@@ -95,13 +104,13 @@ public class Name extends SimpleStreamableObject
|
|||||||
return _name;
|
return _name;
|
||||||
}
|
}
|
||||||
|
|
||||||
// documentation inherited
|
@Override // from Object
|
||||||
public int hashCode ()
|
public int hashCode ()
|
||||||
{
|
{
|
||||||
return getNormal().hashCode();
|
return getNormal().hashCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
// documentation inherited
|
@Override // from Object
|
||||||
public boolean equals (Object other)
|
public boolean equals (Object other)
|
||||||
{
|
{
|
||||||
if (other != null) {
|
if (other != null) {
|
||||||
@@ -116,23 +125,10 @@ public class Name extends SimpleStreamableObject
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// documentation inherited
|
// from interface Comparable<Name>
|
||||||
public int compareTo (Object o)
|
public int compareTo (Name other)
|
||||||
{
|
{
|
||||||
if (o instanceof Name) {
|
return getNormal().compareTo(other.getNormal());
|
||||||
return getNormal().compareTo(((Name)o).getNormal());
|
|
||||||
} else {
|
|
||||||
return getClass().getName().compareTo(o.getClass().getName());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns true if this name is null or blank, false if it contains
|
|
||||||
* useful data. This works on derived classes as well.
|
|
||||||
*/
|
|
||||||
public static boolean isBlank (Name name)
|
|
||||||
{
|
|
||||||
return (name == null || name.toString().equals(BLANK.toString()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user