Package Torello.Java.JSON
Class RJArrIntoBoxedConsumer
- java.lang.Object
-
- Torello.Java.JSON.RJArrIntoBoxedConsumer
-
public class RJArrIntoBoxedConsumer extends java.lang.Object
Each of the methods in this class, all of which are declared'static'
, accept a standardJsonArray
as input, and make a (User-Specified) "Best Efforts" attempt to convert the elements of the Input-Array into one of Java's Boxed-Primitives.
Just to serve as a reminder, a Java 'Boxed Primitive
' structure is nearly identical to a primitive, save for the following differences:Boxed Primitive's
are wrapped in an (artificial) Object-Reference, and may be passed-by-reference, no different than any othe Java Object-Reference. (In reality they are variant of 'Value-Classes', and their wrappers do not actually exists)- Boxed-Types may be assigned null, and will not force
NullPointerException
to throw when they are assigned null - nor produce any other adverse or unintended issues.. - Boxed-Types have several Class-Member functions to which their values may be applied
Each Json-Array Element that is successfully converted into a Boxed-Value (or null) is subsequently passed to a (User-Provided)Consumer<X>
, where the Generic-Type'X'
is identical to (or a parent of) the Json-Array Method-Type in this class which you have selected.
This class is capable of processing 7 of the 8 Java Boxed-Types that are available. The standard type'java.lang.Character'
is not accomodated by any of the Json Array-Processing Classes in this Json-Package. For each method in this class, the user is expected to provide a singleJsonArray
as input, along with an appropriate & matching Consumer.Utilities for parsing Json Array's and sending the parsed values into a Java Consumer of Boxed-Primitives.
This class builds on the J2EE Standard 'Glass-Fish' JSON Processor
There are several JSON Parsers available, and even more implementations for serializing and de-serializing data to/from JSON. The tool included in the J2EE is available on GitHub, and that is the one used by the Java HTML JAR Library. (See:javax.json.*
)
Primary Classes Used:JsonArray
andJsonObject
JSON Binding Helper-Class:
JSON-Binding is the art of converting data that has been stored, saved or transmitted usingJava-Script Object Notation
into a Primitive-Type or Object-Type of any Programming Language, for instance Java.JSON
often arrives into Java-Program Memory from an external Internet Connection, and may have traveled hundreds or even thousands of miles from a Host-Server.
Unlike Java-Types which are checked by the Java-Compiler each-and-every time a programmer compiles his project, any guarantee that JSON-Type Data is pristine, uncorrupted, and in any kind of pre-agreed format is never completely assured.
Being able to handle changes that might be made to an API (possibly from great distances away, and without the Software-Manager's consent) is the type of feature that robust JSON-Code simply has to offer.
Binding-Helper Features:- Utilizes the Java-Standard
javax.json.*
Package-Library, & its Glass-Fish Implementation - Handles the Transfer & Conversion of All Json-Type's into Java-Type's with just One Line of Code
- Provides all manner of User-Configurable Exception-Handling &
Error-Decision Management via Class
JFlag
- Provides a Fine-Grained Suite of Exception-Classes, all with Consistent & Meaningful Error-Messages
- Primary Helper-Classes for the (Experimental) Google-Chrome
Headless Browser
Package
Hi-Lited Source-Code:This File's Source Code:
- View Here: Torello/Java/JSON/RJArrIntoBoxedConsumer.java
- Open New Browser-Tab: Torello/Java/JSON/RJArrIntoBoxedConsumer.java
File Size: 16,765 Bytes Line Count: 452 '\n' Characters Found
Json-Array Reader-Helper:
- View Here: BASIC_TYPES.java
- Open New Browser-Tab: BASIC_TYPES.java
File Size: 16,119 Bytes Line Count: 393 '\n' Characters Found
Stateless Class:This class neither contains any program-state, nor can it be instantiated. The@StaticFunctional
Annotation may also be called 'The Spaghetti Report'.Static-Functional
classes are, essentially, C-Styled Files, without any constructors or non-static member fields. It is a concept very similar to the Java-Bean's@Stateless
Annotation.
- 1 Constructor(s), 1 declared private, zero-argument constructor
- 16 Method(s), 16 declared static
- 0 Field(s)
-
-
Method Summary
Read the Contents of a Json-Array into a Java Boxed-Primitives Consumer Modifier and Type Method static void
booleanArr(JsonArray ja, boolean defaultValue, int FLAGS, Function<String,Boolean> optionalUserParser, Consumer<Boolean> c)
static void
byteArr(JsonArray ja, byte defaultValue, int FLAGS, Function<String,Byte> optionalUserParser, Consumer<Byte> c)
static void
doubleArr(JsonArray ja, double defaultValue, int FLAGS, Function<String,Double> optionalUserParser, Consumer<Double> c)
static void
floatArr(JsonArray ja, float defaultValue, int FLAGS, Function<String,Float> optionalUserParser, Consumer<Float> c)
static void
intArr(JsonArray ja, int defaultValue, int FLAGS, Function<String,Integer> optionalUserParser, Consumer<Integer> c)
static void
longArr(JsonArray ja, long defaultValue, int FLAGS, Function<String,Long> optionalUserParser, Consumer<Long> c)
static void
numberArr(JsonArray ja, Number defaultValue, int FLAGS, Function<String,Number> optionalUserParser, Consumer<Number> c)
static void
shortArr(JsonArray ja, short defaultValue, int FLAGS, Function<String,Short> optionalUserParser, Consumer<Short> c)
Read the Contents of a Json-Array into a Boxed-Primitives Consumer, w/ Array-Indices Modifier and Type Method static void
booleanArr2(JsonArray ja, boolean defaultValue, int FLAGS, Function<String,Boolean> optionalUserParser, IntIntTConsumer<Boolean> c)
static void
byteArr2(JsonArray ja, byte defaultValue, int FLAGS, Function<String,Byte> optionalUserParser, IntIntTConsumer<Byte> c)
static void
doubleArr2(JsonArray ja, double defaultValue, int FLAGS, Function<String,Double> optionalUserParser, IntIntTConsumer<Double> c)
static void
floatArr2(JsonArray ja, float defaultValue, int FLAGS, Function<String,Float> optionalUserParser, IntIntTConsumer<Float> c)
static void
intArr2(JsonArray ja, int defaultValue, int FLAGS, Function<String,Integer> optionalUserParser, IntIntTConsumer<Integer> c)
static void
longArr2(JsonArray ja, long defaultValue, int FLAGS, Function<String,Long> optionalUserParser, IntIntTConsumer<Long> c)
static void
numberArr2(JsonArray ja, Number defaultValue, int FLAGS, Function<String,Number> optionalUserParser, IntIntTConsumer<Number> c)
static void
shortArr2(JsonArray ja, short defaultValue, int FLAGS, Function<String,Short> optionalUserParser, IntIntTConsumer<Short> c)
-
-
-
Method Detail
-
intArr
public static void intArr (JsonArray ja, int defaultValue, int FLAGS, java.util.function.Function<java.lang.String,java.lang.Integer> optionalUserParser, java.util.function.Consumer<java.lang.Integer> c)
Java-Consumer which accepts Boxed-IntegersInvokes: ProcessJsonArray.numericToJava(JsonArray, SettingsRec)
Passes: Java Integer
Settings-RecordSee: Class JFlag
for information about parameter'FLAGS'
Example:
Consumer<Integer> myConsumer = (Integer boxedVal) -> System.out.println(boxedVal); RJArrIntoBoxedConsumer.intArr(ja, -1, 0, null, myConsumer);
-
shortArr
public static void shortArr (JsonArray ja, short defaultValue, int FLAGS, java.util.function.Function<java.lang.String,java.lang.Short> optionalUserParser, java.util.function.Consumer<java.lang.Short> c)
Java-Consumer which accepts Boxed Short-IntegersInvokes: ProcessJsonArray.numericToJava(JsonArray, SettingsRec)
Passes: Java Short
Settings-RecordSee: Class JFlag
for information about parameter'FLAGS'
Example:
Consumer<Short> myConsumer = (Short boxedVal) -> System.out.println(boxedVal); RJArrIntoBoxedConsumer.shortArr(ja, -1, 0, null, myConsumer);
-
byteArr
public static void byteArr (JsonArray ja, byte defaultValue, int FLAGS, java.util.function.Function<java.lang.String,java.lang.Byte> optionalUserParser, java.util.function.Consumer<java.lang.Byte> c)
Java-Consumer which accepts Boxed-BytesInvokes: ProcessJsonArray.numericToJava(JsonArray, SettingsRec)
Passes: Java Byte
Settings-RecordSee: Class JFlag
for information about parameter'FLAGS'
Example:
Consumer<Byte> myConsumer = (Byte boxedVal) -> System.out.println(boxedVal); RJArrIntoBoxedConsumer.byteArr(ja, -1, 0, null, myConsumer);
-
longArr
public static void longArr (JsonArray ja, long defaultValue, int FLAGS, java.util.function.Function<java.lang.String,java.lang.Long> optionalUserParser, java.util.function.Consumer<java.lang.Long> c)
Java-Consumer which accepts Boxed Long-IntegersInvokes: ProcessJsonArray.numericToJava(JsonArray, SettingsRec)
Passes: Java Long
Settings-RecordSee: Class JFlag
for information about parameter'FLAGS'
Example:
Consumer<Long> myConsumer = (Long boxedVal) -> System.out.println(boxedVal); RJArrIntoBoxedConsumer.longArr(ja, -1, 0, null, myConsumer);
-
doubleArr
public static void doubleArr (JsonArray ja, double defaultValue, int FLAGS, java.util.function.Function<java.lang.String,java.lang.Double> optionalUserParser, java.util.function.Consumer<java.lang.Double> c)
Java-Consumer which accepts Boxed-DoublesInvokes: ProcessJsonArray.numericToJava(JsonArray, SettingsRec)
Passes: Java Double
Settings-RecordSee: Class JFlag
for information about parameter'FLAGS'
Example:
Consumer<Double> myConsumer = (Double boxedVal) -> System.out.println(boxedVal); RJArrIntoBoxedConsumer.doubleArr(ja, -1, 0, null, myConsumer);
-
floatArr
public static void floatArr (JsonArray ja, float defaultValue, int FLAGS, java.util.function.Function<java.lang.String,java.lang.Float> optionalUserParser, java.util.function.Consumer<java.lang.Float> c)
Java-Consumer which accepts Boxed-FloatsInvokes: ProcessJsonArray.numericToJava(JsonArray, SettingsRec)
Passes: Java Float
Settings-RecordSee: Class JFlag
for information about parameter'FLAGS'
Example:
Consumer<Float> myConsumer = (Float boxedVal) -> System.out.println(boxedVal); RJArrIntoBoxedConsumer.floatArr(ja, -1, 0, null, myConsumer);
-
booleanArr
public static void booleanArr (JsonArray ja, boolean defaultValue, int FLAGS, java.util.function.Function<java.lang.String,java.lang.Boolean> optionalUserParser, java.util.function.Consumer<java.lang.Boolean> c)
Java-Consumer which accepts Boxed-BooleansInvokes: ProcessJsonArray.booleanToJava(JsonArray, SettingsRec)
Passes: Java Boolean
Settings-RecordSee: Class JFlag
for information about parameter'FLAGS'
Example:
Consumer<Boolean> myConsumer = (Boolean boxedVal) -> System.out.println(boxedVal); RJArrIntoBoxedConsumer.booleanArr(ja, -1, 0, null, myConsumer);
-
numberArr
public static void numberArr (JsonArray ja, java.lang.Number defaultValue, int FLAGS, java.util.function.Function<java.lang.String,java.lang.Number> optionalUserParser, java.util.function.Consumer<java.lang.Number> c)
Java-Consumer which accepts Best-Fit Boxed-NumbersInvokes: ProcessJsonArray.numericToJava(JsonArray, SettingsRec)
Passes: Java Number
Settings-RecordSee: Class JFlag
for information about parameter'FLAGS'
Example:
Consumer<Number> myConsumer = (Number boxedVal) -> System.out.println(boxedVal); RJArrIntoBoxedConsumer.intArr(ja, -1, 0, null, myConsumer);
-
intArr2
public static void intArr2 (JsonArray ja, int defaultValue, int FLAGS, java.util.function.Function<java.lang.String,java.lang.Integer> optionalUserParser, IntIntTConsumer<java.lang.Integer> c)
Java-Consumer accepting Boxed-Integers, w/ Array-IndicesInvokes: ProcessJsonArray.numericToJava(JsonArray, SettingsRec)
Passes: Java Integer
Settings-Record, w/ an "Array-Indices Consumer"See: Class JFlag
for information about parameter'FLAGS'
Input-Consumer: IntIntTConsumer<Integer>
Lambda-Signature: void accept (int jsonArrIndex, int javaArrIndex, Integer value)
Example:
IntIntTConsumer<Integer> myConsumer = (int i1, int i2, Integer boxedVal) -> System.out.println("jsonArr[" + i1 + "], javaArr[" + i2 + "]: " + boxedVal); RJArrIntoBoxedConsumer.intArr2(ja, -1, 0, null, myConsumer);
-
shortArr2
public static void shortArr2 (JsonArray ja, short defaultValue, int FLAGS, java.util.function.Function<java.lang.String,java.lang.Short> optionalUserParser, IntIntTConsumer<java.lang.Short> c)
Java-Consumer accepting Boxed Short-Integers, w/ Array-IndicesInvokes: ProcessJsonArray.numericToJava(JsonArray, SettingsRec)
Passes: Java Short
Settings-Record, w/ an "Array-Indices Consumer"See: Class JFlag
for information about parameter'FLAGS'
Input-Consumer: IntIntTConsumer<Short>
Lambda-Signature: void accept (int jsonArrIndex, int javaArrIndex, Short value)
Example:
IntIntTConsumer<Short> myConsumer = (int i1, int i2, Short boxedVal) -> System.out.println("jsonArr[" + i1 + "], javaArr[" + i2 + "]: " + boxedVal); RJArrIntoBoxedConsumer.shortArr2(ja, -1, 0, null, myConsumer);
-
byteArr2
public static void byteArr2 (JsonArray ja, byte defaultValue, int FLAGS, java.util.function.Function<java.lang.String,java.lang.Byte> optionalUserParser, IntIntTConsumer<java.lang.Byte> c)
Java-Consumer accepting Boxed-Bytes, w/ Array-IndicesInvokes: ProcessJsonArray.numericToJava(JsonArray, SettingsRec)
Passes: Java Byte
Settings-Record, w/ an "Array-Indices Consumer"See: Class JFlag
for information about parameter'FLAGS'
Input-Consumer: IntIntTConsumer<Byte>
Lambda-Signature: void accept (int jsonArrIndex, int javaArrIndex, Byte value)
Example:
IntIntTConsumer<Byte> myConsumer = (int i1, int i2, Byte boxedVal) -> System.out.println("jsonArr[" + i1 + "], javaArr[" + i2 + "]: " + boxedVal); RJArrIntoBoxedConsumer.byteArr2(ja, -1, 0, null, myConsumer);
-
longArr2
public static void longArr2 (JsonArray ja, long defaultValue, int FLAGS, java.util.function.Function<java.lang.String,java.lang.Long> optionalUserParser, IntIntTConsumer<java.lang.Long> c)
Java-Consumer accepting Boxed Long-Integers, w/ Array-IndicesInvokes: ProcessJsonArray.numericToJava(JsonArray, SettingsRec)
Passes: Java Long
Settings-Record, w/ an "Array-Indices Consumer"See: Class JFlag
for information about parameter'FLAGS'
Input-Consumer: IntIntTConsumer<Long>
Lambda-Signature: void accept (int jsonArrIndex, int javaArrIndex, Long value)
Example:
IntIntTConsumer<Long> myConsumer = (int i1, int i2, Long boxedVal) -> System.out.println("jsonArr[" + i1 + "], javaArr[" + i2 + "]: " + boxedVal); RJArrIntoBoxedConsumer.longArr2(ja, -1, 0, null, myConsumer);
-
doubleArr2
public static void doubleArr2 (JsonArray ja, double defaultValue, int FLAGS, java.util.function.Function<java.lang.String,java.lang.Double> optionalUserParser, IntIntTConsumer<java.lang.Double> c)
Java-Consumer accepting Boxed-Doubles, w/ Array-IndicesInvokes: ProcessJsonArray.numericToJava(JsonArray, SettingsRec)
Passes: Java Double
Settings-Record, w/ an "Array-Indices Consumer"See: Class JFlag
for information about parameter'FLAGS'
Input-Consumer: IntIntTConsumer<Double>
Lambda-Signature: void accept (int jsonArrIndex, int javaArrIndex, Double value)
Example:
IntIntTConsumer<Double> myConsumer = (int i1, int i2, Double boxedVal) -> System.out.println("jsonArr[" + i1 + "], javaArr[" + i2 + "]: " + boxedVal); RJArrIntoBoxedConsumer.doubleArr2(ja, -1, 0, null, myConsumer);
-
floatArr2
public static void floatArr2 (JsonArray ja, float defaultValue, int FLAGS, java.util.function.Function<java.lang.String,java.lang.Float> optionalUserParser, IntIntTConsumer<java.lang.Float> c)
Java-Consumer accepting Boxed-Floats, w/ Array-IndicesInvokes: ProcessJsonArray.numericToJava(JsonArray, SettingsRec)
Passes: Java Float
Settings-Record, w/ an "Array-Indices Consumer"See: Class JFlag
for information about parameter'FLAGS'
Input-Consumer: IntIntTConsumer<Float>
Lambda-Signature: void accept (int jsonArrIndex, int javaArrIndex, Float value)
Example:
IntIntTConsumer<Float> myConsumer = (int i1, int i2, Float boxedVal) -> System.out.println("jsonArr[" + i1 + "], javaArr[" + i2 + "]: " + boxedVal); RJArrIntoBoxedConsumer.floatArr2(ja, -1, 0, null, myConsumer);
-
booleanArr2
public static void booleanArr2 (JsonArray ja, boolean defaultValue, int FLAGS, java.util.function.Function<java.lang.String,java.lang.Boolean> optionalUserParser, IntIntTConsumer<java.lang.Boolean> c)
Java-Consumer accepting Boxed-Booleans, w/ Array-IndicesInvokes: ProcessJsonArray.booleanToJava(JsonArray, SettingsRec)
Passes: Java Boolean
Settings-Record, w/ an "Array-Indices Consumer"See: Class JFlag
for information about parameter'FLAGS'
Input-Consumer: IntIntTConsumer<Boolean>
Lambda-Signature: void accept (int jsonArrIndex, int javaArrIndex, Boolean value)
Example:
IntIntTConsumer<Boolean> myConsumer = (int i1, int i2, Boolean boxedVal) -> System.out.println("jsonArr[" + i1 + "], javaArr[" + i2 + "]: " + boxedVal); RJArrIntoBoxedConsumer.booleanArr2(ja, -1, 0, null, myConsumer);
-
numberArr2
public static void numberArr2 (JsonArray ja, java.lang.Number defaultValue, int FLAGS, java.util.function.Function<java.lang.String,java.lang.Number> optionalUserParser, IntIntTConsumer<java.lang.Number> c)
Java-Consumer accepting Best-Fit Boxed-Numbers, w/ Array-IndicesInvokes: ProcessJsonArray.numericToJava(JsonArray, SettingsRec)
Passes: Java Number
Settings-Record, w/ an "Array-Indices Consumer"See: Class JFlag
for information about parameter'FLAGS'
Input-Consumer: IntIntTConsumer<Number>
Lambda-Signature: void accept (int jsonArrIndex, int javaArrIndex, Number value)
Example:
IntIntTConsumer<Number> myConsumer = (int i1, int i2, Number boxedVal) -> System.out.println("jsonArr[" + i1 + "], javaArr[" + i2 + "]: " + boxedVal); RJArrIntoBoxedConsumer.numberArr2(ja, -1, 0, null, myConsumer);
-
-