Class ObjectNode
- java.lang.Object
-
- software.amazon.smithy.model.node.Node
-
- software.amazon.smithy.model.node.ObjectNode
-
- All Implemented Interfaces:
FromSourceLocation
,ToNode
,ToSmithyBuilder<ObjectNode>
public final class ObjectNode extends Node implements ToSmithyBuilder<ObjectNode>
Represents an object node.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ObjectNode.Builder
Builder used to efficiently create an ObjectNode.-
Nested classes/interfaces inherited from class software.amazon.smithy.model.node.Node
Node.NonNumericFloat
-
-
Constructor Summary
Constructors Constructor Description ObjectNode(java.util.Map<StringNode,Node> members, SourceLocation sourceLocation)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method 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.<N extends Node,T>
ObjectNodeexpectArrayMember(java.lang.String k, java.util.function.Function<N,T> map, java.util.function.Consumer<java.util.List<T>> consumer)
Requires that the given member exists and is an array; then creates a list of values for the array by passing array element through the mapping function, and passes that list to the consumer.BooleanNode
expectBooleanMember(java.lang.String name)
Gets a member and requires it to be a boolean.ObjectNode
expectBooleanMember(java.lang.String key, java.util.function.Consumer<java.lang.Boolean> consumer)
Requires thatkey
exists, is a boolean, and passes the value toconsumer
.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, throwingExpectationNotMetException
when the member is not present.<T> ObjectNode
expectMember(java.lang.String key, java.util.function.Function<Node,T> mapper, java.util.function.Consumer<T> consumer)
Requires that thekey
member is present, passes the value through the givenmapper
, and then passes the mapped value toconsumer
.Node
expectMember(java.lang.String name, java.util.function.Supplier<java.lang.String> errorMessage)
Gets the member with the given name, throwingExpectationNotMetException
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
expectNumberMember(java.lang.String key, java.util.function.Consumer<java.lang.Number> consumer)
Requires thatkey
exists, is a number, and passes the value toconsumer
.ObjectNode
expectObjectMember(java.lang.String name)
Gets a member and requires it to be an object.ObjectNode
expectObjectMember(java.lang.String name, java.util.function.Consumer<ObjectNode> consumer)
Gets a member and requires it to be an object.ObjectNode
expectObjectNode(java.lang.String errorMessage)
Casts the current node to anObjectNode
, throwingExpectationNotMetException
when the node is the wrong type.ObjectNode
expectObjectNode(java.util.function.Supplier<java.lang.String> errorMessage)
Casts the current node to anObjectNode
, throwingExpectationNotMetException
when the node is the wrong type.StringNode
expectStringMember(java.lang.String name)
Gets a member and requires it to be a string.ObjectNode
expectStringMember(java.lang.String key, java.util.function.Consumer<java.lang.String> consumer)
Requires thatkey
exists, is a string, and passes the value toconsumer
.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.ObjectNode
getArrayMember(java.lang.String key, java.util.function.Consumer<java.util.List<Node>> consumer)
Gets the nodes of an optional member that contains an array.<N extends Node,T>
ObjectNodegetArrayMember(java.lang.String k, java.util.function.Function<N,T> map, java.util.function.Consumer<java.util.List<T>> consumer)
The same asexpectArrayMember(String, Function, Consumer)
, but the member is optional.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.ObjectNode
getBooleanMember(java.lang.String key, java.util.function.Consumer<java.lang.Boolean> consumer)
The same asexpectBooleanMember(String, Consumer)
but the member is optional.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.<T> ObjectNode
getMember(java.lang.String key, java.util.function.Function<Node,T> mapper, java.util.function.Consumer<T> consumer)
The same asexpectMember(String, Function, Consumer)
, but the member is optional.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.ObjectNode
getNumberMember(java.lang.String key, java.util.function.Consumer<java.lang.Number> consumer)
The same asexpectNumberMember(String, Consumer)
but the member is optional.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.ObjectNode
getObjectMember(java.lang.String memberName, java.util.function.Consumer<ObjectNode> consumer)
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 immutableMap<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.ObjectNode
getStringMember(java.lang.String key, java.util.function.Consumer<java.lang.String> consumer)
The same asexpectStringMember(String, Consumer)
but the member is optional.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.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>
ObjectNodewithMember(java.lang.String key, T value)
Constructs a new object node with the given member added.<T extends ToNode>
ObjectNodewithMember(StringNode key, T value)
Constructs a new object node with the given member added.<T extends ToNode>
ObjectNodewithOptionalMember(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.-
Methods inherited from class software.amazon.smithy.model.node.Node
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, 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
-
-
-
-
Constructor Detail
-
ObjectNode
public ObjectNode(java.util.Map<StringNode,Node> members, SourceLocation sourceLocation)
-
-
Method Detail
-
fromStringMap
public static ObjectNode fromStringMap(java.util.Map<java.lang.String,java.lang.String> map)
-
builder
public static ObjectNode.Builder builder()
-
accept
public <R> R accept(NodeVisitor<R> visitor)
Description copied from class:Node
Accepts a visitor with the node.
-
expectObjectNode
public ObjectNode expectObjectNode(java.lang.String errorMessage)
Description copied from class:Node
Casts the current node to anObjectNode
, throwingExpectationNotMetException
when the node is the wrong type.- Overrides:
expectObjectNode
in classNode
- Parameters:
errorMessage
- Error message to use if the node is of the wrong type.- Returns:
- Returns an object node.
-
expectObjectNode
public ObjectNode expectObjectNode(java.util.function.Supplier<java.lang.String> errorMessage)
Description copied from class:Node
Casts the current node to anObjectNode
, throwingExpectationNotMetException
when the node is the wrong type.- Overrides:
expectObjectNode
in classNode
- Parameters:
errorMessage
- Error message supplier.- Returns:
- Returns an object node.
-
asObjectNode
public java.util.Optional<ObjectNode> asObjectNode()
Description copied from class:Node
Gets the node as an ObjectNode if it is an object.- Overrides:
asObjectNode
in classNode
- Returns:
- Returns the optional object node.
-
withMember
public <T extends ToNode> ObjectNode withMember(StringNode key, T value)
Constructs a new object node with the given member added.- Type Parameters:
T
- Type of the value member to add.- Parameters:
key
- Name of the member to add.value
- Value of the member to add.- Returns:
- Returns a new object node.
-
withMember
public <T extends ToNode> ObjectNode withMember(java.lang.String key, T value)
Constructs a new object node with the given member added.- Type Parameters:
T
- Type of the value member to add.- Parameters:
key
- Name of the member to add as a string.value
- Value of the member to add.- Returns:
- Returns a new object node.
-
withMember
public ObjectNode withMember(java.lang.String key, java.lang.String value)
Constructs a new object node with the given member added.- Parameters:
key
- Name of the member to add as a string.value
- Value of the member to add.- Returns:
- Returns a new object node.
-
withMember
public ObjectNode withMember(java.lang.String key, boolean value)
Constructs a new object node with the given member added.- Parameters:
key
- Name of the member to add as a string.value
- Value of the member to add.- Returns:
- Returns a new object node.
-
withMember
public ObjectNode withMember(java.lang.String key, java.lang.Number value)
Constructs a new object node with the given member added.- Parameters:
key
- Name of the member to add as a string.value
- Value of the member to add.- Returns:
- Returns a new object node.
-
withOptionalMember
public <T extends ToNode> ObjectNode withOptionalMember(java.lang.String key, java.util.Optional<T> value)
Adds a member to a new ObjectNode if the provided value is present.- Type Parameters:
T
- Type of the value member to add.- Parameters:
key
- Key to set if value is present.value
- Value that may be present.- Returns:
- Returns an object with the optionally added member.
-
withoutMember
public ObjectNode withoutMember(java.lang.String memberName)
Constructs a new object node from the current node, but without the named member.- Parameters:
memberName
- Name of a member that should be omitted.- Returns:
- Returns a new object node.
-
getMembers
public java.util.Map<StringNode,Node> getMembers()
Gets the map of members.- Returns:
- Returns a map of nodes.
-
containsMember
public boolean containsMember(java.lang.String memberName)
Checks if the given member name exists in the ObjectNode.- Parameters:
memberName
- Member name to check.- Returns:
- Returns true if this member is in the ObjectNode.
-
getMember
public java.util.Optional<Node> getMember(java.lang.String memberName)
Gets the member with the given name.- Parameters:
memberName
- Name of the member to get.- Returns:
- Returns the optional node with the given member name.
-
getMembersByPrefix
public 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.- Parameters:
prefix
- Prefix to search for in keys.- Returns:
- Returns the map of matching members.
-
getStringMap
public java.util.Map<java.lang.String,Node> getStringMap()
Gets an immutableMap<String, Node>
that represents the ObjectNode.- Returns:
- Returns the immutable map.
-
getStringMember
public 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.- Parameters:
memberName
- Name of the member to get.- Returns:
- Returns the optional node with the given member name.
- Throws:
ExpectationNotMetException
- if the member is not a string.
-
getStringMemberOrDefault
public 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.- Parameters:
memberName
- Name of the member to get.defaultValue
- Default string value to return if the member is not present.- Returns:
- Returns a String value contained in the String node or the default value.
- Throws:
ExpectationNotMetException
- if the member is not a string.
-
getNumberMember
public 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.- Parameters:
memberName
- Name of the member to get.- Returns:
- Returns the optional node with the given member name.
- Throws:
ExpectationNotMetException
- if the member is not a number.
-
getNumberMemberOrDefault
public 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.- Parameters:
memberName
- Name of the member to get.defaultValue
- Default value to return if a member is not found.- Returns:
- Returns the Number value or a default value.
- Throws:
ExpectationNotMetException
- if the member is not a number.
-
getArrayMember
public 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.- Parameters:
memberName
- Name of the member to get.- Returns:
- Returns the optional node with the given member name.
- Throws:
ExpectationNotMetException
- if the member is not an array.
-
getObjectMember
public 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.- Parameters:
memberName
- Name of the member to get.- Returns:
- Returns the optional node with the given member name.
- Throws:
ExpectationNotMetException
- if the member is not an object.
-
getBooleanMember
public 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.- Parameters:
memberName
- Name of the member to get.- Returns:
- Returns the optional node with the given member name.
- Throws:
ExpectationNotMetException
- if the member is not a boolean.
-
getBooleanMemberOrDefault
public 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.- Parameters:
memberName
- Name of the member to get.defaultValue
- Default value to return if not present.- Returns:
- Returns the boolean value or a default value.
- Throws:
ExpectationNotMetException
- if the member is not a boolean.
-
getBooleanMemberOrDefault
public 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.- Parameters:
memberName
- Name of the member to get.- Returns:
- Returns the boolean value or false if not found.
- Throws:
ExpectationNotMetException
- if the member is found and not a boolean.
-
expectMember
public Node expectMember(java.lang.String name)
Gets the member with the given name.- Parameters:
name
- Name of the member to get.- Returns:
- Returns the node with the given member name.
- Throws:
java.lang.IllegalArgumentException
- whenmemberName
is null.ExpectationNotMetException
- whenmemberName
is not present in the members map.
-
expectMember
public Node expectMember(java.lang.String name, java.lang.String errorMessage)
Gets the member with the given name, throwingExpectationNotMetException
when the member is not present.- Parameters:
name
- Name of the member to get.errorMessage
- The error message to use if the expectation is not met.- Returns:
- Returns the node with the given member name.
- Throws:
ExpectationNotMetException
- whenmemberName
is not present in the members map.
-
expectMember
public Node expectMember(java.lang.String name, java.util.function.Supplier<java.lang.String> errorMessage)
Gets the member with the given name, throwingExpectationNotMetException
when the member is not present.- Parameters:
name
- Name of the member to get.errorMessage
- Error message supplier.- Returns:
- Returns the node with the given member name.
- Throws:
ExpectationNotMetException
- whenmemberName
is not present in the members map.
-
expectArrayMember
public ArrayNode expectArrayMember(java.lang.String name)
Gets a member and requires it to be an array.- Parameters:
name
- Name of the member to get.- Returns:
- Returns the node with the given member name.
- Throws:
ExpectationNotMetException
- when not present or not an array.
-
expectBooleanMember
public BooleanNode expectBooleanMember(java.lang.String name)
Gets a member and requires it to be a boolean.- Parameters:
name
- Name of the member to get.- Returns:
- Returns the node with the given member name.
- Throws:
ExpectationNotMetException
- when not present or not a boolean.
-
expectNullMember
public NullNode expectNullMember(java.lang.String name)
Gets a member and requires it to be a null.- Parameters:
name
- Name of the member to get.- Returns:
- Returns the node with the given member name.
- Throws:
ExpectationNotMetException
- when not present or not a null.
-
expectNumberMember
public NumberNode expectNumberMember(java.lang.String name)
Gets a member and requires it to be a number.- Parameters:
name
- Name of the member to get.- Returns:
- Returns the node with the given member name.
- Throws:
ExpectationNotMetException
- when not present or not a number.
-
expectObjectMember
public ObjectNode expectObjectMember(java.lang.String name)
Gets a member and requires it to be an object.- Parameters:
name
- Name of the member to get.- Returns:
- Returns the node with the given member name.
- Throws:
ExpectationNotMetException
- when not present or not an object.
-
expectStringMember
public StringNode expectStringMember(java.lang.String name)
Gets a member and requires it to be a string.- Parameters:
name
- Name of the member to get.- Returns:
- Returns the node with the given member name.
- Throws:
ExpectationNotMetException
- when not present or not a string.
-
expectNoAdditionalProperties
public ObjectNode expectNoAdditionalProperties(java.util.Collection<java.lang.String> allowedProperties)
Ensures that there are no additional properties other than the provided member names.- Parameters:
allowedProperties
- Properties that may exist.- Returns:
- Returns self
- Throws:
ExpectationNotMetException
- if other properties are found.
-
warnIfAdditionalProperties
public ObjectNode warnIfAdditionalProperties(java.util.Collection<java.lang.String> allowedProperties)
Warns if unknown properties are found in object.- Parameters:
allowedProperties
- Properties that may exist.- Returns:
- Returns self
-
expectMember
public <T> ObjectNode expectMember(java.lang.String key, java.util.function.Function<Node,T> mapper, java.util.function.Consumer<T> consumer)
Requires that thekey
member is present, passes the value through the givenmapper
, and then passes the mapped value toconsumer
.- Type Parameters:
T
- Mapped value type.- Parameters:
key
- Key to get from the object.mapper
- Mapping function used to convert the node value.consumer
- Consumer to pass the found value to.- Returns:
- Returns the node.
-
getMember
public <T> ObjectNode getMember(java.lang.String key, java.util.function.Function<Node,T> mapper, java.util.function.Consumer<T> consumer)
The same asexpectMember(String, Function, Consumer)
, but the member is optional.- Type Parameters:
T
- Mapped value type.- Parameters:
key
- Key to get from the object.mapper
- Mapping function used to convert the node value.consumer
- Consumer to pass the found value to.- Returns:
- Returns the node.
-
expectObjectMember
public ObjectNode expectObjectMember(java.lang.String name, java.util.function.Consumer<ObjectNode> consumer)
Gets a member and requires it to be an object.- Parameters:
name
- Name of the member to get.consumer
- Consumer that accepts the object member.- Returns:
- Returns the node.
- Throws:
ExpectationNotMetException
- when not present or not an object.
-
getObjectMember
public ObjectNode getObjectMember(java.lang.String memberName, java.util.function.Consumer<ObjectNode> consumer)
Gets the member with the given name, and if present, expects it to be an object.- Parameters:
memberName
- Name of the member to get.consumer
- Consumer that accepts the member if found.- Returns:
- Returns the node.
- Throws:
ExpectationNotMetException
- if the member is not an object.
-
expectStringMember
public ObjectNode expectStringMember(java.lang.String key, java.util.function.Consumer<java.lang.String> consumer)
Requires thatkey
exists, is a string, and passes the value toconsumer
.- Parameters:
key
- Key to retrieve.consumer
- Consumer that accepts the string value.- Returns:
- Returns the node.
-
getStringMember
public ObjectNode getStringMember(java.lang.String key, java.util.function.Consumer<java.lang.String> consumer)
The same asexpectStringMember(String, Consumer)
but the member is optional.- Parameters:
key
- Key to retrieve.consumer
- Consumer that accepts the string value.- Returns:
- Returns the node.
-
expectBooleanMember
public ObjectNode expectBooleanMember(java.lang.String key, java.util.function.Consumer<java.lang.Boolean> consumer)
Requires thatkey
exists, is a boolean, and passes the value toconsumer
.- Parameters:
key
- Key to retrieve.consumer
- Consumer that accepts the boolean value.- Returns:
- Returns the node.
-
getBooleanMember
public ObjectNode getBooleanMember(java.lang.String key, java.util.function.Consumer<java.lang.Boolean> consumer)
The same asexpectBooleanMember(String, Consumer)
but the member is optional.- Parameters:
key
- Key to retrieve.consumer
- Consumer that accepts the boolean value.- Returns:
- Returns the node.
-
expectNumberMember
public ObjectNode expectNumberMember(java.lang.String key, java.util.function.Consumer<java.lang.Number> consumer)
Requires thatkey
exists, is a number, and passes the value toconsumer
.- Parameters:
key
- Key to retrieve.consumer
- Consumer that accepts the number value.- Returns:
- Returns the node.
-
getNumberMember
public ObjectNode getNumberMember(java.lang.String key, java.util.function.Consumer<java.lang.Number> consumer)
The same asexpectNumberMember(String, Consumer)
but the member is optional.- Parameters:
key
- Key to retrieve.consumer
- Consumer that accepts the number value.- Returns:
- Returns the node.
-
getArrayMember
public ObjectNode getArrayMember(java.lang.String key, java.util.function.Consumer<java.util.List<Node>> consumer)
Gets the nodes of an optional member that contains an array.- Parameters:
key
- Key to retrieve.consumer
- Consumer that accepts the array node value.- Returns:
- Returns the node.
-
expectArrayMember
public <N extends Node,T> ObjectNode expectArrayMember(java.lang.String k, java.util.function.Function<N,T> map, java.util.function.Consumer<java.util.List<T>> consumer)
Requires that the given member exists and is an array; then creates a list of values for the array by passing array element through the mapping function, and passes that list to the consumer.- Type Parameters:
N
- Type of Node to expect in each array element.T
- Type of value returned from the mapper.- Parameters:
k
- Key to retrieve.map
- Mapper that takes each array node and returns a mapped value.consumer
- Consumer that accepts the collected mapped values.- Returns:
- Returns the node.
-
getArrayMember
public <N extends Node,T> ObjectNode getArrayMember(java.lang.String k, java.util.function.Function<N,T> map, java.util.function.Consumer<java.util.List<T>> consumer)
The same asexpectArrayMember(String, Function, Consumer)
, but the member is optional.- Type Parameters:
N
- Type of Node to expect in each array element.T
- Type of value returned from the mapper.- Parameters:
k
- Key to retrieve.map
- Mapper that takes each array node and returns a mapped value.consumer
- Consumer that accepts the collected mapped values.- Returns:
- Returns the node.
-
isEmpty
public boolean isEmpty()
Returns true if this object has no members.- Returns:
- Returns if this object is empty.
-
size
public int size()
Returns the number of members.- Returns:
- Returns the number of members.
-
merge
public ObjectNode merge(ObjectNode other)
Merge this object node with another, creating a new ObjectNode.Conflicting keys are overwritten by
other
. If the current object has a source location, it is applied to the result. Otherwise, the source location ofother
is applied to the result.- Parameters:
other
- Other object node to merge with.- Returns:
- Returns the merged object node.
-
collect
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)
Creates a collector that creates an ObjectNode.- Type Parameters:
T
- Type being collected over (e.g., Map.Entry, Pair, etc.).- Parameters:
keyMapper
- Key mapping function that returns a ToNode.valueMapper
- Value mapping function that returns a ToNode.- Returns:
- Returns the created collector.
-
collectStringKeys
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)
Creates a collector that creates an ObjectNode.- Type Parameters:
T
- Type being collected over (e.g., Map.Entry, Pair, etc.).- Parameters:
keyMapper
- Key mapping function that returns a string.valueMapper
- Value mapping function that returns a ToNode.- Returns:
- Returns the created collector.
-
equals
public boolean equals(java.lang.Object other)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
toBuilder
public ObjectNode.Builder toBuilder()
Description copied from interface:ToSmithyBuilder
Take this object and create a builder that contains all of the current property values of this object.- Specified by:
toBuilder
in interfaceToSmithyBuilder<ObjectNode>
- Returns:
- a builder for type T
-
-