Package com.apicatalog.tree.io.java
Class NativeAdapter
java.lang.Object
com.apicatalog.tree.io.java.NativeAdapter
- All Implemented Interfaces:
TreeAdapter
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic final Objectadapt(Object value, TreeAdapter adapter) static Collection<?>asCollection(Object node) Converts a given node to aBigDecimal, if possible.asIterable(Object node) Returns the node's contents as a universalIterable.Returns the node's contents as a universalStream.Returns a string representation of the node, coercing non-string scalar types where applicable.byte[]binaryValue(Object node) Extracts the binary data from a binary node.decimalValue(Object node) Extracts theBigDecimalvalue from a numeric node.doubledoubleValue(Object node) Extracts thedoublevalue from a numeric node.Returns the elements of a collection node as anIterable.elementStream(Object node) Returns the elements of a collection node as aStream.Returns all key-value pairs of a map node as anIterable.entryStream(Object node) Returns all key-value pairs of a map node as aStream.features()static final NativeAdapterinstance()integerValue(Object node) Extracts theBigIntegervalue from a numeric node.intExtracts theintvalue from a numeric node.booleanChecks if the adapted node contains binary data.booleanChecks if the adapted node represents a boolean value.booleanisCollection(Object node) Checks if the adapted node represents a collection of elements (e.g., an array or list).booleanChecks if a map or collection node is empty.booleanisIntegral(Object node) Checks if a number node represents an integral value (e.g., an integer or long) as opposed to a floating-point value.booleanChecks if the adapted collection node is a list (an ordered collection that allows duplicates).booleanChecks if the adapted node represents a map (an object with key-value pairs).booleanChecks if the given object is a native node that this adapter can process.booleanChecks if the adapted node represents a null value.booleanChecks if the adapted node represents any numeric value (integral or floating-point).booleanChecks if the adapted collection node is a set (an unordered collection of unique elements).booleanChecks if the adapted node represents a string value.Collection<? extends Object>Returns a collection of the native key objects from a map node.longExtracts thelongvalue from a numeric node.property(Object key, TreeAdapter keyAdapter, Object node) Retrieves the value associated with a given native key object from a map node.intReturns the number of entries in a map or elements in a collection.stringValue(Object node) Extracts the string value from a string node.Determines theNodeTypeof the given native node.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.apicatalog.tree.io.TreeAdapter
isCompatibleWith, isEmptyCollection, isEmptyMap, isFalse, isSingleElement, isSingleEntry, isTrue, keyStream, numericValue, singleElement, singleEntry
-
Constructor Details
-
NativeAdapter
public NativeAdapter()
-
-
Method Details
-
instance
-
features
- Specified by:
featuresin interfaceTreeAdapter
-
isNode
Description copied from interface:TreeAdapterChecks if the given object is a native node that this adapter can process. This method is the primary entry point for determining if the adapter is suitable for a given piece of data.- Specified by:
isNodein interfaceTreeAdapter- Parameters:
node- the object to check, which may benull.- Returns:
trueif the adapter can handle the object's type,falseotherwise.
-
type
Description copied from interface:TreeAdapterDetermines theNodeTypeof the given native node.- Specified by:
typein interfaceTreeAdapter- Parameters:
node- the node to inspect, which must be a valid node for this adapter.- Returns:
- the
NodeTypecorresponding to the node.
-
keys
Description copied from interface:TreeAdapterReturns a collection of the native key objects from a map node. The types of the keys depend on the underlying format (e.g., Strings for JSON, various scalars for CBOR).- Specified by:
keysin interfaceTreeAdapter- Parameters:
node- the map node to inspect.- Returns:
- a collection containing the map's native key objects.
-
property
Description copied from interface:TreeAdapterRetrieves the value associated with a given native key object from a map node.- Specified by:
propertyin interfaceTreeAdapter- Parameters:
property- the native key object used for the lookup.node- the map node to query.- Returns:
- the native value node, or
nullif the key is not found.
-
property
- Specified by:
propertyin interfaceTreeAdapter
-
entries
Description copied from interface:TreeAdapterReturns all key-value pairs of a map node as anIterable. The entries contain the native key and value objects.- Specified by:
entriesin interfaceTreeAdapter- Parameters:
node- the map node to inspect.- Returns:
- an
Iterableof its entries.
-
entryStream
Description copied from interface:TreeAdapterReturns all key-value pairs of a map node as aStream. This is a convenience method for processing map entries using the Stream API.- Specified by:
entryStreamin interfaceTreeAdapter- Parameters:
node- the map node to inspect.- Returns:
- a
Streamof its entries.
-
elements
Description copied from interface:TreeAdapterReturns the elements of a collection node as anIterable.- Specified by:
elementsin interfaceTreeAdapter- Parameters:
node- the collection node to inspect.- Returns:
- an
Iterableof its native element objects.
-
elementStream
Description copied from interface:TreeAdapterReturns the elements of a collection node as aStream.- Specified by:
elementStreamin interfaceTreeAdapter- Parameters:
node- the collection node to inspect.- Returns:
- a
Streamof its native element objects.
-
stringValue
Description copied from interface:TreeAdapterExtracts the string value from a string node.- Specified by:
stringValuein interfaceTreeAdapter- Parameters:
node- the string node.- Returns:
- the string value.
-
intValue
Description copied from interface:TreeAdapterExtracts theintvalue from a numeric node. This may involve a narrowing primitive conversion.- Specified by:
intValuein interfaceTreeAdapter- Parameters:
node- the numeric node.- Returns:
- the value as an
int.
-
longValue
Description copied from interface:TreeAdapterExtracts thelongvalue from a numeric node. This may involve a narrowing primitive conversion.- Specified by:
longValuein interfaceTreeAdapter- Parameters:
node- the numeric node.- Returns:
- the value as a
long.
-
integerValue
Description copied from interface:TreeAdapterExtracts theBigIntegervalue from a numeric node.- Specified by:
integerValuein interfaceTreeAdapter- Parameters:
node- the numeric node.- Returns:
- the value as a
BigInteger.
-
doubleValue
Description copied from interface:TreeAdapterExtracts thedoublevalue from a numeric node.- Specified by:
doubleValuein interfaceTreeAdapter- Parameters:
node- the numeric node.- Returns:
- the value as a
double.
-
decimalValue
Description copied from interface:TreeAdapterExtracts theBigDecimalvalue from a numeric node.- Specified by:
decimalValuein interfaceTreeAdapter- Parameters:
node- the numeric node.- Returns:
- the value as a
BigDecimal.
-
binaryValue
Description copied from interface:TreeAdapterExtracts the binary data from a binary node.- Specified by:
binaryValuein interfaceTreeAdapter- Parameters:
node- the binary node.- Returns:
- the data as a byte array.
-
asIterable
Description copied from interface:TreeAdapterReturns the node's contents as a universalIterable. This is a convenience method that enables uniform iteration logic.- If the node is a collection, returns its elements.
- If the node is not a collection, wraps it in a single-element iterable.
- If the node is
null, returns an empty iterable.
- Specified by:
asIterablein interfaceTreeAdapter- Parameters:
node- the node to convert.- Returns:
- a non-null
Iterablerepresenting the node's contents.
-
asStream
Description copied from interface:TreeAdapterReturns the node's contents as a universalStream.- Specified by:
asStreamin interfaceTreeAdapter- Parameters:
node- the node to convert.- Returns:
- a non-null
Streamrepresenting the node's contents.
-
isNull
Description copied from interface:TreeAdapterChecks if the adapted node represents a null value.- Specified by:
isNullin interfaceTreeAdapter- Parameters:
node- the node to check.- Returns:
trueif the node represents a null value,falseotherwise.
-
isBoolean
Description copied from interface:TreeAdapterChecks if the adapted node represents a boolean value.- Specified by:
isBooleanin interfaceTreeAdapter- Parameters:
node- the node to check.- Returns:
trueif the node represents a boolean value,falseotherwise.
-
isMap
Description copied from interface:TreeAdapterChecks if the adapted node represents a map (an object with key-value pairs).- Specified by:
isMapin interfaceTreeAdapter- Parameters:
node- the node to check.- Returns:
trueif the node represents a map,falseotherwise.
-
isCollection
Description copied from interface:TreeAdapterChecks if the adapted node represents a collection of elements (e.g., an array or list).- Specified by:
isCollectionin interfaceTreeAdapter- Parameters:
node- the node to check.- Returns:
trueif the node represents a collection,falseotherwise.
-
isList
Description copied from interface:TreeAdapterChecks if the adapted collection node is a list (an ordered collection that allows duplicates).- Specified by:
isListin interfaceTreeAdapter- Parameters:
node- the collection node to check.- Returns:
trueif the node is a list,falseotherwise.
-
isSet
Description copied from interface:TreeAdapterChecks if the adapted collection node is a set (an unordered collection of unique elements).- Specified by:
isSetin interfaceTreeAdapter- Parameters:
node- the collection node to check.- Returns:
trueif the node is a set,falseotherwise.
-
isString
Description copied from interface:TreeAdapterChecks if the adapted node represents a string value.- Specified by:
isStringin interfaceTreeAdapter- Parameters:
node- the node to check.- Returns:
trueif the node represents a string,falseotherwise.
-
isNumber
Description copied from interface:TreeAdapterChecks if the adapted node represents any numeric value (integral or floating-point).- Specified by:
isNumberin interfaceTreeAdapter- Parameters:
node- the node to check.- Returns:
trueif the node represents a number,falseotherwise.
-
isIntegral
Description copied from interface:TreeAdapterChecks if a number node represents an integral value (e.g., an integer or long) as opposed to a floating-point value.- Specified by:
isIntegralin interfaceTreeAdapter- Parameters:
node- the number node to check.- Returns:
trueif the node's value is integral,falseotherwise.
-
isBinary
Description copied from interface:TreeAdapterChecks if the adapted node contains binary data.- Specified by:
isBinaryin interfaceTreeAdapter- Parameters:
node- the node to check.- Returns:
trueif the node represents binary data,falseotherwise.
-
isEmpty
Description copied from interface:TreeAdapterChecks if a map or collection node is empty.- Specified by:
isEmptyin interfaceTreeAdapter- Parameters:
node- the structure node to inspect.- Returns:
trueif the node contains no entries or elements,falseotherwise.
-
size
Description copied from interface:TreeAdapterReturns the number of entries in a map or elements in a collection. This method is intended for nodes whereTreeAdapter.isMap(Object)orTreeAdapter.isCollection(Object)returnstrue.- Specified by:
sizein interfaceTreeAdapter- Parameters:
node- the structure node to inspect.- Returns:
- the number of entries (for a map) or elements (for a collection).
-
asString
Description copied from interface:TreeAdapterReturns a string representation of the node, coercing non-string scalar types where applicable.- Specified by:
asStringin interfaceTreeAdapter- Parameters:
node- the node to convert.- Returns:
- a string representation of the node's value.
-
asDecimal
Description copied from interface:TreeAdapterConverts a given node to aBigDecimal, if possible. This method can be used to treat both numeric and string nodes as decimal values.- Specified by:
asDecimalin interfaceTreeAdapter- Parameters:
node- the node to convert.- Returns:
- the
BigDecimalrepresentation.
-
adapt
-
asCollection
-