Class Token
- java.lang.Object
-
- com.attivio.sdk.token.Token
-
- All Implemented Interfaces:
TokenAnnotationSet,java.io.Serializable,java.lang.CharSequence,java.lang.Cloneable,java.lang.Comparable<Token>
public class Token extends java.lang.Object implements java.lang.Comparable<Token>, java.lang.Cloneable, java.lang.CharSequence, java.io.Serializable, TokenAnnotationSet
Represents a Token.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected intendOffsetThe start offset in the source textprotected intstartOffsetThe start offset in the source textprotected java.lang.StringtextThe character data for this token
-
Constructor Summary
Constructors Constructor Description Token(char[] text)Construct a new Token withtext.Token(java.lang.CharSequence text)Construct a new Token withtext.Token(java.lang.String text)Construct a new token withtextToken(java.lang.String text, TokenAnnotation annotation)Construct a new annotated token withtext.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidappend(java.lang.CharSequence value)Appendvalueto the end of this token.booleanbufferEquals(Token token)Return true if this Token's buffer contains the same text astoken.booleanbufferEquals(java.lang.String token)Return true if this Token's buffer contains the same text astoken.charcharAt(int index)Returns the char value at the specified index.Tokenclone()intcompareTo(Token other)intcompareToIgnoreCase(Token other)Case insensitive equivalent to compareTo.booleancontains(char c)Returnstrueif this Token containsc.booleancontainsAnnotation(TokenAnnotation annotation)Returns true if the specified annotation is set.booleancontainsWhitespace()Returnstrueif this Token contains any whitespace.booleancontainsWildcard()Returns true if token contains a wildcard character.static TokencreateElementAttributeToken(java.lang.String key, java.lang.String value)Creates an element attribute token.static TokencreateEndScopeToken(java.lang.String text)Creates an end scope token.static TokencreateStartScopeToken(java.lang.String text)Creates a start scope token.protected booleanequals(Token other, long annotationMask)Compare this token toother.booleanequals(java.lang.Object other)Compares this Token to another object.longgetAnnotations()Get all set token annotations as a bit mask.intgetEndOffset()Get the end offset from the source text for this token.intgetStartOffset()Get the start offset from the source text for this token.java.lang.StringgetText()Get the token text.inthashCode()intindexOf(char ch)Returns the index within this token of the first occurence of the specified character.booleanisMatchAll()Returns true if this token is a single character wildcard '*' query.booleanisScopeEnd()Returns true if this token designates the end of a scope.booleanisScopeStart()Returns true if this token designates the start of a scope.booleanisScopeToken()Returns true if this token designates the start or end of a scope.booleanisSearchTerm()Returnstrueif this token is an standard atomic search term.booleanisSurfaceForm()Returnstrueif this token is a surface token.intlength()Returns the length of this token's text.intoffsetGap(Token previous)Get the offset gap betweenpreviousand this token.voidsetAnnotation(TokenAnnotation annotation)Set a TokenAnnotation.voidsetAnnotations(long mask)Set the token annotations from a bit mask.voidsetEndOffset(int offset)Set the end offset from the source text for this token.voidsetLength(int length)Truncate token text to length.voidsetStartOffset(int offset)Set the start offset from the source text for this token.voidsetText(java.lang.String value)Set the token text.voidsetValue(char[] value)Set the token text tovalue.voidsetValue(char[] value, int start, int end)Sets the token text.voidsetValue(java.lang.CharSequence value)Set the token text tovalue.voidsetValue(java.lang.String value)Set the token text tovalue.voidsetValue(java.lang.String value, int start, int end)Sets the token text to be a substring ofvalue.TokensubSequence(int start, int end)Returns a new character sequence that is a subsequence of this sequence.TokentoLowerCase()Convert all characters in this Token to be LowerCased.PhrasetoPhrase()Convert this token into a suitable Phrase query.PhrasetoPhrase(int offsetBase)Convert this token into a suitable Phrase query.voidtoQueryString(java.lang.StringBuilder buffer)Encode this Token intobuffersuitable for parsing inside a phrase() operator.java.lang.StringtoString()Returns the String value representation of this Token.TokentoUpperCase()Convert all characters in this Token to be LowerCased.voidunsetAnnotation(TokenAnnotation annotation)Unset a TokenAnnotation.static TokenvalueOf(java.lang.Object value)Return the token representation of an arbitraryvalue.voidwrite(java.lang.StringBuilder buffer)Append this Token's text to the StringBuilder.voidwriteTo(java.lang.StringBuilder buffer)Serialize this Token tobuffer.
-
-
-
Constructor Detail
-
Token
public Token(java.lang.String text)
Construct a new token withtext
-
Token
public Token(char[] text)
Construct a new Token withtext.
-
Token
public Token(java.lang.CharSequence text)
Construct a new Token withtext.
-
Token
public Token(java.lang.String text, TokenAnnotation annotation)Construct a new annotated token withtext.
-
-
Method Detail
-
createStartScopeToken
public static Token createStartScopeToken(java.lang.String text)
Creates a start scope token.- Parameters:
text- the scope name- Returns:
- the created start scope token
-
createEndScopeToken
public static Token createEndScopeToken(java.lang.String text)
Creates an end scope token.- Parameters:
text- the scope name- Returns:
- the created end scope token
-
createElementAttributeToken
public static Token createElementAttributeToken(java.lang.String key, java.lang.String value)
Creates an element attribute token.- Parameters:
key- the attribute namevalue- the attribute value- Returns:
- the created element attribute token
-
toPhrase
public Phrase toPhrase()
Convert this token into a suitable Phrase query.
-
toPhrase
public Phrase toPhrase(int offsetBase)
Convert this token into a suitable Phrase query.
-
isSearchTerm
public boolean isSearchTerm()
Returnstrueif this token is an standard atomic search term.Returns
falseif this is a special term, such as a wildcard, regex, or fuzzy search term.
-
isSurfaceForm
public boolean isSurfaceForm()
Returnstrueif this token is a surface token.
-
getAnnotations
public long getAnnotations()
Get all set token annotations as a bit mask.- Specified by:
getAnnotationsin interfaceTokenAnnotationSet
-
offsetGap
public int offsetGap(Token previous)
Get the offset gap betweenpreviousand this token.NOTE: if this Token or the
previoustoken do not contain offsets,1is returned.NOTE: Returns
0ifpreviousisnull.
-
setAnnotations
public void setAnnotations(long mask)
Set the token annotations from a bit mask.- Specified by:
setAnnotationsin interfaceTokenAnnotationSet
-
setAnnotation
public void setAnnotation(TokenAnnotation annotation)
Set a TokenAnnotation.- Specified by:
setAnnotationin interfaceTokenAnnotationSet
-
containsAnnotation
public boolean containsAnnotation(TokenAnnotation annotation)
Returns true if the specified annotation is set.- Specified by:
containsAnnotationin interfaceTokenAnnotationSet
-
unsetAnnotation
public void unsetAnnotation(TokenAnnotation annotation)
Unset a TokenAnnotation.- Specified by:
unsetAnnotationin interfaceTokenAnnotationSet
-
isScopeToken
public boolean isScopeToken()
Returns true if this token designates the start or end of a scope.
-
isScopeStart
public boolean isScopeStart()
Returns true if this token designates the start of a scope.
-
isScopeEnd
public boolean isScopeEnd()
Returns true if this token designates the end of a scope.
-
containsWildcard
public boolean containsWildcard()
Returns true if token contains a wildcard character.Wildcard Characters:
- asterisk - '*' - match 0 or more characters.
- question mark - '?' - match any single character.
- full width asterisk - '*' - treated same as asterisk.
- Returns:
- true if token contains a wildcard character
-
isMatchAll
public boolean isMatchAll()
Returns true if this token is a single character wildcard '*' query.
-
containsWhitespace
public boolean containsWhitespace()
Returnstrueif this Token contains any whitespace.
-
contains
public boolean contains(char c)
Returnstrueif this Token containsc.
-
getStartOffset
public int getStartOffset()
Get the start offset from the source text for this token.
-
setStartOffset
public void setStartOffset(int offset)
Set the start offset from the source text for this token.
-
getEndOffset
public int getEndOffset()
Get the end offset from the source text for this token.The end offset is actually 1 past the final column of source text. To get the source text, you should do the following:
String tokenSource = sourceText.substring(token.getStartOffset(), token.getEndOffset());
-
setEndOffset
public void setEndOffset(int offset)
Set the end offset from the source text for this token.
-
indexOf
public int indexOf(char ch)
Returns the index within this token of the first occurence of the specified character.- Parameters:
ch- a character (Unicode code point).- Returns:
- the index of the first occurrence of the character this token, or -1 if the character does not occur.
-
setValue
public void setValue(char[] value)
Set the token text tovalue.
-
setValue
public void setValue(java.lang.String value)
Set the token text tovalue.
-
setLength
public void setLength(int length)
Truncate token text to length.
-
setValue
public void setValue(java.lang.CharSequence value)
Set the token text tovalue.
-
append
public void append(java.lang.CharSequence value)
Appendvalueto the end of this token.
-
setValue
public void setValue(char[] value, int start, int end)Sets the token text.- Parameters:
value- source array containing token textstart- the start index in value to start copying fromend- the end index in value to stop copying at (not inclusive)
-
setValue
public void setValue(java.lang.String value, int start, int end)Sets the token text to be a substring ofvalue.- Parameters:
value- source value containing token text.start- the start index in value to start copying fromend- the end index in value to stop copying at (not inclusive)
-
getText
public java.lang.String getText()
Get the token text.
-
setText
public void setText(java.lang.String value)
Set the token text.
-
subSequence
public Token subSequence(int start, int end)
Returns a new character sequence that is a subsequence of this sequence.- Specified by:
subSequencein interfacejava.lang.CharSequence- Parameters:
start- the begin index, inclusive.end- the end index, exclusive.- Returns:
- the specified subsequence.
-
charAt
public char charAt(int index)
Returns the char value at the specified index.An index ranges from 0 to length() - 1. The first char value of the sequence is at index 0, the next at index 1, and so on, as for array indexing.
- Specified by:
charAtin interfacejava.lang.CharSequence- Parameters:
index- the index of the char value to be returned- Returns:
- the specified char value
-
length
public int length()
Returns the length of this token's text.- Specified by:
lengthin interfacejava.lang.CharSequence
-
toString
public java.lang.String toString()
Returns the String value representation of this Token.NOTE: token.equals( token.toString() ) will always equal true.
- Specified by:
toStringin interfacejava.lang.CharSequence- Overrides:
toStringin classjava.lang.Object- Returns:
- the string representation of this Token
-
bufferEquals
public boolean bufferEquals(Token token)
Return true if this Token's buffer contains the same text astoken.
-
bufferEquals
public boolean bufferEquals(java.lang.String token)
Return true if this Token's buffer contains the same text astoken.
-
equals
public boolean equals(java.lang.Object other)
Compares this Token to another object.- Overrides:
equalsin classjava.lang.Object- Parameters:
other- The object to compare this Token against.- Returns:
- True if the given object represents a Token that is equal to this Token, or a String that is lexigraphically equivalent to this Token.
-
equals
protected boolean equals(Token other, long annotationMask)
Compare this token toother.Only compare token annotations set on
annotationMask.
-
compareTo
public int compareTo(Token other)
- Specified by:
compareToin interfacejava.lang.Comparable<Token>
-
compareToIgnoreCase
public int compareToIgnoreCase(Token other)
Case insensitive equivalent to compareTo.NOTE: this method does not take Locale into account. To be truely Locale Aware, you should toString() this Token and use a java.text.Collator.
-
toLowerCase
public Token toLowerCase()
Convert all characters in this Token to be LowerCased.WARNING: this method is NOT Locale-aware.
- Returns:
- a reference to this Token.
-
toUpperCase
public Token toUpperCase()
Convert all characters in this Token to be LowerCased.WARNING: this method is NOT Locale-aware.
- Returns:
- a reference to this Token.
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
clone
public Token clone()
- Overrides:
clonein classjava.lang.Object
-
write
public void write(java.lang.StringBuilder buffer)
Append this Token's text to the StringBuilder.
-
toQueryString
public void toQueryString(java.lang.StringBuilder buffer)
Encode this Token intobuffersuitable for parsing inside a phrase() operator.
-
writeTo
public void writeTo(java.lang.StringBuilder buffer)
Serialize this Token tobuffer.
-
valueOf
public static Token valueOf(java.lang.Object value)
Return the token representation of an arbitraryvalue.
-
-