Interface Node<T>
- Type Parameters:
T- a type of object
- All Known Subinterfaces:
ArrayNode<T>,CommentableNode<T>,ListNode,MapNode,NumberValue,ValueNode<T>
- All Known Implementing Classes:
BooleanArray,BooleanValue,ByteArray,ByteValue,CharArray,CharValue,CommentedNode,DoubleArray,DoubleValue,EnumValue,FloatArray,FloatValue,IntArray,IntValue,LongArray,LongValue,NullNode,ObjectNode,ShortArray,ShortValue,StringValue
public sealed interface Node<T>
permits ArrayNode<T>, CommentableNode<T>, NullNode, ObjectNode<T>, ValueNode<T>
An interface that holds an object or value
-
Method Summary
Modifier and TypeMethodDescription@NotNull VisitResultaccept(@NotNull NodeVisitor visitor) Accepts aNodeVisitorfor thisNode.Gets an object asOptional.static @NotNull Node<?>fromObject(@Nullable Object obj) Creates aNodefrom the specified object.default booleanhasValue()Checks if thisNodeholds an object.@UnknownNullability Tvalue()Gets an object which thisNodeholds
-
Method Details
-
fromObject
Creates aNodefrom the specified object.This method is implemented with the following specifications:
- If the given object is null or
NullNode.NULL, returnsNullNode.NULL - If the given object is
Node:- If the
Nodeis implementedValueNode, returns it as-is - If the
NodeisListNode, copies it by usingListNode.copy() - If the
NodeisMapNode, copies it by usingMapNode.copy() - If the
NodeisCommentedNode, recreate it withCommentedNode.node()that is passed to this method - Other
Nodes will be re-created
- If the
- If the given object is a array:
- If the given object is
String/Enum, createsStringValue/EnumValue - If the given object is
Number, passes the number toNumberValue.fromNumber(Number) - If the given object is
Boolean, passes the boolean toBooleanValue.fromBoolean(Boolean) - If the given object is implemented
Collection, createsListNodeusingListNode.create(java.util.Collection) - If the given object is implemented
Map, createsMapNodeusingMapNode.create(java.util.Map) - Otherwise, returns
ObjectNodewith the given object
- If the given object is null or
-
value
@UnknownNullability T value()Gets an object which thisNodeholds- Returns:
- an object which this
Nodeholds
-
hasValue
default boolean hasValue()Checks if thisNodeholds an object.The default implementation of this method checks if the returning value from
value()is notnull.- Returns:
trueif thisNodeholds an object, otherwisefalse
-
asOptional
Gets an object asOptional.The default implementation of this method returns
Optional.ofNullable(Object)which is wrappingvalue().- Returns:
- the
Optional
-
accept
Accepts aNodeVisitorfor thisNode.- Parameters:
visitor- aNodeVisitorto accept- Returns:
- a
VisitResult
-