Interface NodeAdapter

  • All Known Implementing Classes:
    Jackson2Adapter, JakartaAdapter, NativeAdapter

    public interface NodeAdapter
    Provides a uniform abstraction for reading tree-like data structures.

    Implementations can support any tree representation (JSON, YAML, CBOR, etc.) and any underlying library (Jackson, Gson, Jakarta, etc.).

    Each adapter may support only a subset of nodes from a representation. Methods may throw IllegalArgumentException, ClassCastException, NullPointerException, or IllegalStateException if a node cannot be processed or an operation fails.

    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      java.math.BigDecimal asDecimal​(java.lang.Object node)
      Converts the given node to a BigDecimal, if possible.
      java.lang.Iterable<?> asIterable​(java.lang.Object node)
      Returns the node as an iterable.
      java.util.stream.Stream<?> 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<?> elements​(java.lang.Object node)
      Returns the child nodes of a collection node as an Iterable.
      java.util.stream.Stream<?> 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.
      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<?> 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 key, 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.
    • Method Detail

      • isNode

        boolean isNode​(java.lang.Object node)
        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.

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

        java.util.Set<NodeType> nodeTypes()
        Returns the set of node types supported by this adapter.
        Returns:
        a set of supported node types
      • keyTypes

        java.util.Set<NodeType> keyTypes()
        Returns the set of node types that are supported as keys in map nodes for this adapter.
        Returns:
        a set of supported key node types
      • type

        NodeType type​(java.lang.Object node)
        Returns the type of the given node.
        Parameters:
        node - the node to inspect
        Returns:
        the NodeType of the node
      • isNull

        boolean isNull​(java.lang.Object node)
        Checks whether the node represents a null value.
        Parameters:
        node - the node to check
        Returns:
        true if the node is null, false otherwise
      • isBoolean

        boolean isBoolean​(java.lang.Object node)
        Checks whether the node represents a boolean value.
        Parameters:
        node - the node to check
        Returns:
        true if the node is a boolean, false otherwise
      • isBinary

        boolean isBinary​(java.lang.Object node)
        Checks whether the node contains binary data.
        Parameters:
        node - the node to check
        Returns:
        true if the node is binary, false otherwise
      • size

        int size​(java.lang.Object node)
        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.

        Parameters:
        node - the node to inspect
        Returns:
        number of entries (for map) or items (for collection)
      • isEmpty

        boolean isEmpty​(java.lang.Object node)
        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.

        Parameters:
        node - the node to inspect
        Returns:
        true if the map has no entries or the collection has no items, false otherwise
      • isMap

        boolean isMap​(java.lang.Object node)
        Checks whether the node represents a map (object) structure.
        Parameters:
        node - the node to check
        Returns:
        true if the node is a map, false otherwise
      • keys

        java.util.Collection<?> keys​(java.lang.Object node)
        Returns the collection of property key nodes for a map node.
        Parameters:
        node - the map node
        Returns:
        collection of property key nodes
      • property

        java.lang.Object property​(java.lang.Object key,
                                  java.lang.Object node)
        Returns the property value associated with the specified key node in a map node.
        Parameters:
        key - the property key node
        node - the map node containing the property
        Returns:
        the property value node corresponding to the property key
      • entries

        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.
        Parameters:
        node - the map node
        Returns:
        iterable of key-value entries
      • entryStream

        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.
        Parameters:
        node - the map node
        Returns:
        stream of key-value entries
      • isCollection

        boolean isCollection​(java.lang.Object node)
        Checks whether the node represents a collection.
        Parameters:
        node - the node to check
        Returns:
        true if the node is a collection, false otherwise
      • isList

        boolean isList​(java.lang.Object node)
        Preserves insertion order and can contain duplicates.
        Parameters:
        node -
        Returns:
      • isSet

        boolean isSet​(java.lang.Object node)
        Contains only unique elements. Is unordered.
        Parameters:
        node -
        Returns:
      • elements

        java.lang.Iterable<?> elements​(java.lang.Object node)
        Returns the child nodes of a collection node as an Iterable.
        Parameters:
        node - the collection node
        Returns:
        iterable of child nodes
      • elementStream

        java.util.stream.Stream<?> elementStream​(java.lang.Object node)
        Returns the child nodes of a collection node as a Stream.
        Parameters:
        node - the collection node
        Returns:
        stream of child nodes
      • isString

        boolean isString​(java.lang.Object node)
        Checks whether the node represents a string value.
        Parameters:
        node - the node to check
        Returns:
        true if the node is a string, false otherwise
      • stringValue

        java.lang.String stringValue​(java.lang.Object node)
        Returns the string value of the node.
        Parameters:
        node - the string node
        Returns:
        string representation
      • isNumber

        boolean isNumber​(java.lang.Object node)
        Checks whether the node represents a numeric value.
        Parameters:
        node - the node to check
        Returns:
        true if the node is numeric, false otherwise
      • isIntegral

        boolean isIntegral​(java.lang.Object node)
        Checks whether a number node represents an integral value.

        Returns false for floating-point or BigDecimal nodes.

        Parameters:
        node - the number node
        Returns:
        true if the node is integral, false otherwise
      • intValue

        int intValue​(java.lang.Object node)
        Returns the integer value of a number node.
        Parameters:
        node - the number node
        Returns:
        integer value
      • longValue

        long longValue​(java.lang.Object node)
        Returns the long value of a number node.
        Parameters:
        node - the number node
        Returns:
        long value
      • bigIntegerValue

        java.math.BigInteger bigIntegerValue​(java.lang.Object node)
        Returns the BigInteger value of a number node.
        Parameters:
        node - the number node
        Returns:
        BigInteger value
      • doubleValue

        double doubleValue​(java.lang.Object node)
        Returns the double value of a number node.
        Parameters:
        node - the number node
        Returns:
        double value
      • decimalValue

        java.math.BigDecimal decimalValue​(java.lang.Object node)
        Returns the BigDecimal value of a number node.
        Parameters:
        node - the number node
        Returns:
        BigDecimal value
      • binaryValue

        byte[] binaryValue​(java.lang.Object node)
        Returns the binary value of the node as a byte array.
        Parameters:
        node - the binary node
        Returns:
        byte array representation
      • asIterable

        java.lang.Iterable<?> asIterable​(java.lang.Object node)
        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.

        Parameters:
        node - the node to convert
        Returns:
        iterable of elements
      • asStream

        java.util.stream.Stream<?> asStream​(java.lang.Object node)
        Returns the node as a stream.
        Parameters:
        node - the node to convert
        Returns:
        stream of elements
      • asString

        java.lang.String asString​(java.lang.Object node)
        Returns the string representation of the node, converting other types as needed.
        Parameters:
        node - the node to convert
        Returns:
        string representation
      • asDecimal

        java.math.BigDecimal asDecimal​(java.lang.Object node)
        Converts the given node to a BigDecimal, if possible.
        Parameters:
        node - the node to convert
        Returns:
        BigDecimal representation of the node