public final class StringNode extends Node
Node.NonNumericFloat
Constructor and Description |
---|
StringNode(java.lang.String value,
SourceLocation sourceLocation)
Creates a new StringNode.
|
Modifier and Type | Method and Description |
---|---|
<R> R |
accept(NodeVisitor<R> visitor)
Accepts a visitor with the node.
|
java.util.Optional<StringNode> |
asStringNode()
Gets the node as an StringNode if it is an string.
|
static Pair<StringNode,java.util.function.Consumer<java.lang.String>> |
createLazyString(java.lang.String placeholder,
SourceLocation sourceLocation)
Creates a StringNode that is lazily populated with a value provided by
the given
Supplier . |
boolean |
equals(java.lang.Object other) |
java.lang.String |
expectOneOf(java.util.Collection<java.lang.String> validValues)
Gets the string if it is one of the provided valid strings.
|
java.lang.String |
expectOneOf(java.lang.String... validValues)
Gets the string if it is one of the provided valid strings.
|
ShapeId |
expectShapeId()
Expects that the value of the string is a fully-qualified Shape ID.
|
ShapeId |
expectShapeId(java.lang.String namespace)
Expects that the value of the string is a Shape ID.
|
StringNode |
expectStringNode(java.lang.String errorMessage)
Casts the current node to a
StringNode , throwing
ExpectationNotMetException when the node is the wrong type. |
StringNode |
expectStringNode(java.util.function.Supplier<java.lang.String> errorMessage)
Casts the current node to a
StringNode , throwing
ExpectationNotMetException when the node is the wrong type. |
NodeType |
getType()
Gets the type of the node.
|
java.lang.String |
getValue()
Gets the string value.
|
int |
hashCode() |
java.lang.String |
toString() |
arrayNode, arrayNode, asArrayNode, asBooleanNode, asNullNode, asNumberNode, asObjectNode, assertEquals, diff, expectArrayNode, expectArrayNode, expectArrayNode, expectBooleanNode, expectBooleanNode, expectBooleanNode, expectNullNode, expectNullNode, expectNullNode, expectNumberNode, expectNumberNode, expectNumberNode, expectObjectNode, expectObjectNode, expectObjectNode, expectStringNode, from, from, from, fromNodes, fromNodes, fromStrings, fromStrings, getSourceLocation, isArrayNode, isBooleanNode, isNullNode, isNumberNode, isObjectNode, isStringNode, loadArrayOfString, nullNode, objectNode, objectNode, objectNodeBuilder, parse, parse, parse, parse, parseJsonWithComments, parseJsonWithComments, prettyPrintJson, prettyPrintJson, printJson, toNode, withDeepSortedKeys, withDeepSortedKeys
public StringNode(java.lang.String value, SourceLocation sourceLocation)
value
- Immutable value to set.sourceLocation
- Source location of where the node was defined.public static Pair<StringNode,java.util.function.Consumer<java.lang.String>> createLazyString(java.lang.String placeholder, SourceLocation sourceLocation)
Supplier
.
This method is used in the SmithyModelLoader
class to be
able to resolve unquoted strings to the appropriate shape ID. Because
this can only be done after an entire model is loaded, setting the
resolved value inside of a node needs to be deferred.
Lazy string nodes are not thread safe and there's no validation to ensure that the supplier is invoked only once. Their usage should be rare and you should generally try to use an alternative approach.
placeholder
- Placeholder string to use until the supplier is called.sourceLocation
- Location of where the value was originally defined.public <R> R accept(NodeVisitor<R> visitor)
Node
public StringNode expectStringNode(java.lang.String errorMessage)
Node
StringNode
, throwing
ExpectationNotMetException
when the node is the wrong type.expectStringNode
in class Node
errorMessage
- Error message to use if the node is of the wrong type.public StringNode expectStringNode(java.util.function.Supplier<java.lang.String> errorMessage)
Node
StringNode
, throwing
ExpectationNotMetException
when the node is the wrong type.expectStringNode
in class Node
errorMessage
- Error message supplier.public java.util.Optional<StringNode> asStringNode()
Node
asStringNode
in class Node
public java.lang.String getValue()
public java.lang.String expectOneOf(java.lang.String... validValues)
validValues
- A list of valid string values.ExpectationNotMetException
- when the value is not one of the
valid strings.public java.lang.String expectOneOf(java.util.Collection<java.lang.String> validValues)
validValues
- A list of valid string values.ExpectationNotMetException
- if the value is not in the list.public ShapeId expectShapeId(java.lang.String namespace)
namespace
- Namespace to use when resolving relative shape IDs.public ShapeId expectShapeId()
public boolean equals(java.lang.Object other)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object