|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object cz.cuni.amis.utils.token.Tokens
public class Tokens
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.
Field Summary | |
---|---|
static Token |
NULL_TOKEN
Token representing "null" / "empty token". |
Constructor Summary | |
---|---|
Tokens()
|
Method Summary | |
---|---|
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(java.lang.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 |
---|
public static final Token NULL_TOKEN
Constructor Detail |
---|
public Tokens()
Method Detail |
---|
public static Token get(java.lang.String tokenStr)
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!
tokenStr
-
public static Token get(long id)
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!
tokenStr
-
public static Token get(double id)
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!
tokenStr
-
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |