Class ExtensionKt
-
- All Implemented Interfaces:
public final class ExtensionKt
-
-
Method Summary
Modifier and Type Method Description final TgetValue()final static <T extends JSONValue> UnitifPresent(ResourceRef<JSONObject> $self, String name, Function2<ResourceRef<T>, T, Unit> block)Conditionally execute if JSONObject referenced by thisResourceRef contains a member with the specified key and the expected type.final static <T extends JSONPrimitive<R>, R extends Any> List<R>map(ResourceRef<JSONArray> $self)Map the values of the JSONArray referenced by thisResourceRef to an array of the primitive type for the JSONValue.final static <T extends JSONValue, R extends Any> List<R>map(ResourceRef<JSONArray> $self, Function2<ResourceRef<T>, Integer, R> transform)Map the values of the JSONArray referenced by thisResourceRef to an array of the target type, applying a transformation to each item.final static <T extends JSONValue, R extends Any> Rmap(ResourceRef<JSONObject> $self, String name, Function2<ResourceRef<T>, T, R> block)Map the JSONObject property referenced by thisResourceRef and the specified key, using the provided mapping function.final static <T extends JSONValue> Booleanany(ResourceRef<JSONArray> $self, Function2<ResourceRef<T>, Integer, Boolean> predicate)Return trueif any of the values of the JSONArray referenced bythisResourceRef satisfy a given predicate.final static <T extends JSONValue> Booleanall(ResourceRef<JSONArray> $self, Function2<ResourceRef<T>, Integer, Boolean> predicate)Return trueif all of the values of the JSONArray referenced bythisResourceRef satisfy a given predicate.final static StringoptionalString(ResourceRef<JSONObject> $self, String name)Get a String property from a JSONObject using thisResourceRef 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(ResourceRef<JSONObject> $self, String name)Get a Boolean property from a JSONObject using thisResourceRef 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(ResourceRef<JSONObject> $self, String name)Get an Int property from a JSONObject using thisResourceRef 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(ResourceRef<JSONObject> $self, String name)Get a Long property from a JSONObject using thisResourceRef 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(ResourceRef<JSONObject> $self, String name)Get a BigDecimal property from a JSONObject using thisResourceRef 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> ResourceRef<T>optionalChild(ResourceRef<JSONObject> $self, String name)Get a child property ResourceRef from a JSONObject using thisResourceRef 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(ResourceRef<JSONObject> $self, Function2<ResourceRef<T>, String, Unit> block)Iterate over the members of the JSONObject referenced by thisResourceRef.final static <T extends JSONValue> UnitforEach(ResourceRef<JSONArray> $self, Function2<ResourceRef<T>, Integer, Unit> block)Iterate over the members of the JSONArray referenced by thisResourceRef.final static <T extends JSONValue> ResourceRef<T>child(ResourceRef<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> ResourceRef<T>child(ResourceRef<JSONArray> $self, Integer index)Get the named child reference (strongly typed) from this JSONArray reference, using the implied child type. final static ResourceRef<JSONValue>untypedChild(ResourceRef<JSONObject> $self, String name)Get the named child reference (untyped) from this JSONObject reference. final static ResourceRef<JSONValue>untypedChild(ResourceRef<JSONArray> $self, Integer index)Get the named child reference (untyped) from this JSONArray reference. final static <T extends JSONValue> BooleanhasChild(ResourceRef<JSONObject> $self, String name)Test whether this JSONObject reference has the named child with the implied type. final static <T extends JSONValue> BooleanhasChild(ResourceRef<JSONArray> $self, Integer index)Test whether this JSONArray reference has a child at the given index with the implied type. final static UnitcheckName(ResourceRef<JSONObject> $self, String name)Check that this JSONObject reference has the named child, and throw an exception if not. final static UnitcheckIndex(ResourceRef<JSONArray> $self, Integer index)Check that this JSONArray reference has a child at the given index, and throw an exception if not. final static ResourceRef<JSONObject>ref(Resource<JSONObject> $self)Load a Resource and create a reference. -
-
Method Detail
-
ifPresent
final static <T extends JSONValue> Unit ifPresent(ResourceRef<JSONObject> $self, String name, Function2<ResourceRef<T>, T, Unit> block)
Conditionally execute if JSONObject referenced by
thisResourceRef 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(ResourceRef<JSONArray> $self)
Map the values of the JSONArray referenced by
thisResourceRef to an array of the primitive type for the JSONValue.
-
map
final static <T extends JSONValue, R extends Any> List<R> map(ResourceRef<JSONArray> $self, Function2<ResourceRef<T>, Integer, R> transform)
Map the values of the JSONArray referenced by
thisResourceRef 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(ResourceRef<JSONObject> $self, String name, Function2<ResourceRef<T>, T, R> block)
Map the JSONObject property referenced by
thisResourceRef and the specified key, using the provided mapping function.
-
any
final static <T extends JSONValue> Boolean any(ResourceRef<JSONArray> $self, Function2<ResourceRef<T>, Integer, Boolean> predicate)
Return
trueif any of the values of the JSONArray referenced bythisResourceRef satisfy a given predicate.
-
all
final static <T extends JSONValue> Boolean all(ResourceRef<JSONArray> $self, Function2<ResourceRef<T>, Integer, Boolean> predicate)
Return
trueif all of the values of the JSONArray referenced bythisResourceRef satisfy a given predicate.
-
optionalString
final static String optionalString(ResourceRef<JSONObject> $self, String name)
Get a String property from a JSONObject using
thisResourceRef and the specified key, ornullif the property is not present (throws an exception if the property is present but is the wrong type).
-
optionalBoolean
final static Boolean optionalBoolean(ResourceRef<JSONObject> $self, String name)
Get a Boolean property from a JSONObject using
thisResourceRef and the specified key, ornullif the property is not present (throws an exception if the property is present but is the wrong type).
-
optionalInt
final static Integer optionalInt(ResourceRef<JSONObject> $self, String name)
Get an Int property from a JSONObject using
thisResourceRef and the specified key, ornullif the property is not present (throws an exception if the property is present but is the wrong type).
-
optionalLong
final static Long optionalLong(ResourceRef<JSONObject> $self, String name)
Get a Long property from a JSONObject using
thisResourceRef 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).
-
optionalDecimal
final static BigDecimal optionalDecimal(ResourceRef<JSONObject> $self, String name)
Get a BigDecimal property from a JSONObject using
thisResourceRef 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> ResourceRef<T> optionalChild(ResourceRef<JSONObject> $self, String name)
Get a child property ResourceRef from a JSONObject using
thisResourceRef and the specified key, ornullif the property is not present (throws an exception if the property is present but is the wrong type).
-
forEachKey
final static <T extends JSONValue> Unit forEachKey(ResourceRef<JSONObject> $self, Function2<ResourceRef<T>, String, Unit> block)
Iterate over the members of the JSONObject referenced by
thisResourceRef.
-
forEach
final static <T extends JSONValue> Unit forEach(ResourceRef<JSONArray> $self, Function2<ResourceRef<T>, Integer, Unit> block)
Iterate over the members of the JSONArray referenced by
thisResourceRef.
-
child
final static <T extends JSONValue> ResourceRef<T> child(ResourceRef<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> ResourceRef<T> child(ResourceRef<JSONArray> $self, Integer index)
Get the named child reference (strongly typed) from this JSONArray reference, using the implied child type.
-
untypedChild
final static ResourceRef<JSONValue> untypedChild(ResourceRef<JSONObject> $self, String name)
Get the named child reference (untyped) from this JSONObject reference.
-
untypedChild
final static ResourceRef<JSONValue> untypedChild(ResourceRef<JSONArray> $self, Integer index)
Get the named child reference (untyped) from this JSONArray reference.
-
hasChild
final static <T extends JSONValue> Boolean hasChild(ResourceRef<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(ResourceRef<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(ResourceRef<JSONObject> $self, String name)
Check that this JSONObject reference has the named child, and throw an exception if not.
-
checkIndex
final static Unit checkIndex(ResourceRef<JSONArray> $self, Integer index)
Check that this JSONArray reference has a child at the given index, and throw an exception if not.
-
ref
final static ResourceRef<JSONObject> ref(Resource<JSONObject> $self)
Load a Resource and create a reference.
-
-
-
-