Class ExtensionKt
-
- All Implemented Interfaces:
public final class ExtensionKt
-
-
Method Summary
Modifier and Type Method Description final TgetValue()final static <T extends JSONValue> JSONRef<T>ptr(JSONValue $self, JSONPointer pointer)Create a JSONRef from thisJSONValue and the specified JSONPointer.final static <T extends JSONValue> UnitifPresent(JSONRef<JSONObject> $self, String name, Function2<JSONRef<T>, T, Unit> block)Conditionally execute if JSONObject referenced by thisJSONRef contains a member with the specified key and the expected type.final static <T extends JSONPrimitive<R>, R extends Any> List<R>map(JSONRef<JSONArray> $self)Map the values of the JSONArray referenced by thisJSONRef to an array of the primitive type for the JSONValue.final static <T extends JSONValue, R extends Any> List<R>map(JSONRef<JSONArray> $self, Function2<JSONRef<T>, Integer, R> transform)Map the values of the JSONArray referenced by thisJSONRef to an array of the target type, applying a transformation to each item.final static <T extends JSONValue, R extends Any> Rmap(JSONRef<JSONObject> $self, String name, Function2<JSONRef<T>, T, R> block)Map the JSONObject property referenced by thisJSONRef and the specified key, using the provided mapping function.final static <T extends JSONValue> Booleanany(JSONRef<JSONArray> $self, Function2<JSONRef<T>, Integer, Boolean> predicate)Return trueif any of the values of the JSONArray referenced bythisJSONRef satisfy a given predicate.final static <T extends JSONValue> Booleanall(JSONRef<JSONArray> $self, Function2<JSONRef<T>, Integer, Boolean> predicate)Return trueif all of the values of the JSONArray referenced bythisJSONRef satisfy a given predicate.final static <T extends JSONValue, R extends Any> RmapIfPresent(JSONRef<JSONObject> $self, String name, Function2<JSONRef<T>, T, R> block)Map the JSONObject property referenced by thisJSONRef and the specified key, using the provided mapping function, returningnullif property not present.final static StringoptionalString(JSONRef<JSONObject> $self, String name)Get a String property from a JSONObject using thisJSONRef and the specified key, ornullif the property is not present (throws an exception if the property is present but is the wrong type).final static BooleanoptionalBoolean(JSONRef<JSONObject> $self, String name)Get a Boolean property from a JSONObject using thisJSONRef and the specified key, ornullif the property is not present (throws an exception if the property is present but is the wrong type).final static IntegeroptionalInt(JSONRef<JSONObject> $self, String name)Get an Int property from a JSONObject using thisJSONRef and the specified key, ornullif the property is not present (throws an exception if the property is present but is the wrong type).final static LongoptionalLong(JSONRef<JSONObject> $self, String name)Get a Long property from a JSONObject using thisJSONRef and the specified key, ornullif the property is not present (throws an exception if the property is present but is not an Int or Long).final static BigDecimaloptionalDecimal(JSONRef<JSONObject> $self, String name)Get a BigDecimal property from a JSONObject using thisJSONRef and the specified key, ornullif the property is not present (throws an exception if the property is present but is the wrong type).final static <T extends JSONValue> JSONRef<T>optionalChild(JSONRef<JSONObject> $self, String name)Get a child property JSONRef from a JSONObject using thisJSONRef and the specified key, ornullif the property is not present (throws an exception if the property is present but is the wrong type).final static <T extends JSONValue> UnitforEachKey(JSONRef<JSONObject> $self, Function2<JSONRef<T>, String, Unit> block)Iterate over the members of the JSONObject referenced by thisJSONRef.final static <T extends JSONValue> UnitforEach(JSONRef<JSONArray> $self, Function2<JSONRef<T>, Integer, Unit> block)Iterate over the members of the JSONArray referenced by thisJSONRef.final static <T extends JSONValue> JSONRef<T>child(JSONRef<JSONObject> $self, String name)Get the named child reference (strongly typed) from this JSONObject reference, using the implied child type. final static <T extends JSONValue> JSONRef<T>child(JSONRef<JSONArray> $self, Integer index)Get the named child reference (strongly typed) from this JSONArray reference, using the implied child type. final static JSONRef<JSONValue>untypedChild(JSONRef<JSONObject> $self, String name)Get the named child reference (untyped) from this JSONObject reference. final static JSONRef<JSONValue>untypedChild(JSONRef<JSONArray> $self, Integer index)Get the named child reference (untyped) from this JSONArray reference. final static <T extends JSONValue> BooleanhasChild(JSONRef<JSONObject> $self, String name)Test whether this JSONObject reference has the named child with the implied type. final static <T extends JSONValue> BooleanhasChild(JSONRef<JSONArray> $self, Integer index)Test whether this JSONArray reference has a child at the given index with the implied type. final static UnitcheckName(JSONRef<JSONObject> $self, String name)Check that this JSONObject reference has the named child, and throw an exception if not. final static UnitcheckIndex(JSONRef<JSONArray> $self, Integer index)Check that this JSONArray reference has a child at the given index, and throw an exception if not. final static <T extends JSONValue> JSONRef<T>ref(T $self)Create a reference to this JSONValue. -
-
Method Detail
-
ptr
final static <T extends JSONValue> JSONRef<T> ptr(JSONValue $self, JSONPointer pointer)
Create a JSONRef from
thisJSONValue and the specified JSONPointer.
-
ifPresent
final static <T extends JSONValue> Unit ifPresent(JSONRef<JSONObject> $self, String name, Function2<JSONRef<T>, T, Unit> block)
Conditionally execute if JSONObject referenced by
thisJSONRef contains a member with the specified key and the expected type.NOTE: this function will not throw an exception if the property is present but is of the wrong type, and it may be removed from future releases. To achieve the same effect with strong type checking, use:
ref.optionalChild<JSONObject>("name")?.let { doSomething(it) }
-
map
final static <T extends JSONPrimitive<R>, R extends Any> List<R> map(JSONRef<JSONArray> $self)
Map the values of the JSONArray referenced by
thisJSONRef to an array of the primitive type for the JSONValue.
-
map
final static <T extends JSONValue, R extends Any> List<R> map(JSONRef<JSONArray> $self, Function2<JSONRef<T>, Integer, R> transform)
Map the values of the JSONArray referenced by
thisJSONRef to an array of the target type, applying a transformation to each item.
-
map
@Deprecated(message = "Confusing function name", replaceWith = @ReplaceWith(imports = {}, expression = "child(name).apply(block)")) final static <T extends JSONValue, R extends Any> R map(JSONRef<JSONObject> $self, String name, Function2<JSONRef<T>, T, R> block)
Map the JSONObject property referenced by
thisJSONRef and the specified key, using the provided mapping function.
-
any
final static <T extends JSONValue> Boolean any(JSONRef<JSONArray> $self, Function2<JSONRef<T>, Integer, Boolean> predicate)
Return
trueif any of the values of the JSONArray referenced bythisJSONRef satisfy a given predicate.
-
all
final static <T extends JSONValue> Boolean all(JSONRef<JSONArray> $self, Function2<JSONRef<T>, Integer, Boolean> predicate)
Return
trueif all of the values of the JSONArray referenced bythisJSONRef satisfy a given predicate.
-
mapIfPresent
@Deprecated(message = "Does not check property type", replaceWith = @ReplaceWith(imports = {}, expression = "optionalChild(name)?.apply(block)")) final static <T extends JSONValue, R extends Any> R mapIfPresent(JSONRef<JSONObject> $self, String name, Function2<JSONRef<T>, T, R> block)
Map the JSONObject property referenced by
thisJSONRef and the specified key, using the provided mapping function, returningnullif property not present.NOTE: this function will not throw an exception if the property is present but is of the wrong type, and it has been deprecated. To achieve the same effect with strong type checking, use:
ref.optionalChild<JSONObject>("name")?.let { doSomething(it) }
-
optionalString
final static String optionalString(JSONRef<JSONObject> $self, String name)
-
optionalBoolean
final static Boolean optionalBoolean(JSONRef<JSONObject> $self, String name)
-
optionalInt
final static Integer optionalInt(JSONRef<JSONObject> $self, String name)
-
optionalLong
final static Long optionalLong(JSONRef<JSONObject> $self, String name)
-
optionalDecimal
final static BigDecimal optionalDecimal(JSONRef<JSONObject> $self, String name)
Get a BigDecimal property from a JSONObject using
thisJSONRef and the specified key, ornullif the property is not present (throws an exception if the property is present but is the wrong type).
-
optionalChild
final static <T extends JSONValue> JSONRef<T> optionalChild(JSONRef<JSONObject> $self, String name)
-
forEachKey
final static <T extends JSONValue> Unit forEachKey(JSONRef<JSONObject> $self, Function2<JSONRef<T>, String, Unit> block)
Iterate over the members of the JSONObject referenced by
thisJSONRef.
-
forEach
final static <T extends JSONValue> Unit forEach(JSONRef<JSONArray> $self, Function2<JSONRef<T>, Integer, Unit> block)
Iterate over the members of the JSONArray referenced by
thisJSONRef.
-
child
final static <T extends JSONValue> JSONRef<T> child(JSONRef<JSONObject> $self, String name)
Get the named child reference (strongly typed) from this JSONObject reference, using the implied child type.
-
child
final static <T extends JSONValue> JSONRef<T> child(JSONRef<JSONArray> $self, Integer index)
Get the named child reference (strongly typed) from this JSONArray reference, using the implied child type.
-
untypedChild
final static JSONRef<JSONValue> untypedChild(JSONRef<JSONObject> $self, String name)
Get the named child reference (untyped) from this JSONObject reference.
-
untypedChild
final static JSONRef<JSONValue> untypedChild(JSONRef<JSONArray> $self, Integer index)
Get the named child reference (untyped) from this JSONArray reference.
-
hasChild
final static <T extends JSONValue> Boolean hasChild(JSONRef<JSONObject> $self, String name)
Test whether this JSONObject reference has the named child with the implied type.
-
hasChild
final static <T extends JSONValue> Boolean hasChild(JSONRef<JSONArray> $self, Integer index)
Test whether this JSONArray reference has a child at the given index with the implied type.
-
checkName
final static Unit checkName(JSONRef<JSONObject> $self, String name)
Check that this JSONObject reference has the named child, and throw an exception if not.
-
checkIndex
final static Unit checkIndex(JSONRef<JSONArray> $self, Integer index)
Check that this JSONArray reference has a child at the given index, and throw an exception if not.
-
-
-
-