public class Tokens extends Object
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.
Modifier and Type | Field and Description |
---|---|
static Token |
NONE_TOKEN
Token representing "none" information.
|
static Token |
NULL_TOKEN
Token representing "null" / "empty token".
|
Constructor and Description |
---|
Tokens() |
Modifier and Type | Method and Description |
---|---|
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). |
public static final Token NULL_TOKEN
public static final Token NONE_TOKEN
public static Token get(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
- Copyright © 2012 AMIS research group, Faculty of Mathematics and Physics, Charles University in Prague, Czech Republic. All Rights Reserved.