com.threerings.util
Class Name

java.lang.Object
  extended by com.threerings.io.SimpleStreamableObject
      extended by com.threerings.util.Name
All Implemented Interfaces:
Streamable, Comparable<Name>
Direct Known Subclasses:
BureauAuthName, PeerAuthName

public class Name
extends SimpleStreamableObject
implements Comparable<Name>

Contains the name of an entity. Provides a means by which names can be efficiently loosely compared rather than relying on humans to type things exactly or the challenge of inserting code to normalize names everywhere they are compared.


Nested Class Summary
 
Nested classes/interfaces inherited from interface com.threerings.io.Streamable
Streamable.Closure
 
Field Summary
protected  String _name
          The raw name text.
protected  String _normal
          The normalized name text.
static Name BLANK
          A blank name for use in situations where it is needed.
 
Constructor Summary
Name(String name)
          Creates a name instance with the supplied name.
 
Method Summary
 int compareTo(Name other)
           
 boolean equals(Object other)
           
 String getNormal()
          Returns the normalized version of this name.
 int hashCode()
           
 boolean isBlank()
          Returns true if this name is blank, false if it contains data.
static boolean isBlank(Name name)
          Returns true if this name is null or blank, false if it contains useful data.
 boolean isValid()
          Returns true if this name is valid.
protected  String normalize(String name)
          Returns a normalized version of the supplied name.
protected  Integer overrideCompareTo(Name other)
          Gives this name a chance to override the default comparison in a symmetric fashion.
protected  Boolean overrideEquals(Name other)
          Gives this name a chance to override the default equality comparison in a symmetric fashion.
 String toString()
          Returns the unprocessed name as a string.
 
Methods inherited from class com.threerings.io.SimpleStreamableObject
toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

BLANK

public static final Name BLANK
A blank name for use in situations where it is needed. Note: because names are used in distributed applications you cannot assume that a reference check against blank is sufficient. You must use BLANK.equals(targetName).


_name

protected String _name
The raw name text.


_normal

protected transient String _normal
The normalized name text.

Constructor Detail

Name

public Name(String name)
Creates a name instance with the supplied name.

Method Detail

isBlank

public static boolean isBlank(Name name)
Returns true if this name is null or blank, false if it contains useful data. This works on derived classes as well.


getNormal

public String getNormal()
Returns the normalized version of this name.


isValid

public boolean isValid()
Returns true if this name is valid. Derived classes can provide more interesting requirements for name validity than the default which is that it is non-blank.


isBlank

public boolean isBlank()
Returns true if this name is blank, false if it contains data.


toString

public String toString()
Returns the unprocessed name as a string.

Overrides:
toString in class SimpleStreamableObject

hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

public boolean equals(Object other)
Overrides:
equals in class Object

compareTo

public int compareTo(Name other)
Specified by:
compareTo in interface Comparable<Name>

normalize

protected String normalize(String name)
Returns a normalized version of the supplied name. The default implementation is case insensitive.


overrideEquals

protected Boolean overrideEquals(Name other)
Gives this name a chance to override the default equality comparison in a symmetric fashion.

Returns:
the result of the comparison, or null for no override.

overrideCompareTo

protected Integer overrideCompareTo(Name other)
Gives this name a chance to override the default comparison in a symmetric fashion.

Returns:
the result of the comparison, or null for no override.