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+0000
toU+001F
inclusive.
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
Modifier and TypeFieldDescriptionstatic final char
The 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 String
The string with which an escape sequence begins.static final char
The character with which an escape sequence begins.static final char
The character that denotes the start of the string representation of a string node.static final NodeType
The type of a string node.static final char
The character that denotes a Unicode escape sequence when it follows the escape prefix. -
Constructor Summary
ConstructorDescriptionStringNode
(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 String
charToUnicodeHex
(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.boolean
Returnstrue
if the specified object is an instance ofStringNode
and it has the same value as this string node.static String
escape
(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 String
Callsescape(CharSequence)
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.int
hashCode()
Returns the hash code of this string node.boolean
Returnstrue
if 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.static String
unicodeEscape
(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:
-
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
- ifvalue
isnull
.
-
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
- ifvalue
isnull
.
-
-
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 required.- Returns:
- the representation of the Unicode value of
ch
as 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 required.- 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 \b
U+0009 tab \t
U+000A line feed \n
U+000C form feed \f
U+000D carriage return \r
U+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,
\
u
nnnn
, wheren
is 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
seq
that must be escaped or is greater than U+007E 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
seq
escaped 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:AbstractNode
Returns the type of this node.- Specified by:
getType
in classAbstractNode
- Returns:
TYPE
.
-
isContainer
public boolean isContainer()Returnstrue
if this node can contain other nodes. For a string node, this method always returnsfalse
.- Specified by:
isContainer
in classAbstractNode
- Returns:
false
.
-
equals
Returnstrue
if the specified object is an instance ofStringNode
and 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:
clone
in classAbstractNode
- Returns:
- a copy of this string node that has no parent.
-
toString
Returns a string representation of this string node. -
getValue
Returns the value of this string node.- Returns:
- the value of this string node.
-