Package jsonvalues

Interface Position

  • All Superinterfaces:
    java.lang.Comparable<Position>
    All Known Implementing Classes:
    Index, Key

    public interface Position
    extends java.lang.Comparable<Position>
    Represents the location of a first-level element in a json, either a Key in a JsObj or an Index in a JsArray.
    • Method Summary

      All Methods Instance Methods Abstract Methods Default Methods 
      Modifier and Type Method Description
      Index asIndex()
      Casts this position into an Index, throwing an exception if it's a Key.
      Key asKey()
      Casts this position into a Key, throwing an exception if it's an index.
      boolean isIndex()
      Returns true if this position is an index.
      default boolean isIndex​(java.util.function.IntPredicate predicate)
      Returns true if this position is an index and its index tested on a given predicate is true.
      boolean isKey()
      Returns true if this position is an key.
      default boolean isKey​(java.util.function.Predicate<java.lang.String> predicate)
      Returns true if this position is a key and its name tested on a given predicate is true.
      default <T> T match​(java.util.function.Function<java.lang.String,​T> keyFn, java.util.function.IntFunction<T> indexFn)
      Returns a new value applying pattern matching on the Position type.
      • Methods inherited from interface java.lang.Comparable

        compareTo
    • Method Detail

      • isKey

        default boolean isKey​(java.util.function.Predicate<java.lang.String> predicate)
        Returns true if this position is a key and its name tested on a given predicate is true.
        Parameters:
        predicate - the give predicate
        Returns:
        true if this position is a key and its name tested on a given predicate is true
      • isIndex

        boolean isIndex()
        Returns true if this position is an index.
        Returns:
        true if this position is an index
      • asKey

        Key asKey()
        Casts this position into a Key, throwing an exception if it's an index.
        Returns:
        this position as a Key
        Throws:
        UserError - if this position is an Index
      • isIndex

        default boolean isIndex​(java.util.function.IntPredicate predicate)
        Returns true if this position is an index and its index tested on a given predicate is true.
        Parameters:
        predicate - the give predicate
        Returns:
        true if this position is an index and its index tested on a given predicate is true
      • isKey

        boolean isKey()
        Returns true if this position is an key.
        Returns:
        true if this position is an key
      • asIndex

        Index asIndex()
        Casts this position into an Index, throwing an exception if it's a Key.
        Returns:
        this position as an Index
        Throws:
        UserError - if this position is an Key
      • match

        default <T> T match​(java.util.function.Function<java.lang.String,​T> keyFn,
                            java.util.function.IntFunction<T> indexFn)
        Returns a new value applying pattern matching on the Position type.
        Type Parameters:
        T - the type of the object returned
        Parameters:
        keyFn - function to apply if this Position is a key
        indexFn - function to apply if this Position is an index
        Returns:
        an object of type T