com.virtuosotechnologies.lib.util
Class StringID

java.lang.Object
  extended bycom.virtuosotechnologies.lib.util.StringID
All Implemented Interfaces:
Cloneable, Comparable, Serializable

public final class StringID
extends Object
implements Comparable, Cloneable, Serializable

A immutable string ID class. This is basically a numbering system of natural numbers expressed as strings of lower-case letters. There is no upper limit to the numbering.

The representation is NOT base-26! It's kind of similar, but not the same. For example, the next value after "z" is "aa". Clients should generally use the getNext() method and the implementation of Comparable rather than trying to interpret the value themselves.

See Also:
Serialized Form

Constructor Summary
StringID()
          Constructs a new id with value ""
StringID(long value)
          Constructs a new id with a nonnegative integer value.
StringID(String value)
          Constructs a new id with the given value
StringID(StringID value)
          Constructs a new id with the given value
 
Method Summary
 Object clone()
          Implementation of Object.clone().
 int compareTo(Object obj)
          Implementation of Comparable.compareTo().
 boolean equals(Object obj)
          Implementation of Object.equals().
 StringID getNext()
          Gets the next id
 String getValue()
          Returns the current value
 int hashCode()
          Implementation of Object.hashCode().
static boolean isWellFormed(String str)
          Determines whether a string is a well-formed value for StringID
 char[] toCharArray()
          Returns a copy of the character array
 String toString()
          Implementation of Object.toString().
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

StringID

public StringID()
Constructs a new id with value ""


StringID

public StringID(String value)
Constructs a new id with the given value

Parameters:
value - initial value
Throws:
IllegalArgumentException - value was badly formatted

StringID

public StringID(StringID value)
Constructs a new id with the given value

Parameters:
value - initial value

StringID

public StringID(long value)
Constructs a new id with a nonnegative integer value. This value will be translated to the StringID equivalent.

Parameters:
value - initial value
Method Detail

isWellFormed

public static boolean isWellFormed(String str)
Determines whether a string is a well-formed value for StringID

Parameters:
str - string to test
Returns:
true if the string is well-formed, or false if not.

toCharArray

public char[] toCharArray()
Returns a copy of the character array

Returns:
character array

getValue

public String getValue()
Returns the current value

Returns:
value

getNext

public StringID getNext()
Gets the next id


compareTo

public int compareTo(Object obj)
Implementation of Comparable.compareTo().

Specified by:
compareTo in interface Comparable
Parameters:
obj - object to compare with
Returns:
-1 if this < obj, 0 if this == obj, 1 if this > obj

toString

public String toString()
Implementation of Object.toString(). Identical to getString().


equals

public boolean equals(Object obj)
Implementation of Object.equals().


hashCode

public int hashCode()
Implementation of Object.hashCode().

Returns:
hash code integer

clone

public Object clone()
Implementation of Object.clone().