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 VisitResult
accept
(@NotNull NodeVisitor visitor) Accepts aNodeVisitor
for thisNode
.Gets an object asOptional
.static @NotNull Node<?>
fromObject
(@Nullable Object obj) Creates aNode
from the specified object.default boolean
hasValue()
Checks if thisNode
holds an object.@UnknownNullability T
value()
Gets an object which thisNode
holds
-
Method Details
-
fromObject
Creates aNode
from 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
Node
is implementedValueNode
, returns it as-is - If the
Node
isListNode
, copies it by usingListNode.copy()
- If the
Node
isMapNode
, copies it by usingMapNode.copy()
- If the
Node
isCommentedNode
, recreate it withCommentedNode.node()
that is passed to this method - Other
Node
s 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
, createsListNode
usingListNode.create(java.util.Collection)
- If the given object is implemented
Map
, createsMapNode
usingMapNode.create(java.util.Map)
- Otherwise, returns
ObjectNode
with the given object
- If the given object is null or
-
value
@UnknownNullability T value()Gets an object which thisNode
holds- Returns:
- an object which this
Node
holds
-
hasValue
default boolean hasValue()Checks if thisNode
holds an object.The default implementation of this method checks if the returning value from
value()
is notnull
.- Returns:
true
if thisNode
holds 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 aNodeVisitor
for thisNode
.- Parameters:
visitor
- aNodeVisitor
to accept- Returns:
- a
VisitResult
-