public final class ObjectNode extends Node implements ToSmithyBuilder<ObjectNode>
Modifier and Type | Class and Description |
---|---|
static class |
ObjectNode.Builder
Builder used to efficiently create an ObjectNode.
|
Node.NonNumericFloat
Constructor and Description |
---|
ObjectNode(java.util.Map<StringNode,Node> members,
SourceLocation sourceLocation) |
Modifier and Type | Method and Description |
---|---|
<R> R |
accept(NodeVisitor<R> visitor)
Accepts a visitor with the node.
|
java.util.Optional<ObjectNode> |
asObjectNode()
Gets the node as an ObjectNode if it is an object.
|
static ObjectNode.Builder |
builder() |
static <T> java.util.stream.Collector<T,java.util.Map<StringNode,Node>,ObjectNode> |
collect(java.util.function.Function<T,StringNode> keyMapper,
java.util.function.Function<T,ToNode> valueMapper)
Creates a collector that creates an ObjectNode.
|
static <T> java.util.stream.Collector<T,java.util.Map<StringNode,Node>,ObjectNode> |
collectStringKeys(java.util.function.Function<T,java.lang.String> keyMapper,
java.util.function.Function<T,ToNode> valueMapper)
Creates a collector that creates an ObjectNode.
|
boolean |
containsMember(java.lang.String memberName)
Checks if the given member name exists in the ObjectNode.
|
boolean |
equals(java.lang.Object other) |
ArrayNode |
expectArrayMember(java.lang.String name)
Gets a member and requires it to be an array.
|
BooleanNode |
expectBooleanMember(java.lang.String name)
Gets a member and requires it to be a boolean.
|
Node |
expectMember(java.lang.String name)
Gets the member with the given name.
|
Node |
expectMember(java.lang.String name,
java.lang.String errorMessage)
Gets the member with the given name, throwing
ExpectationNotMetException when the member is not present. |
Node |
expectMember(java.lang.String name,
java.util.function.Supplier<java.lang.String> errorMessage)
Gets the member with the given name, throwing
ExpectationNotMetException when the member is not present. |
ObjectNode |
expectNoAdditionalProperties(java.util.Collection<java.lang.String> allowedProperties)
Ensures that there are no additional properties other than the
provided member names.
|
NullNode |
expectNullMember(java.lang.String name)
Gets a member and requires it to be a null.
|
NumberNode |
expectNumberMember(java.lang.String name)
Gets a member and requires it to be a number.
|
ObjectNode |
expectObjectMember(java.lang.String name)
Gets a member and requires it to be an object.
|
ObjectNode |
expectObjectNode(java.lang.String errorMessage)
Casts the current node to an
ObjectNode , throwing
ExpectationNotMetException when the node is the wrong type. |
ObjectNode |
expectObjectNode(java.util.function.Supplier<java.lang.String> errorMessage)
Casts the current node to an
ObjectNode , throwing
ExpectationNotMetException when the node is the wrong type. |
StringNode |
expectStringMember(java.lang.String name)
Gets a member and requires it to be a string.
|
static ObjectNode |
fromStringMap(java.util.Map<java.lang.String,java.lang.String> map) |
java.util.Optional<ArrayNode> |
getArrayMember(java.lang.String memberName)
Gets the member with the given name, and if present, expects it to
be an array.
|
java.util.Optional<BooleanNode> |
getBooleanMember(java.lang.String memberName)
Gets the member with the given name, and if present, expects it to
be a boolean.
|
boolean |
getBooleanMemberOrDefault(java.lang.String memberName)
Gets the member with the given name, and if present, expects it to
be a boolean, otherwise returns false.
|
java.lang.Boolean |
getBooleanMemberOrDefault(java.lang.String memberName,
java.lang.Boolean defaultValue)
Gets the member with the given name, and if present, expects it to
be a boolean, otherwise returns a default value.
|
java.util.Optional<Node> |
getMember(java.lang.String memberName)
Gets the member with the given name.
|
java.util.Map<StringNode,Node> |
getMembers()
Gets the map of members.
|
java.util.Map<java.lang.String,Node> |
getMembersByPrefix(java.lang.String prefix)
Gets a map of all members where the key starts with the given prefix.
|
java.util.Optional<NumberNode> |
getNumberMember(java.lang.String memberName)
Gets the member with the given name, and if present, expects it to
be a number.
|
java.lang.Number |
getNumberMemberOrDefault(java.lang.String memberName,
java.lang.Number defaultValue)
Gets the member with the given name, and if present, expects it to
be a number, otherwise returns the default value.
|
java.util.Optional<ObjectNode> |
getObjectMember(java.lang.String memberName)
Gets the member with the given name, and if present, expects it to
be an object.
|
java.util.Map<java.lang.String,Node> |
getStringMap()
Gets an immutable
Map<String, Node> that represents the ObjectNode. |
java.util.Optional<StringNode> |
getStringMember(java.lang.String memberName)
Gets the member with the given name, and if present, expects it to
be a string.
|
java.lang.String |
getStringMemberOrDefault(java.lang.String memberName,
java.lang.String defaultValue)
Gets the member with the given name, and if present, expects it to
be a string, otherwise returns the default value.
|
NodeType |
getType()
Gets the type of the node.
|
int |
hashCode() |
boolean |
isEmpty()
Returns true if this object has no members.
|
ObjectNode |
merge(ObjectNode other)
Merge this object node with another, creating a new ObjectNode.
|
int |
size()
Returns the number of members.
|
ObjectNode.Builder |
toBuilder()
Take this object and create a builder that contains all of the
current property values of this object.
|
ObjectNode |
warnIfAdditionalProperties(java.util.Collection<java.lang.String> allowedProperties)
Warns if unknown properties are found in object.
|
ObjectNode |
withMember(java.lang.String key,
boolean value)
Constructs a new object node with the given member added.
|
<T extends ToNode> |
withMember(StringNode key,
T value)
Constructs a new object node with the given member added.
|
ObjectNode |
withMember(java.lang.String key,
java.lang.Number value)
Constructs a new object node with the given member added.
|
ObjectNode |
withMember(java.lang.String key,
java.lang.String value)
Constructs a new object node with the given member added.
|
<T extends ToNode> |
withMember(java.lang.String key,
T value)
Constructs a new object node with the given member added.
|
<T extends ToNode> |
withOptionalMember(java.lang.String key,
java.util.Optional<T> value)
Adds a member to a new ObjectNode if the provided value is present.
|
ObjectNode |
withoutMember(java.lang.String memberName)
Constructs a new object node from the current node, but without
the named member.
|
arrayNode, arrayNode, asArrayNode, asBooleanNode, asNullNode, asNumberNode, assertEquals, asStringNode, diff, expectArrayNode, expectArrayNode, expectArrayNode, expectBooleanNode, expectBooleanNode, expectBooleanNode, expectNullNode, expectNullNode, expectNullNode, expectNumberNode, expectNumberNode, expectNumberNode, expectObjectNode, expectStringNode, expectStringNode, 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 ObjectNode(java.util.Map<StringNode,Node> members, SourceLocation sourceLocation)
public static ObjectNode fromStringMap(java.util.Map<java.lang.String,java.lang.String> map)
public static ObjectNode.Builder builder()
public <R> R accept(NodeVisitor<R> visitor)
Node
public ObjectNode expectObjectNode(java.lang.String errorMessage)
Node
ObjectNode
, throwing
ExpectationNotMetException
when the node is the wrong type.expectObjectNode
in class Node
errorMessage
- Error message to use if the node is of the wrong type.public ObjectNode expectObjectNode(java.util.function.Supplier<java.lang.String> errorMessage)
Node
ObjectNode
, throwing
ExpectationNotMetException
when the node is the wrong type.expectObjectNode
in class Node
errorMessage
- Error message supplier.public java.util.Optional<ObjectNode> asObjectNode()
Node
asObjectNode
in class Node
public <T extends ToNode> ObjectNode withMember(StringNode key, T value)
T
- Type of the value member to add.key
- Name of the member to add.value
- Value of the member to add.public <T extends ToNode> ObjectNode withMember(java.lang.String key, T value)
T
- Type of the value member to add.key
- Name of the member to add as a string.value
- Value of the member to add.public ObjectNode withMember(java.lang.String key, java.lang.String value)
key
- Name of the member to add as a string.value
- Value of the member to add.public ObjectNode withMember(java.lang.String key, boolean value)
key
- Name of the member to add as a string.value
- Value of the member to add.public ObjectNode withMember(java.lang.String key, java.lang.Number value)
key
- Name of the member to add as a string.value
- Value of the member to add.public <T extends ToNode> ObjectNode withOptionalMember(java.lang.String key, java.util.Optional<T> value)
T
- Type of the value member to add.key
- Key to set if value is present.value
- Value that may be present.public ObjectNode withoutMember(java.lang.String memberName)
memberName
- Name of a member that should be omitted.public java.util.Map<StringNode,Node> getMembers()
public boolean containsMember(java.lang.String memberName)
memberName
- Member name to check.public java.util.Optional<Node> getMember(java.lang.String memberName)
memberName
- Name of the member to get.public java.util.Map<java.lang.String,Node> getMembersByPrefix(java.lang.String prefix)
prefix
- Prefix to search for in keys.public java.util.Map<java.lang.String,Node> getStringMap()
Map<String, Node>
that represents the ObjectNode.public java.util.Optional<StringNode> getStringMember(java.lang.String memberName)
memberName
- Name of the member to get.ExpectationNotMetException
- if the member is not a string.public java.lang.String getStringMemberOrDefault(java.lang.String memberName, java.lang.String defaultValue)
memberName
- Name of the member to get.defaultValue
- Default string value to return if the member is not present.ExpectationNotMetException
- if the member is not a string.public java.util.Optional<NumberNode> getNumberMember(java.lang.String memberName)
memberName
- Name of the member to get.ExpectationNotMetException
- if the member is not a number.public java.lang.Number getNumberMemberOrDefault(java.lang.String memberName, java.lang.Number defaultValue)
memberName
- Name of the member to get.defaultValue
- Default value to return if a member is not found.ExpectationNotMetException
- if the member is not a number.public java.util.Optional<ArrayNode> getArrayMember(java.lang.String memberName)
memberName
- Name of the member to get.ExpectationNotMetException
- if the member is not an array.public java.util.Optional<ObjectNode> getObjectMember(java.lang.String memberName)
memberName
- Name of the member to get.ExpectationNotMetException
- if the member is not an object.public java.util.Optional<BooleanNode> getBooleanMember(java.lang.String memberName)
memberName
- Name of the member to get.ExpectationNotMetException
- if the member is not a boolean.public java.lang.Boolean getBooleanMemberOrDefault(java.lang.String memberName, java.lang.Boolean defaultValue)
memberName
- Name of the member to get.defaultValue
- Default value to return if not present.ExpectationNotMetException
- if the member is not a boolean.public boolean getBooleanMemberOrDefault(java.lang.String memberName)
memberName
- Name of the member to get.ExpectationNotMetException
- if the member is found and not a boolean.public Node expectMember(java.lang.String name)
name
- Name of the member to get.java.lang.IllegalArgumentException
- when memberName
is null.ExpectationNotMetException
- when memberName
is not
present in the members map.public Node expectMember(java.lang.String name, java.lang.String errorMessage)
ExpectationNotMetException
when the member is not present.name
- Name of the member to get.errorMessage
- The error message to use if the expectation is not met.ExpectationNotMetException
- when memberName
is not
present in the members map.public Node expectMember(java.lang.String name, java.util.function.Supplier<java.lang.String> errorMessage)
ExpectationNotMetException
when the member is not present.name
- Name of the member to get.errorMessage
- Error message supplier.ExpectationNotMetException
- when memberName
is not
present in the members map.public ArrayNode expectArrayMember(java.lang.String name)
name
- Name of the member to get.ExpectationNotMetException
- when not present or not an array.public BooleanNode expectBooleanMember(java.lang.String name)
name
- Name of the member to get.ExpectationNotMetException
- when not present or not a boolean.public NullNode expectNullMember(java.lang.String name)
name
- Name of the member to get.ExpectationNotMetException
- when not present or not a null.public NumberNode expectNumberMember(java.lang.String name)
name
- Name of the member to get.ExpectationNotMetException
- when not present or not a number.public ObjectNode expectObjectMember(java.lang.String name)
name
- Name of the member to get.ExpectationNotMetException
- when not present or not an object.public StringNode expectStringMember(java.lang.String name)
name
- Name of the member to get.ExpectationNotMetException
- when not present or not a string.public ObjectNode expectNoAdditionalProperties(java.util.Collection<java.lang.String> allowedProperties)
allowedProperties
- Properties that may exist.ExpectationNotMetException
- if other properties are found.public ObjectNode warnIfAdditionalProperties(java.util.Collection<java.lang.String> allowedProperties)
allowedProperties
- Properties that may exist.public boolean isEmpty()
public int size()
public ObjectNode merge(ObjectNode other)
Conflicting keys are overwritten by other
. If the current
object has a source location, it is applied to the result. Otherwise,
the source location of other
is applied to the result.
other
- Other object node to merge with.public static <T> java.util.stream.Collector<T,java.util.Map<StringNode,Node>,ObjectNode> collect(java.util.function.Function<T,StringNode> keyMapper, java.util.function.Function<T,ToNode> valueMapper)
T
- Type being collected over (e.g., Map.Entry, Pair, etc.).keyMapper
- Key mapping function that returns a ToNode.valueMapper
- Value mapping function that returns a ToNode.public static <T> java.util.stream.Collector<T,java.util.Map<StringNode,Node>,ObjectNode> collectStringKeys(java.util.function.Function<T,java.lang.String> keyMapper, java.util.function.Function<T,ToNode> valueMapper)
T
- Type being collected over (e.g., Map.Entry, Pair, etc.).keyMapper
- Key mapping function that returns a string.valueMapper
- Value mapping function that returns a ToNode.public boolean equals(java.lang.Object other)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public ObjectNode.Builder toBuilder()
ToSmithyBuilder
toBuilder
in interface ToSmithyBuilder<ObjectNode>