cz.cuni.amis.utils.token
Class Token

Package class diagram package Token
java.lang.Object
  extended by cz.cuni.amis.utils.token.Token
All Implemented Interfaces:
IToken, Serializable

public class Token
extends Object
implements IToken, 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.

Author:
Jimmy
See Also:
Serialized Form

Method Summary
 boolean equals(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.
 String getNameWithIds()
          Returns the name with ids as suffix enclosed inside '[', ']' brackets.
 String getToken()
          Returns an underlying String identifier (might be useful when storing human-readable names).
 int hashCode()
           
 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 Object

equals

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

Overrides:
equals in class Object

getToken

public 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 String getNameWithIds()
Returns the name with ids as suffix enclosed inside '[', ']' brackets.

Returns:

toString

public String toString()
Returns getNameWithIds().

Overrides:
toString in class Object


Copyright © 2013 AMIS research group, Faculty of Mathematics and Physics, Charles University in Prague, Czech Republic. All Rights Reserved.