|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Object | +--com.g11ntoolkit.token.Token
A token is a unique id for an extracted string.
The token is put in place of the string so we know where the string came from. It is used later to put the string back where it belongs. A token is made up of a prefix and a number. This generally makes each string in a set of files unique. This is good because sets of strings may be combined to make translation easier and more efficient.
The prefix usually is some string which will help in identify the source of the string (it could be the file name which contains the string). This can sometimes provide context for translation. It can also make finding the string easier if it is needed after the extract is done.
The number is just a sequence number. The number can be reset when the prefix is reset. It must be unique within a prefix so that each string is uniquely identified.
A token may be decorated with some unique string in front of it and behind it. A decorated token can make it easier to find the tokens in a tokenized file. The default decoration for tokens is stored in the vars.properties file. You can change it by using the appropriate methods of this class, but, it is best to change it in the properties file. Some higher level tools will rely on the token decoration to identify tokens in the tokenized file. If you change it using the methods on this class then it may make the tokenized file difficult to use. It is a good idea to decide on the decoration, set it in the properties file, and leave it alone.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
See License Agreement.
| Field Summary | |
private java.lang.String |
decoration
The decoration is some unique string which will be placed in front of and behind the token. |
private static java.util.logging.Logger |
log
The log used for all messages from this class. |
private static java.util.ResourceBundle |
mrb
Messages Resource Bundle. |
private int |
tokenNumber
The token number is initialized when the class is instantiated and incremented each time a token is requested. |
private java.lang.String |
tokenPrefix
The token prefix is initialized when the class is instantiated or by the set method. |
private int |
tokenSequenceNumber
A token number to use for the sequence. |
private static java.util.ResourceBundle |
vrb
Variables Resource Bundle. |
private static java.util.ResourceBundle |
xrb
Constants, messages, and variables used by the tools and classes for XML processing. |
| Constructor Summary | |
Token()
Establishes an instance with no initial token prefix information. |
|
Token(java.lang.String possibleToken)
Establishes an instance based on the specified string. |
|
Token(java.lang.String prefix,
int start)
Establishes an instance with a specific token prefix and a specific starting number. |
|
| Method Summary | |
int |
compareTo(java.lang.Object anotherToken)
Shows how the specified Object compares to this Token. |
int |
compareTo(Token anotherToken)
Shows how the specified Token compares to this Token. |
void |
debugDump()
Dumps the contents of the object to the console. |
boolean |
equals(java.lang.Object anotherToken)
Tests if the specified Object is equal to this Token. |
boolean |
equals(Token anotherToken)
Tests if the specified Token is equal to this Token. |
java.lang.String |
getDecoratedToken()
Return the current token in the sequence with some decoration in front of and behind it. |
java.lang.String |
getDecoration()
Returns the decoration used on the tokens. |
int |
getNumber()
Returns the current token number. |
java.lang.String |
getPrefix()
Return the token prefix value. |
java.lang.String |
getToken()
Return the current token in the sequence. |
int |
hashCode()
Returns a hash code for this token. |
java.lang.String |
nextDecoratedToken()
Return the next token in the sequence with some decoration in front of and behind it. |
java.lang.String |
nextToken()
Return the next token in the sequence. |
void |
setDecoration(java.lang.String deco)
Sets the decoration to some specified string. |
void |
setParts(java.lang.String wt)
Sets up the two individual parts of the token. |
void |
setPrefix(java.lang.String prefix)
Sets the prefix to some specified string. |
void |
setStartNumber(int start)
Sets the token starting number. |
void |
setToken(java.lang.String possibleToken)
Sets the current token values. |
void |
setToken(java.lang.String possibleToken,
java.lang.String deco)
Sets the current token values. |
java.lang.String |
stripDeco(java.lang.String wt)
Removes the token decorations from a string and returns what is left. |
boolean |
validate(java.lang.String wt)
Validates that the specified string is a token. |
void |
writeXML(java.io.Writer out)
Writes the contents of the object to the specified writer. |
| Methods inherited from class java.lang.Object |
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
private static java.util.logging.Logger log
private static java.util.ResourceBundle vrb
private static java.util.ResourceBundle mrb
private static java.util.ResourceBundle xrb
private java.lang.String tokenPrefix
It is used to give the token some context and to make sure the token ids are unique.
private int tokenNumber
private java.lang.String decoration
This will make the token easier to identify in a file. The default decoration is stored in the vars.properties file. The decoration may be set at any time.
private int tokenSequenceNumber
| Constructor Detail |
public Token()
You must use the set method to set the token prefix before you ask for the first token or all you will get is a number preceded by a dot. This is valid if that is what you want. The token number is started at 0.
public Token(java.lang.String possibleToken)
throws MalformedToken
The string is assumed to be a well formed token with no decoration or with the default (@@) decoration in front of it and behind it.
possibleToken - a String that contains the proposed token value
MalformedToken - if the proposed string is not a valid token
public Token(java.lang.String prefix,
int start)
prefix - a String containing the desired prefixstart - int containing the desired token number| Method Detail |
public void setPrefix(java.lang.String prefix)
Can be used to override the prefix set in the constructor.
prefix - a String containing the desired prefixgetPrefix()public void setStartNumber(int start)
Can be used to change the next number to be used at any time. The number set as the starting token number will be the number used by the nextToken method on the next call to it.
start - an int containing the desired token numberpublic java.lang.String getDecoration()
setDecoration(java.lang.String)public void setDecoration(java.lang.String deco)
Can be used to override what is set in the constructor.
Warning: use this method with caution. If you change the token decoration from what is shown in the properties file, FileDetok may not be able to detokenize the file.
deco - a String containing the decoration string to usegetDecoration()public java.lang.String getPrefix()
setPrefix(java.lang.String)public java.lang.String nextToken()
It increments the current token number then returns the value.
public java.lang.String getToken()
This does not increment the token number.
setToken(java.lang.String)
public void setToken(java.lang.String possibleToken)
throws MalformedToken
The specified possible token is assumed to be a well formed token with no decoration or with the default (found in the vars.properties file) decoration in front of it and behind it.
possibleToken - a String that contains the proposed token value
MalformedToken - if the proposed string is not a valid tokengetToken(),
nextToken()
public void setToken(java.lang.String possibleToken,
java.lang.String deco)
throws MalformedToken
The specified possible token is assumed to be a well formed token with the specified decoration in front of it and behind it.
Warning: use this method with caution. If you change the token decoration from what is shown in the properties file, FileDetok may not be able to detokenize the file.
possibleToken - a String that contains the proposed token valuedeco - a String containing the decoration string to use
MalformedToken - if the proposed string is not a valid tokengetToken(),
nextToken(),
getDecoration()public java.lang.String nextDecoratedToken()
The decoration is to allow you to identify a token in a file more easily. The decoration is the one specified in the global decoration variable in front of an behind the token. It increments the current token number then returns the value.
setToken(java.lang.String)public java.lang.String getDecoratedToken()
The decoration is to allow you to identify a token in a file more easily. The decoration is the one specified in the global decoration variable in front of an behind the token. This does not increment the token number.
setToken(java.lang.String)
public boolean validate(java.lang.String wt)
throws MalformedToken
The validation is looking for a well formed token which may or may not have the currently set decoration in front of it or behind it. Any decoration found will be removed before the validation is continued. The validation is to see if the string has two parts, a prefix and a token number separated by a dot. If so, it is valid and we return a true; if not, we return a false.
wt - a String containing the proposed well formed token
MalformedToken - if the proposed string is not a valid tokenstripDeco(java.lang.String),
setParts(java.lang.String)public int compareTo(Token anotherToken)
Token compares to this Token.
anotherToken - a Token object
Token is less than the specified Token, set to 0 if this Token is equal to the specified Token, or set to 1 if this Token is greater than the specified Tokenpublic int compareTo(java.lang.Object anotherToken)
Object compares to this Token.
anotherToken - an Object specifying the object to compare this instance to
Token is less than the specified Token, set to 0 if this Token is equal to the specified Token, set to 1 if this Token is greater than the specified Token, or -2 if the objects can not be comparedpublic boolean equals(Token anotherToken)
Token is equal to this Token.
Equality means that the token prefixes and token numbers are equal. Decorations are ignored.
anotherToken - a Token object specifying the object to compare this instance to
Token and the specified Token are equal or false if they are not equal.public boolean equals(java.lang.Object anotherToken)
Object is equal to this Token.
Equality means that the token prefixes and token numbers are equal. Decorations are ignored.
equals in class java.lang.ObjectanotherToken - an Object specifying the object to compare this instance to
Token and the specified Object are equal or false if they are not equal.equals(com.g11ntoolkit.token.Token)public int getNumber()
public int hashCode()
The hash code for a token is defined as the sum of the hash code for the token prefix and the token number.
hashCode in class java.lang.ObjectToken.public java.lang.String stripDeco(java.lang.String wt)
The decoration must be both at the beginning of and at the end of the possible token before it is assumed to be decoration.
wt - a String containing the token
public void setParts(java.lang.String wt)
throws MalformedToken
Sets the global variables tokenPrefix and tokenNumber. Also checks to see that the number is in fact all digits.
wt - a String containing the proposed token
MalformedToken - if the proposed string is not a valid token
public void writeXML(java.io.Writer out)
throws java.io.IOException
out - a Writer to use for the output
java.io.IOException - for any errors detected by the specified Writerpublic void debugDump()
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||