cz.cuni.amis.utils.token
Class Tokens

Package class diagram package Tokens
java.lang.Object
  extended by cz.cuni.amis.utils.token.Tokens

public class Tokens
extends Object

Provides a way for string-to-long translation for quick handling of "String" keys inside maps or sets. The method get(long) or get(String) will return you an instance of Token that has Token.hashCode() and Token.equals(Object) correctly specified to be quick (i.e., O(1) time complexity agains String's O(n) time complexity).

Also notice that Token is using an array of 'long' (Token.getIds()) to identify itself, i.e., you can never run out of ids for Strings (meaning you may truly allocate an arbitrary number of tokens via get methods ... as much as JVM heap allows you to).

THREAD-SAFE! You do not need to worry that two threads will request the same token and be provided with different Token instances.

Author:
Jimmy

Field Summary
static Token NONE_TOKEN
          Token representing "none" information.
static Token NULL_TOKEN
          Token representing "null" / "empty token".
 
Constructor Summary
Tokens()
           
 
Method Summary
static void destroy(Token token)
          Removes 'token' from tokenMap.
static Token get(double id)
          Returns Token of a specified 'id'.
static Token get(long id)
          Returns Token of a specified 'id'.
static Token get(String tokenStr)
          Returns Token with name "tokenStr", do not use NULL_TOKEN string "null" as param 'tokenStr' that represents null tokens (tokens without names).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NULL_TOKEN

public static final Token NULL_TOKEN
Token representing "null" / "empty token".


NONE_TOKEN

public static final Token NONE_TOKEN
Token representing "none" information.

Constructor Detail

Tokens

public Tokens()
Method Detail

get

public static Token get(String tokenStr)
Returns Token with name "tokenStr", do not use NULL_TOKEN string "null" as param 'tokenStr' that represents null tokens (tokens without names).

Notice that even though the method is not synchronized, the creation of Token is.

THREAD-SAFE!

Parameters:
tokenStr -
Returns:

get

public static Token get(long id)
Returns Token of a specified 'id'. Note that 'id' is actual translated into String first, meaning that (long)1 and (String)"1" is the same token.

Notice that even though the method is not synchronized, the creation of Token is.

THREAD-SAFE!

Parameters:
tokenStr -
Returns:

get

public static Token get(double id)
Returns Token of a specified 'id'. Note that 'id' is actual translated into String first, meaning that (double)1 and (String)"1" is the same token (but watch out for actual translation of double to string!).

Notice that even though the method is not synchronized, the creation of Token is.

THREAD-SAFE!

Parameters:
tokenStr -
Returns:

destroy

public static void destroy(Token token)
Removes 'token' from tokenMap.

Parameters:
token -


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