cz.cuni.amis.utils.token
Class Token

java.lang.Object
  extended by cz.cuni.amis.utils.token.Token
All Implemented Interfaces:
IToken, java.io.Serializable

public class Token
extends java.lang.Object
implements IToken, java.io.Serializable

Represents a String that can be used inside Map as keys or Sets as equals(Object) has O(1) time complexity which is much better when compared to the O(N) time complexity of String.equals(Object).

Note that you can't instantiate this token, instead use Tokens.get(long) or Tokens.get(String) which is THREAD-SAFE.

The object is suitable for serialization / deserialization, even sending the object between JVM won't broke anything as it has Token#readObject() implemented the way that ensures that two same name won't receive different ids.

See Also:
Serialized Form

Method Summary
 boolean equals(java.lang.Object obj)
          Actually the implementation is as good as it can be, containing early-success checking + NPE-proofed.
 long[] getIds()
          Returns unique ID of the token.
 java.lang.String getNameWithIds()
          Returns the name with ids as suffix enclosed inside '[', ']' brackets.
 java.lang.String getToken()
          Returns an underlying String identifier (might be useful when storing human-readable names).
 int hashCode()
           
 java.lang.String toString()
          Returns getNameWithIds().
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Method Detail

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

equals

public boolean equals(java.lang.Object obj)
Actually the implementation is as good as it can be, containing early-success checking + NPE-proofed.

Overrides:
equals in class java.lang.Object

getToken

public java.lang.String getToken()
Returns an underlying String identifier (might be useful when storing human-readable names).

Specified by:
getToken in interface IToken

getIds

public long[] getIds()
Returns unique ID of the token. No two different instances has the same ids.

Specified by:
getIds in interface IToken

getNameWithIds

public java.lang.String getNameWithIds()
Returns the name with ids as suffix enclosed inside '[', ']' brackets.

Returns:

toString

public java.lang.String toString()
Returns getNameWithIds().

Overrides:
toString in class java.lang.Object