From 9f2a90f0019ab342da893054598d84dcf1d12ae0 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Mon, 10 Sep 2007 17:34:53 +0000 Subject: [PATCH] Implement Comparable. 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 --- src/java/com/threerings/util/Name.java | 34 ++++++++++++-------------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/src/java/com/threerings/util/Name.java b/src/java/com/threerings/util/Name.java index f156807ba..4b67de8b0 100644 --- a/src/java/com/threerings/util/Name.java +++ b/src/java/com/threerings/util/Name.java @@ -32,7 +32,7 @@ import com.threerings.io.SimpleStreamableObject; * everywhere they are compared. */ public class Name extends SimpleStreamableObject - implements Comparable + implements Comparable { /** A blank name for use in situations where it is needed. * Note: because names are used in distributed applications @@ -40,6 +40,15 @@ public class Name extends SimpleStreamableObject * sufficient. You must use BLANK.equals(targetName). */ 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. */ public Name () { @@ -95,13 +104,13 @@ public class Name extends SimpleStreamableObject return _name; } - // documentation inherited + @Override // from Object public int hashCode () { return getNormal().hashCode(); } - // documentation inherited + @Override // from Object public boolean equals (Object other) { if (other != null) { @@ -116,23 +125,10 @@ public class Name extends SimpleStreamableObject return false; } - // documentation inherited - public int compareTo (Object o) + // from interface Comparable + public int compareTo (Name other) { - if (o instanceof Name) { - 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())); + return getNormal().compareTo(other.getNormal()); } /**