Package cn.sliew.milky.common.parse
Class Token
- java.lang.Object
-
- cn.sliew.milky.common.parse.Token
-
- All Implemented Interfaces:
Serializable,Cloneable
public class Token extends Object implements Cloneable, Serializable
- See Also:
- Serialized Form
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Tokenappend(TokenFormat.Segment segment)Tokenappend(String segmentType, String value)Construct a newTokenby appending a newTokenFormat.Segment, based on the suppliedsegmentTypeandvalue, to the end of thisToken.protected Objectclone()booleanequals(Object o)TokenFormat.SegmentgetLastSegment()Get the lastTokenFormat.Segmentof thisToken.List<TokenFormat.Segment>getSegments()Get the immutable list of segments that make up thisToken.inthashCode()booleanhasPrefix(Token potentialPrefix)Determine if the suppliedTokenis a prefix for thisToken.static Tokenparse(String token)Parse aTokenfrom the supplied string representation using the default format.TokenremoveLastSegment()static Tokenroot(String segmentType, String value)Create a root Token from the suppliedsegmentTypeandvalueusing the default format.StringtoString()Generate the unique, formatted string representation of thisTokenusing the configuredTokenFormat.
-
-
-
Method Detail
-
parse
public static Token parse(String token) throws TokenParseException
Parse aTokenfrom the supplied string representation using the default format.- Parameters:
token- the string representation to parse; nevernullor blank- Returns:
- a properly constructed
Token - Throws:
TokenParseException- if the string cannot be parsed
-
root
public static Token root(String segmentType, String value)
Create a root Token from the suppliedsegmentTypeandvalueusing the default format.- Parameters:
segmentType- the segment type; nevernullor blankvalue- the value; nevernullor blank
-
getSegments
public final List<TokenFormat.Segment> getSegments()
Get the immutable list of segments that make up thisToken.
-
append
public final Token append(String segmentType, String value)
Construct a newTokenby appending a newTokenFormat.Segment, based on the suppliedsegmentTypeandvalue, to the end of thisToken.This
Tokenwill not be modified.Neither the
segmentTypenor thevaluemay contain any of the special characters used for constructing the string representation of thisToken.- Parameters:
segmentType- the type of the segment; nevernullor blankvalue- the value of the segment; nevernullor blank
-
append
public final Token append(TokenFormat.Segment segment)
Construct a newTokenby appending a newTokenFormat.Segmentto the end of thisToken.This
Tokenwill not be modified.- Parameters:
segment- the segment to be appended; nevernull
-
hasPrefix
public boolean hasPrefix(Token potentialPrefix)
Determine if the suppliedTokenis a prefix for thisToken.- Parameters:
potentialPrefix- theTokento be checked; nevernull
-
removeLastSegment
public Token removeLastSegment()
Construct a newTokenand removing the lastTokenFormat.Segmentof thisToken.This
Tokenwill not be modified.- Returns:
- a new
Token; nevernull
-
getLastSegment
public TokenFormat.Segment getLastSegment()
Get the lastTokenFormat.Segmentof thisToken.- Returns:
- the last
Segment; nevernull
-
clone
protected Object clone() throws CloneNotSupportedException
- Overrides:
clonein classObject- Throws:
CloneNotSupportedException
-
toString
public String toString()
Generate the unique, formatted string representation of thisTokenusing the configuredTokenFormat.
-
-