Package jsonvalues
Interface Position
-
- All Superinterfaces:
Comparable<Position>
public interface Position extends 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 IndexasIndex()Casts this position into an Index, throwing an exception if it's a Key.KeyasKey()Casts this position into a Key, throwing an exception if it's an index.intcompareTo(Position o)booleanisIndex()Returns true if this position is an index.default booleanisIndex(IntPredicate predicate)Returns true if this position is an index and its index tested on a given predicate is true.booleanisKey()Returns true if this position is an key.default booleanisKey(Predicate<String> predicate)Returns true if this position is a key and its name tested on a given predicate is true.default <T> Tmatch(Function<String,T> keyFn, IntFunction<T> indexFn)Returns a new value applying pattern matching on the Position type.
-
-
-
Method Detail
-
compareTo
int compareTo(Position o)
- Specified by:
compareToin interfaceComparable<Position>
-
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
-
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
-
isIndex
boolean isIndex()
Returns true if this position is an index.- Returns:
- true if this position is an index
-
isKey
boolean isKey()
Returns true if this position is an key.- Returns:
- true if this position is an key
-
isKey
default boolean isKey(Predicate<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
default boolean isIndex(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
-
match
default <T> T match(Function<String,T> keyFn, 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 keyindexFn- function to apply if this Position is an index- Returns:
- an object of type T
-
-