Class StringNode
- All Implemented Interfaces:
Cloneable,ITreeNode<AbstractNode>
The default string representation of a string node begins and ends with quotation marks, between which are zero or more literal characters or escape sequences. Within the quotation marks, the following characters must be escaped:
U+0022 :quotation mark ("),U+005C :reverse solidus (\),- a control character in the range
U+0000toU+001Finclusive.
An escape sequence consists of a prefix (a reverse solidus, '\', U+005C) followed by either a single character or,
for a Unicode escape, a 'u' and four hexadecimal-digit characters; see escape(CharSequence).
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final charThe character that denotes the end of the string representation of a string node.protected static final char[][]Mappings from literal characters to their corresponding characters in an escape sequence.static final StringThe string with which an escape sequence begins.static final charThe character with which an escape sequence begins.static final char[]Hexadecimal-digit characters.static final charThe character that denotes the start of the string representation of a string node.static final NodeTypeThe type of a string node.static final charThe character that denotes a Unicode escape sequence when it follows the escape prefix. -
Constructor Summary
ConstructorsConstructorDescriptionStringNode(String value) Creates a new instance of a string node that has no parent and has the specified value.StringNode(AbstractNode parent, String value) Creates a new instance of a string node that has the specified parent and value. -
Method Summary
Modifier and TypeMethodDescriptionstatic StringcharToUnicodeHex(char ch) Returns a representation of the Unicode value of the specified character as a string of four hexadecimal-digit characters.clone()Creates and returns a copy of this string node that has no parent.booleanReturnstrueif the specified object is an instance ofStringNodeand it has the same value as this string node.static Stringescape(CharSequence seq) Transforms the specified character sequence to a string, replacing each occurrence of one of the following characters with an escape sequence, and returns the resulting string: a quotation mark ("), a reverse solidus (\), a character outside the range U+0020 to U+007E inclusive.static Stringescape(CharSequence seq, boolean printableAsciiOnly) Transforms the specified character sequence to a string, replacing each occurrence of one of the following characters with an escape sequence, and returns the resulting string: a quotation mark ("), a reverse solidus (\), a character in the range U+0000 to U+001F inclusive, a character in the range U+007F to U+009F inclusive, optionally, a character whose code is greater than or equal to U+00A0.static StringCallsescape(CharSequence)on the specified character sequence, encloses the returned string in quotation marks and returns the resulting string.static StringescapeAndQuote(CharSequence seq, boolean printableAsciiOnly) Callsescape(CharSequence, boolean)on the specified character sequence, encloses the returned string in quotation marks and returns the resulting string.getType()Returns the type of this node.getValue()Returns the value of this string node.inthashCode()Returns the hash code of this string node.booleanReturnstrueif this node can contain other nodes.static String[]nodesToArray(Collection<? extends StringNode> nodes) Returns an array whose elements are the values of the specified string nodes, with the order of the elements preserved.nodesToList(Iterable<? extends StringNode> nodes) Returns a list whose elements are the values of the specified string nodes, with the order of the elements preserved.toString()Returns a string representation of this string node.toString(boolean printableAsciiOnly) Returns a string representation of this node whose characters may optionally be escaped where necessary so that the returned string contains only printable characters from the US-ASCII character encoding.static StringunicodeEscape(char ch) Returns the Unicode escape sequence of the specified character.static List<StringNode> valuesToNodes(Iterable<String> values) Creates a list of string nodes for the specified values, preserving the order of the elements, and returns the list, which may be used to construct a list node.static List<StringNode> valuesToNodes(String... values) Creates a list of string nodes for the specified values, preserving the order of the elements, and returns the list, which may be used to construct a list node.Methods inherited from class uk.blankaspect.common.basictree.AbstractNode
getChildren, getListIndex, getMapKey, getParent, isRoot, setParent
-
Field Details
-
START_CHAR
public static final char START_CHARThe character that denotes the start of the string representation of a string node.- See Also:
-
END_CHAR
public static final char END_CHARThe character that denotes the end of the string representation of a string node.- See Also:
-
ESCAPE_PREFIX_CHAR
public static final char ESCAPE_PREFIX_CHARThe character with which an escape sequence begins.- See Also:
-
ESCAPE_PREFIX
The string with which an escape sequence begins. -
UNICODE_ESCAPE_CHAR
public static final char UNICODE_ESCAPE_CHARThe character that denotes a Unicode escape sequence when it follows the escape prefix.- See Also:
-
HEX_DIGITS
public static final char[] HEX_DIGITSHexadecimal-digit characters. -
TYPE
The type of a string node. -
ESCAPE_MAPPINGS
protected static final char[][] ESCAPE_MAPPINGSMappings from literal characters to their corresponding characters in an escape sequence.
-
-
Constructor Details
-
StringNode
Creates a new instance of a string node that has no parent and has the specified value.- Parameters:
value- the value of the string node.- Throws:
IllegalArgumentException- ifvalueisnull.
-
StringNode
Creates a new instance of a string node that has the specified parent and value.- Parameters:
parent- the parent of the string node.value- the value of the string node.- Throws:
IllegalArgumentException- ifvalueisnull.
-
-
Method Details
-
charToUnicodeHex
Returns a representation of the Unicode value of the specified character as a string of four hexadecimal-digit characters.- Parameters:
ch- the character whose string representation of its Unicode value is desired.- Returns:
- the representation of the Unicode value of
chas a string of four hexadecimal-digit characters.
-
unicodeEscape
Returns the Unicode escape sequence of the specified character.- Parameters:
ch- the character whose Unicode escape sequence is desired.- Returns:
- the Unicode escape sequence of
ch.
-
escape
Transforms the specified character sequence to a string, replacing each occurrence of one of the following characters with an escape sequence, and returns the resulting string:- a quotation mark ("),
- a reverse solidus (\),
- a character outside the range U+0020 to U+007E inclusive.
Each occurrence of the following characters in the input sequence is replaced by the corresponding two-character escape sequence in the rightmost column of the table:
Two-character escape sequences U+0008 backspace \bU+0009 tab \tU+000A line feed \nU+000C form feed \fU+000D carriage return \rU+0022 quotation mark (") \"U+005C reverse solidus (\) \\In addition, each character in the input sequence that lies outside the range U+0020 to U+007E inclusive and is not in the table above is replaced by its six-character Unicode escape sequence,
\unnnn, wherenis a hexadecimal-digit character.Characters in the input sequence that are not escaped appear in the output string unchanged.
The returned string contains only printable characters from the US-ASCII character encoding (ie, characters in the range U+0020 to U+007E inclusive).
- Parameters:
seq- the character sequence that will be escaped.- Returns:
- a string in which each character in
seqthat must be escaped or is greater than U+007E is replaced by an escape sequence.
-
escape
Transforms the specified character sequence to a string, replacing each occurrence of one of the following characters with an escape sequence, and returns the resulting string:- a quotation mark ("),
- a reverse solidus (\),
- a character in the range U+0000 to U+001F inclusive,
- a character in the range U+007F to U+009F inclusive,
- optionally, a character whose code is greater than or equal to U+00A0.
Each occurrence of the following characters in the input sequence is replaced by the corresponding two-character escape sequence in the rightmost column of the table:
Two-character escape sequences U+0008 backspace \bU+0009 tab \tU+000A line feed \nU+000C form feed \fU+000D carriage return \rU+0022 quotation mark (") \"U+005C reverse solidus (\) \\In addition, each control character in the input sequence (that is, each character in the range U+0000 to U+001F inclusive or in the range U+007F to U+009F inclusive) is replaced by its six-character Unicode escape sequence,
\unnnn, wherenis a hexadecimal-digit character.If the
printableAsciiOnlyflag istrue, each character in the input sequence whose code is greater than or equal to U+00A0 is replaced by its six-character Unicode escape sequence. In this case, the returned string will contain only printable characters from the US-ASCII character encoding (ie, characters in the range U+0020 to U+007E inclusive).Characters in the input sequence that are not escaped appear in the output string unchanged.
If the
printableAsciiOnlyflag istrue,- Parameters:
seq- the character sequence that will be escaped.printableAsciiOnly- iftrue, the characters ofseqwill be escaped where necessary so that the returned string contains only printable characters from the US-ASCII character encoding (ie, characters in the range U+0020 to U+007E inclusive).- Returns:
- a string in which each character in
seqthat must be escaped or that satisfies any of the conditions described above is replaced by an escape sequence.
-
escapeAndQuote
Callsescape(CharSequence)on the specified character sequence, encloses the returned string in quotation marks and returns the resulting string.- Parameters:
seq- the character sequence that will be escaped and quoted.- Returns:
- a string consisting of
seqescaped and enclosed in quotation marks.
-
escapeAndQuote
Callsescape(CharSequence, boolean)on the specified character sequence, encloses the returned string in quotation marks and returns the resulting string.- Parameters:
seq- the character sequence that will be escaped and quoted.printableAsciiOnly- iftrue, the characters ofseqwill be escaped where necessary so that the returned string contains only printable characters from the US-ASCII character encoding (ie, characters in the range U+0020 to U+007E inclusive).- Returns:
- a string consisting of
seqescaped and enclosed in quotation marks.
-
valuesToNodes
Creates a list of string nodes for the specified values, preserving the order of the elements, and returns the list, which may be used to construct a list node.- Parameters:
values- the values for which string nodes will be created.- Returns:
- a list of string nodes whose underlying values are
values.
-
valuesToNodes
Creates a list of string nodes for the specified values, preserving the order of the elements, and returns the list, which may be used to construct a list node.- Parameters:
values- the values for which string nodes will be created.- Returns:
- a list of string nodes whose underlying values are
values.
-
nodesToArray
Returns an array whose elements are the values of the specified string nodes, with the order of the elements preserved.- Parameters:
nodes- the string nodes whose values will be extracted into an array.- Returns:
- an array whose elements are the values of
nodes.
-
nodesToList
Returns a list whose elements are the values of the specified string nodes, with the order of the elements preserved.- Parameters:
nodes- the string nodes whose values will be extracted into a list.- Returns:
- a list whose elements are the values of
nodes.
-
getType
Description copied from class:AbstractNodeReturns the type of this node.- Specified by:
getTypein classAbstractNode- Returns:
TYPE.
-
isContainer
public boolean isContainer()Returnstrueif this node can contain other nodes. For a string node, this method always returnsfalse.- Specified by:
isContainerin classAbstractNode- Returns:
false.
-
equals
Returnstrueif the specified object is an instance ofStringNodeand it has the same value as this string node. -
hashCode
public int hashCode()Returns the hash code of this string node. -
clone
Creates and returns a copy of this string node that has no parent.- Overrides:
clonein classAbstractNode- Returns:
- a copy of this string node that has no parent.
-
toString
Returns a string representation of this string node. -
toString
Returns a string representation of this node whose characters may optionally be escaped where necessary so that the returned string contains only printable characters from the US-ASCII character encoding.- Overrides:
toStringin classAbstractNode- Parameters:
printableAsciiOnly- iftrue, the characters of the string representation will be escaped where necessary so that the returned string contains only printable characters from the US-ASCII character encoding (ie, characters in the range U+0020 to U+007E inclusive).- Returns:
- a string representation of this node.
-
getValue
Returns the value of this string node.- Returns:
- the value of this string node.
-