Class NativeAdapter

  • All Implemented Interfaces:
    NodeAdapter

    public class NativeAdapter
    extends java.lang.Object
    implements NodeAdapter
    • Constructor Summary

      Constructors 
      Constructor Description
      NativeAdapter()  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.Object adapt​(java.lang.Object value, NodeAdapter adapter)  
      java.math.BigDecimal asDecimal​(java.lang.Object node)
      Converts the given node to a BigDecimal, if possible.
      java.lang.Iterable<? extends java.lang.Object> asIterable​(java.lang.Object node)
      Returns the node as an iterable.
      java.util.stream.Stream<? extends java.lang.Object> asStream​(java.lang.Object node)
      Returns the node as a stream.
      java.lang.String asString​(java.lang.Object node)
      Returns the string representation of the node, converting other types as needed.
      java.math.BigInteger bigIntegerValue​(java.lang.Object node)
      Returns the BigInteger value of a number node.
      byte[] binaryValue​(java.lang.Object node)
      Returns the binary value of the node as a byte array.
      java.math.BigDecimal decimalValue​(java.lang.Object node)
      Returns the BigDecimal value of a number node.
      double doubleValue​(java.lang.Object node)
      Returns the double value of a number node.
      java.lang.Iterable<? extends java.lang.Object> elements​(java.lang.Object node)
      Returns the child nodes of a collection node as an Iterable.
      java.util.stream.Stream<? extends java.lang.Object> elementStream​(java.lang.Object node)
      Returns the child nodes of a collection node as a Stream.
      java.lang.Iterable<java.util.Map.Entry<?,​?>> entries​(java.lang.Object node)
      Returns all key-value pairs of the given map node as an Iterable.
      java.util.stream.Stream<java.util.Map.Entry<?,​?>> entryStream​(java.lang.Object node)
      Returns all key-value pairs of the given map node as a Stream.
      static NativeAdapter instance()  
      int intValue​(java.lang.Object node)
      Returns the integer value of a number node.
      boolean isBinary​(java.lang.Object node)
      Checks whether the node contains binary data.
      boolean isBoolean​(java.lang.Object node)
      Checks whether the node represents a boolean value.
      boolean isCollection​(java.lang.Object node)
      Checks whether the node represents a collection.
      boolean isEmpty​(java.lang.Object node)
      Checks whether a map node has no entries or a collection node has no items.
      boolean isIntegral​(java.lang.Object node)
      Checks whether a number node represents an integral value.
      boolean isList​(java.lang.Object node)
      Preserves insertion order and can contain duplicates.
      boolean isMap​(java.lang.Object node)
      Checks whether the node represents a map (object) structure.
      boolean isNode​(java.lang.Object node)
      Checks whether the given object can be processed by this adapter.
      boolean isNull​(java.lang.Object node)
      Checks whether the node represents a null value.
      boolean isNumber​(java.lang.Object node)
      Checks whether the node represents a numeric value.
      boolean isSet​(java.lang.Object node)
      Contains only unique elements.
      boolean isString​(java.lang.Object node)
      Checks whether the node represents a string value.
      java.util.Collection<? extends java.lang.Object> keys​(java.lang.Object node)
      Returns the collection of property key nodes for a map node.
      java.util.Set<NodeType> keyTypes()
      Returns the set of node types that are supported as keys in map nodes for this adapter.
      long longValue​(java.lang.Object node)
      Returns the long value of a number node.
      java.util.Set<NodeType> nodeTypes()
      Returns the set of node types supported by this adapter.
      java.lang.Object property​(java.lang.Object property, java.lang.Object node)
      Returns the property value associated with the specified key node in a map node.
      int size​(java.lang.Object node)
      Returns the number of entries in a map node or items in a collection node.
      java.lang.String stringValue​(java.lang.Object node)
      Returns the string value of the node.
      NodeType type​(java.lang.Object node)
      Returns the type of the given node.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • NativeAdapter

        public NativeAdapter()
    • Method Detail

      • isNode

        public boolean isNode​(java.lang.Object node)
        Description copied from interface: NodeAdapter
        Checks whether the given object can be processed by this adapter.

        Returns true if the adapter is capable of handling the node type; false otherwise.

        Specified by:
        isNode in interface NodeAdapter
        Parameters:
        node - the object to check
        Returns:
        true if the node can be adapted by this adapter, false otherwise
      • nodeTypes

        public java.util.Set<NodeType> nodeTypes()
        Description copied from interface: NodeAdapter
        Returns the set of node types supported by this adapter.
        Specified by:
        nodeTypes in interface NodeAdapter
        Returns:
        a set of supported node types
      • type

        public NodeType type​(java.lang.Object node)
        Description copied from interface: NodeAdapter
        Returns the type of the given node.
        Specified by:
        type in interface NodeAdapter
        Parameters:
        node - the node to inspect
        Returns:
        the NodeType of the node
      • keyTypes

        public java.util.Set<NodeType> keyTypes()
        Description copied from interface: NodeAdapter
        Returns the set of node types that are supported as keys in map nodes for this adapter.
        Specified by:
        keyTypes in interface NodeAdapter
        Returns:
        a set of supported key node types
      • keys

        public java.util.Collection<? extends java.lang.Object> keys​(java.lang.Object node)
        Description copied from interface: NodeAdapter
        Returns the collection of property key nodes for a map node.
        Specified by:
        keys in interface NodeAdapter
        Parameters:
        node - the map node
        Returns:
        collection of property key nodes
      • property

        public java.lang.Object property​(java.lang.Object property,
                                         java.lang.Object node)
        Description copied from interface: NodeAdapter
        Returns the property value associated with the specified key node in a map node.
        Specified by:
        property in interface NodeAdapter
        Parameters:
        property - the property key node
        node - the map node containing the property
        Returns:
        the property value node corresponding to the property key
      • entries

        public java.lang.Iterable<java.util.Map.Entry<?,​?>> entries​(java.lang.Object node)
        Description copied from interface: NodeAdapter
        Returns all key-value pairs of the given map node as an Iterable.
        Specified by:
        entries in interface NodeAdapter
        Parameters:
        node - the map node
        Returns:
        iterable of key-value entries
      • entryStream

        public java.util.stream.Stream<java.util.Map.Entry<?,​?>> entryStream​(java.lang.Object node)
        Description copied from interface: NodeAdapter
        Returns all key-value pairs of the given map node as a Stream.
        Specified by:
        entryStream in interface NodeAdapter
        Parameters:
        node - the map node
        Returns:
        stream of key-value entries
      • elements

        public java.lang.Iterable<? extends java.lang.Object> elements​(java.lang.Object node)
        Description copied from interface: NodeAdapter
        Returns the child nodes of a collection node as an Iterable.
        Specified by:
        elements in interface NodeAdapter
        Parameters:
        node - the collection node
        Returns:
        iterable of child nodes
      • elementStream

        public java.util.stream.Stream<? extends java.lang.Object> elementStream​(java.lang.Object node)
        Description copied from interface: NodeAdapter
        Returns the child nodes of a collection node as a Stream.
        Specified by:
        elementStream in interface NodeAdapter
        Parameters:
        node - the collection node
        Returns:
        stream of child nodes
      • stringValue

        public java.lang.String stringValue​(java.lang.Object node)
        Description copied from interface: NodeAdapter
        Returns the string value of the node.
        Specified by:
        stringValue in interface NodeAdapter
        Parameters:
        node - the string node
        Returns:
        string representation
      • intValue

        public int intValue​(java.lang.Object node)
        Description copied from interface: NodeAdapter
        Returns the integer value of a number node.
        Specified by:
        intValue in interface NodeAdapter
        Parameters:
        node - the number node
        Returns:
        integer value
      • longValue

        public long longValue​(java.lang.Object node)
        Description copied from interface: NodeAdapter
        Returns the long value of a number node.
        Specified by:
        longValue in interface NodeAdapter
        Parameters:
        node - the number node
        Returns:
        long value
      • bigIntegerValue

        public java.math.BigInteger bigIntegerValue​(java.lang.Object node)
        Description copied from interface: NodeAdapter
        Returns the BigInteger value of a number node.
        Specified by:
        bigIntegerValue in interface NodeAdapter
        Parameters:
        node - the number node
        Returns:
        BigInteger value
      • doubleValue

        public double doubleValue​(java.lang.Object node)
        Description copied from interface: NodeAdapter
        Returns the double value of a number node.
        Specified by:
        doubleValue in interface NodeAdapter
        Parameters:
        node - the number node
        Returns:
        double value
      • decimalValue

        public java.math.BigDecimal decimalValue​(java.lang.Object node)
        Description copied from interface: NodeAdapter
        Returns the BigDecimal value of a number node.
        Specified by:
        decimalValue in interface NodeAdapter
        Parameters:
        node - the number node
        Returns:
        BigDecimal value
      • binaryValue

        public byte[] binaryValue​(java.lang.Object node)
        Description copied from interface: NodeAdapter
        Returns the binary value of the node as a byte array.
        Specified by:
        binaryValue in interface NodeAdapter
        Parameters:
        node - the binary node
        Returns:
        byte array representation
      • asIterable

        public java.lang.Iterable<? extends java.lang.Object> asIterable​(java.lang.Object node)
        Description copied from interface: NodeAdapter
        Returns the node as an iterable.

        If the node is null, returns an empty iterable. If it is a single element, wraps it as a singleton iterable. Useful for iterating without type checks.

        Specified by:
        asIterable in interface NodeAdapter
        Parameters:
        node - the node to convert
        Returns:
        iterable of elements
      • asStream

        public java.util.stream.Stream<? extends java.lang.Object> asStream​(java.lang.Object node)
        Description copied from interface: NodeAdapter
        Returns the node as a stream.
        Specified by:
        asStream in interface NodeAdapter
        Parameters:
        node - the node to convert
        Returns:
        stream of elements
      • isNull

        public boolean isNull​(java.lang.Object node)
        Description copied from interface: NodeAdapter
        Checks whether the node represents a null value.
        Specified by:
        isNull in interface NodeAdapter
        Parameters:
        node - the node to check
        Returns:
        true if the node is null, false otherwise
      • isBoolean

        public boolean isBoolean​(java.lang.Object node)
        Description copied from interface: NodeAdapter
        Checks whether the node represents a boolean value.
        Specified by:
        isBoolean in interface NodeAdapter
        Parameters:
        node - the node to check
        Returns:
        true if the node is a boolean, false otherwise
      • isMap

        public boolean isMap​(java.lang.Object node)
        Description copied from interface: NodeAdapter
        Checks whether the node represents a map (object) structure.
        Specified by:
        isMap in interface NodeAdapter
        Parameters:
        node - the node to check
        Returns:
        true if the node is a map, false otherwise
      • isCollection

        public boolean isCollection​(java.lang.Object node)
        Description copied from interface: NodeAdapter
        Checks whether the node represents a collection.
        Specified by:
        isCollection in interface NodeAdapter
        Parameters:
        node - the node to check
        Returns:
        true if the node is a collection, false otherwise
      • isList

        public boolean isList​(java.lang.Object node)
        Description copied from interface: NodeAdapter
        Preserves insertion order and can contain duplicates.
        Specified by:
        isList in interface NodeAdapter
        Returns:
      • isSet

        public boolean isSet​(java.lang.Object node)
        Description copied from interface: NodeAdapter
        Contains only unique elements. Is unordered.
        Specified by:
        isSet in interface NodeAdapter
        Returns:
      • isString

        public boolean isString​(java.lang.Object node)
        Description copied from interface: NodeAdapter
        Checks whether the node represents a string value.
        Specified by:
        isString in interface NodeAdapter
        Parameters:
        node - the node to check
        Returns:
        true if the node is a string, false otherwise
      • isNumber

        public boolean isNumber​(java.lang.Object node)
        Description copied from interface: NodeAdapter
        Checks whether the node represents a numeric value.
        Specified by:
        isNumber in interface NodeAdapter
        Parameters:
        node - the node to check
        Returns:
        true if the node is numeric, false otherwise
      • isIntegral

        public boolean isIntegral​(java.lang.Object node)
        Description copied from interface: NodeAdapter
        Checks whether a number node represents an integral value.

        Returns false for floating-point or BigDecimal nodes.

        Specified by:
        isIntegral in interface NodeAdapter
        Parameters:
        node - the number node
        Returns:
        true if the node is integral, false otherwise
      • isBinary

        public boolean isBinary​(java.lang.Object node)
        Description copied from interface: NodeAdapter
        Checks whether the node contains binary data.
        Specified by:
        isBinary in interface NodeAdapter
        Parameters:
        node - the node to check
        Returns:
        true if the node is binary, false otherwise
      • isEmpty

        public boolean isEmpty​(java.lang.Object node)
        Description copied from interface: NodeAdapter
        Checks whether a map node has no entries or a collection node has no items.

        This method is intended for nodes of type NodeType.MAP or NodeType.COLLECTION.

        Specified by:
        isEmpty in interface NodeAdapter
        Parameters:
        node - the node to inspect
        Returns:
        true if the map has no entries or the collection has no items, false otherwise
      • size

        public int size​(java.lang.Object node)
        Description copied from interface: NodeAdapter
        Returns the number of entries in a map node or items in a collection node.

        Intended for nodes of type NodeType.MAP or NodeType.COLLECTION.

        Specified by:
        size in interface NodeAdapter
        Parameters:
        node - the node to inspect
        Returns:
        number of entries (for map) or items (for collection)
      • asString

        public java.lang.String asString​(java.lang.Object node)
        Description copied from interface: NodeAdapter
        Returns the string representation of the node, converting other types as needed.
        Specified by:
        asString in interface NodeAdapter
        Parameters:
        node - the node to convert
        Returns:
        string representation
      • asDecimal

        public java.math.BigDecimal asDecimal​(java.lang.Object node)
        Description copied from interface: NodeAdapter
        Converts the given node to a BigDecimal, if possible.
        Specified by:
        asDecimal in interface NodeAdapter
        Parameters:
        node - the node to convert
        Returns:
        BigDecimal representation of the node
      • adapt

        public static final java.lang.Object adapt​(java.lang.Object value,
                                                   NodeAdapter adapter)