Class NativeAdapter

java.lang.Object
com.apicatalog.tree.io.java.NativeAdapter
All Implemented Interfaces:
TreeAdapter

public class NativeAdapter extends Object implements TreeAdapter
  • Constructor Details

    • NativeAdapter

      public NativeAdapter()
  • Method Details

    • instance

      public static final NativeAdapter instance()
    • features

      public Features features()
      Specified by:
      features in interface TreeAdapter
    • isNode

      public boolean isNode(Object node)
      Description copied from interface: TreeAdapter
      Checks 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:
      isNode in interface TreeAdapter
      Parameters:
      node - the object to check, which may be null.
      Returns:
      true if the adapter can handle the object's type, false otherwise.
    • type

      public NodeType type(Object node)
      Description copied from interface: TreeAdapter
      Determines the NodeType of the given native node.
      Specified by:
      type in interface TreeAdapter
      Parameters:
      node - the node to inspect, which must be a valid node for this adapter.
      Returns:
      the NodeType corresponding to the node.
    • keys

      public Collection<? extends Object> keys(Object node)
      Description copied from interface: TreeAdapter
      Returns 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:
      keys in interface TreeAdapter
      Parameters:
      node - the map node to inspect.
      Returns:
      a collection containing the map's native key objects.
    • property

      public Object property(Object property, Object node)
      Description copied from interface: TreeAdapter
      Retrieves the value associated with a given native key object from a map node.
      Specified by:
      property in interface TreeAdapter
      Parameters:
      property - the native key object used for the lookup.
      node - the map node to query.
      Returns:
      the native value node, or null if the key is not found.
    • property

      public Object property(Object key, TreeAdapter keyAdapter, Object node)
      Specified by:
      property in interface TreeAdapter
    • entries

      public Iterable<Map.Entry<?,?>> entries(Object node)
      Description copied from interface: TreeAdapter
      Returns all key-value pairs of a map node as an Iterable. The entries contain the native key and value objects.
      Specified by:
      entries in interface TreeAdapter
      Parameters:
      node - the map node to inspect.
      Returns:
      an Iterable of its entries.
    • entryStream

      public Stream<Map.Entry<?,?>> entryStream(Object node)
      Description copied from interface: TreeAdapter
      Returns all key-value pairs of a map node as a Stream. This is a convenience method for processing map entries using the Stream API.
      Specified by:
      entryStream in interface TreeAdapter
      Parameters:
      node - the map node to inspect.
      Returns:
      a Stream of its entries.
    • elements

      public Iterable<? extends Object> elements(Object node)
      Description copied from interface: TreeAdapter
      Returns the elements of a collection node as an Iterable.
      Specified by:
      elements in interface TreeAdapter
      Parameters:
      node - the collection node to inspect.
      Returns:
      an Iterable of its native element objects.
    • elementStream

      public Stream<? extends Object> elementStream(Object node)
      Description copied from interface: TreeAdapter
      Returns the elements of a collection node as a Stream.
      Specified by:
      elementStream in interface TreeAdapter
      Parameters:
      node - the collection node to inspect.
      Returns:
      a Stream of its native element objects.
    • stringValue

      public String stringValue(Object node)
      Description copied from interface: TreeAdapter
      Extracts the string value from a string node.
      Specified by:
      stringValue in interface TreeAdapter
      Parameters:
      node - the string node.
      Returns:
      the string value.
    • intValue

      public int intValue(Object node)
      Description copied from interface: TreeAdapter
      Extracts the int value from a numeric node. This may involve a narrowing primitive conversion.
      Specified by:
      intValue in interface TreeAdapter
      Parameters:
      node - the numeric node.
      Returns:
      the value as an int.
    • longValue

      public long longValue(Object node)
      Description copied from interface: TreeAdapter
      Extracts the long value from a numeric node. This may involve a narrowing primitive conversion.
      Specified by:
      longValue in interface TreeAdapter
      Parameters:
      node - the numeric node.
      Returns:
      the value as a long.
    • integerValue

      public BigInteger integerValue(Object node)
      Description copied from interface: TreeAdapter
      Extracts the BigInteger value from a numeric node.
      Specified by:
      integerValue in interface TreeAdapter
      Parameters:
      node - the numeric node.
      Returns:
      the value as a BigInteger.
    • doubleValue

      public double doubleValue(Object node)
      Description copied from interface: TreeAdapter
      Extracts the double value from a numeric node.
      Specified by:
      doubleValue in interface TreeAdapter
      Parameters:
      node - the numeric node.
      Returns:
      the value as a double.
    • decimalValue

      public BigDecimal decimalValue(Object node)
      Description copied from interface: TreeAdapter
      Extracts the BigDecimal value from a numeric node.
      Specified by:
      decimalValue in interface TreeAdapter
      Parameters:
      node - the numeric node.
      Returns:
      the value as a BigDecimal.
    • binaryValue

      public byte[] binaryValue(Object node)
      Description copied from interface: TreeAdapter
      Extracts the binary data from a binary node.
      Specified by:
      binaryValue in interface TreeAdapter
      Parameters:
      node - the binary node.
      Returns:
      the data as a byte array.
    • asIterable

      public Iterable<? extends Object> asIterable(Object node)
      Description copied from interface: TreeAdapter
      Returns the node's contents as a universal Iterable. 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:
      asIterable in interface TreeAdapter
      Parameters:
      node - the node to convert.
      Returns:
      a non-null Iterable representing the node's contents.
    • asStream

      public Stream<? extends Object> asStream(Object node)
      Description copied from interface: TreeAdapter
      Returns the node's contents as a universal Stream.
      Specified by:
      asStream in interface TreeAdapter
      Parameters:
      node - the node to convert.
      Returns:
      a non-null Stream representing the node's contents.
    • isNull

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

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

      public boolean isMap(Object node)
      Description copied from interface: TreeAdapter
      Checks if the adapted node represents a map (an object with key-value pairs).
      Specified by:
      isMap in interface TreeAdapter
      Parameters:
      node - the node to check.
      Returns:
      true if the node represents a map, false otherwise.
    • isCollection

      public boolean isCollection(Object node)
      Description copied from interface: TreeAdapter
      Checks if the adapted node represents a collection of elements (e.g., an array or list).
      Specified by:
      isCollection in interface TreeAdapter
      Parameters:
      node - the node to check.
      Returns:
      true if the node represents a collection, false otherwise.
    • isList

      public boolean isList(Object node)
      Description copied from interface: TreeAdapter
      Checks if the adapted collection node is a list (an ordered collection that allows duplicates).
      Specified by:
      isList in interface TreeAdapter
      Parameters:
      node - the collection node to check.
      Returns:
      true if the node is a list, false otherwise.
    • isSet

      public boolean isSet(Object node)
      Description copied from interface: TreeAdapter
      Checks if the adapted collection node is a set (an unordered collection of unique elements).
      Specified by:
      isSet in interface TreeAdapter
      Parameters:
      node - the collection node to check.
      Returns:
      true if the node is a set, false otherwise.
    • isString

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

      public boolean isNumber(Object node)
      Description copied from interface: TreeAdapter
      Checks if the adapted node represents any numeric value (integral or floating-point).
      Specified by:
      isNumber in interface TreeAdapter
      Parameters:
      node - the node to check.
      Returns:
      true if the node represents a number, false otherwise.
    • isIntegral

      public boolean isIntegral(Object node)
      Description copied from interface: TreeAdapter
      Checks if a number node represents an integral value (e.g., an integer or long) as opposed to a floating-point value.
      Specified by:
      isIntegral in interface TreeAdapter
      Parameters:
      node - the number node to check.
      Returns:
      true if the node's value is integral, false otherwise.
    • isBinary

      public boolean isBinary(Object node)
      Description copied from interface: TreeAdapter
      Checks if the adapted node contains binary data.
      Specified by:
      isBinary in interface TreeAdapter
      Parameters:
      node - the node to check.
      Returns:
      true if the node represents binary data, false otherwise.
    • isEmpty

      public boolean isEmpty(Object node)
      Description copied from interface: TreeAdapter
      Checks if a map or collection node is empty.
      Specified by:
      isEmpty in interface TreeAdapter
      Parameters:
      node - the structure node to inspect.
      Returns:
      true if the node contains no entries or elements, false otherwise.
    • size

      public int size(Object node)
      Description copied from interface: TreeAdapter
      Returns the number of entries in a map or elements in a collection. This method is intended for nodes where TreeAdapter.isMap(Object) or TreeAdapter.isCollection(Object) returns true.
      Specified by:
      size in interface TreeAdapter
      Parameters:
      node - the structure node to inspect.
      Returns:
      the number of entries (for a map) or elements (for a collection).
    • asString

      public String asString(Object node)
      Description copied from interface: TreeAdapter
      Returns a string representation of the node, coercing non-string scalar types where applicable.
      Specified by:
      asString in interface TreeAdapter
      Parameters:
      node - the node to convert.
      Returns:
      a string representation of the node's value.
    • asDecimal

      public BigDecimal asDecimal(Object node)
      Description copied from interface: TreeAdapter
      Converts a given node to a BigDecimal, if possible. This method can be used to treat both numeric and string nodes as decimal values.
      Specified by:
      asDecimal in interface TreeAdapter
      Parameters:
      node - the node to convert.
      Returns:
      the BigDecimal representation.
    • adapt

      public static final Object adapt(Object value, TreeAdapter adapter)
    • asCollection

      public static Collection<?> asCollection(Object node)