Package Torello.JSON
Class RJArrIntoPrimArray
- java.lang.Object
-
- Torello.JSON.RJArrIntoPrimArray
-
public class RJArrIntoPrimArray extends java.lang.Object
RJArrIntoPrimArray 🠞RJArr- ReadJsonArray
This class is used for reading data directly from an already parsedJsonArrayinstance.
Into- Data that is extracted, is sent to a specific User-Provided Destination.
PrimArray- Data is sent to a Primitive Java-Array.
Utilities for parsing Json Array's and sending the parsed values into a Java-Array
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 Glass Fish Tool is included in the J2EE, and is available on GitHub. That is the one used by the Java HTML JAR Library (See:javax.json.*)
Primary Classes Used:JsonArrayandJsonObject
This comment-note is intentionally repeated, verbatim, at the top of all Json Reader Classes in this package.
JSON to Java Binding:
JSON-Binding is the art of converting data that has been stored, saved or transmitted usingJava-Script Object Notationinto a Java Primitive or Object-Type.JSONcan arrive into Java-Program Memory from almost any source. If you are wondering why such a massive amount of "work" is necessary just to convert a Json Integer into Java Integer, the value added is the extraordinary amount of attention paid to user configuration, error checking, & exception messaging. Methods here don't require more than 1 or 2 lines of code, and guarantee that a thorough type checking is performed.
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 may or may not be assured. The methods here are able to handle changes that might be made to an API (possibly from great distances away, and without the Software-Manager's consent). If an error could occur, configuration flags can be used to determine default error-recovery behaviors. If an exception does throw, the exception messages printed will contain multiple lines of detailed information.- 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. Json Files can occasionally grow extremely large, and error messaging details make debugging easier
- Primary Helper-Classes for the (Experimental) Google-Chrome
Browser AutomationPackage
The goal ofTorello.JSONis to provide small, static helper methods in the same spirit asjava.util.Objectsandjava.util.Arrays: simple calls that keep JSON handling out of your application logic. Instead of repeating loops, type checks, null checks, and exception wiring at every call site, these methods centralize that work behind a consistent set of straight-forward “read value” operations.
Generate Java Primitive, Single-Dimension, Arrays using JsonArray's as Input
The seven methods provided by this class are, also, all declared'static'. They produce simple, Single-Dimension, Java Primitive-Array's. This makes for a total of seven "Generator Methods" provided in this class' simple A.P.I. There is one method for each of the Primitive-Types included with the JDK, except for typechar
It might be of some interest to know that the three types for which Oracle has written "Primitive-Stream" types (IntStream, LongStreamandDoubleStream) are methods which, in this class, are nothing more than single line convenience Wrapper-Invocations around calls to the classRJArrIntoPrimStream, followed by a call to the Primitive-Stream Helper-Method which is included in all implementations of theStream-API- which is'toArray(...)'.
These three are simple, single-line calls:intArr(...),longArr(...)anddoubleArr(...).
The remaining four Primitive-Types require methods which actually build a Java Boxed-Stream, and then convert the Boxed-Stream into a primitive array. The methods which do this include those for generating:short[], byte[], float[]andboolean[].
Hi-Lited Source-Code:This File's Source Code:
- View Here: Torello/JSON/RJArrIntoPrimArray.java
- Open New Browser-Tab: Torello/JSON/RJArrIntoPrimArray.java
File Size: 7,690 Bytes Line Count: 214 '\n' Characters Found
Internal Use Only: Settings-Record Helper:
- View Here: BASIC_TYPES.java
- Open New Browser-Tab: BASIC_TYPES.java
File Size: 28,899 Bytes Line Count: 621 '\n' Characters Found
Stateless Class:This class neither contains any program-state, nor can it be instantiated. The@StaticFunctionalAnnotation may also be called 'The Spaghetti Report'.Static-Functionalclasses are, essentially, C-Styled Files, without any constructors or non-static member fields. It is a concept very similar to the Java-Bean's@StatelessAnnotation.
- 1 Constructor(s), 1 declared private, zero-argument constructor
- 7 Method(s), 7 declared static
- 0 Field(s)
-
-
Method Summary
Read the Contents of a Json-Array into a Java Primitive-Array Modifier and Type Method static boolean[]booleanArr(JsonArray ja, boolean defaultValue, int FLAGS, Predicate<String> optionalUserParser)static byte[]byteArr(JsonArray ja, byte defaultValue, int FLAGS, ToByteFunction<String> optionalUserParser)static double[]doubleArr(JsonArray ja, double defaultValue, int FLAGS, ToDoubleFunction<String> optionalUserParser)static float[]floatArr(JsonArray ja, float defaultValue, int FLAGS, ToFloatFunction<String> optionalUserParser)static int[]intArr(JsonArray ja, int defaultValue, int FLAGS, ToIntFunction<String> optionalUserParser)static long[]longArr(JsonArray ja, long defaultValue, int FLAGS, ToLongFunction<String> optionalUserParser)static short[]shortArr(JsonArray ja, short defaultValue, int FLAGS, ToShortFunction<String> optionalUserParser)
-
-
-
Method Detail
-
shortArr
public static short[] shortArr (JsonArray ja, short defaultValue, int FLAGS, ToShortFunction<java.lang.String> optionalUserParser)
JsonArray of ShortInvokes: Method RJArrIntoBoxedStream.shortArr(JsonArray, short, int, Function)And: Method GENERATE_1DARRAY.boxedStreamToPrimitiveArray(Stream, JsonArray, Class, ObjIntConsumer, Object)Converts: A JsonArrayinto aStream<Short>and then to ashort[]Removes: Any JFlagmasks which might insert null-entries in the return-streamSee: Class JFlagfor information about parameter'FLAGS'See: Flag JFlag.NOT_ALLOWED_RET_NULL_MASKSfor a list of all disallowed & filtered flags.- Code:
- Exact Method Body:
final short[] retArr = new short[ja.size()]; return GENERATE_1DARRAY.boxedStreamToPrimitiveArray( RJArrIntoBoxedStream.shortArr( ja, defaultValue, FLAGS & NOT_ALLOWED_RET_NULL_MASKS, (optionalUserParser == null) ? null : optionalUserParser::applyAsShort ), ja, short.class, (Short s, int i) -> retArr[i] = s.shortValue(), retArr );
-
byteArr
public static byte[] byteArr (JsonArray ja, byte defaultValue, int FLAGS, ToByteFunction<java.lang.String> optionalUserParser)
JsonArray of BytesInvokes: Method RJArrIntoBoxedStream.byteArr(JsonArray, byte, int, Function)And: Method GENERATE_1DARRAY.boxedStreamToPrimitiveArray(Stream, JsonArray, Class, ObjIntConsumer, Object)Converts: A JsonArrayinto aStream<Byte>and then to abyte[]Removes: Any JFlagmasks which might insert null-entries in the return-streamSee: Class JFlagfor information about parameter'FLAGS'See: Flag JFlag.NOT_ALLOWED_RET_NULL_MASKSfor a list of all disallowed & filtered flags.- Code:
- Exact Method Body:
final byte[] retArr = new byte[ja.size()]; return GENERATE_1DARRAY.boxedStreamToPrimitiveArray( RJArrIntoBoxedStream.byteArr( ja, defaultValue, FLAGS & NOT_ALLOWED_RET_NULL_MASKS, (optionalUserParser == null) ? null : optionalUserParser::applyAsByte ), ja, byte.class, (Byte s, int i) -> retArr[i] = s.byteValue(), retArr );
-
floatArr
public static float[] floatArr (JsonArray ja, float defaultValue, int FLAGS, ToFloatFunction<java.lang.String> optionalUserParser)
JsonArray of FloatsInvokes: Method RJArrIntoBoxedStream.floatArr(JsonArray, float, int, Function)And: Method GENERATE_1DARRAY.boxedStreamToPrimitiveArray(Stream, JsonArray, Class, ObjIntConsumer, Object)Converts: A JsonArrayinto aStream<Float>and then to afloat[]Removes: Any JFlagmasks which might insert null-entries in the return-streamSee: Class JFlagfor information about parameter'FLAGS'See: Flag JFlag.NOT_ALLOWED_RET_NULL_MASKSfor a list of all disallowed & filtered flags.- Code:
- Exact Method Body:
final float[] retArr = new float[ja.size()]; return GENERATE_1DARRAY.boxedStreamToPrimitiveArray( RJArrIntoBoxedStream.floatArr( ja, defaultValue, FLAGS & NOT_ALLOWED_RET_NULL_MASKS, (optionalUserParser == null) ? null : optionalUserParser::applyAsFloat ), ja, float.class, (Float s, int i) -> retArr[i] = s.floatValue(), retArr );
-
booleanArr
public static boolean[] booleanArr (JsonArray ja, boolean defaultValue, int FLAGS, java.util.function.Predicate<java.lang.String> optionalUserParser)
JsonArray of BooleansInvokes: Method RJArrIntoBoxedStream.booleanArr(JsonArray, boolean, int, Function)And: Method GENERATE_1DARRAY.boxedStreamToPrimitiveArray(Stream, JsonArray, Class, ObjIntConsumer, Object)Converts: A JsonArrayinto aStream<Boolean>and then to aboolean[]Removes: Any JFlagmasks which might insert null-entries in the return-streamSee: Class JFlagfor information about parameter'FLAGS'See: Flag JFlag.NOT_ALLOWED_RET_NULL_MASKSfor a list of all disallowed & filtered flags.- Code:
- Exact Method Body:
final boolean[] retArr = new boolean[ja.size()]; return GENERATE_1DARRAY.boxedStreamToPrimitiveArray( RJArrIntoBoxedStream.booleanArr( ja, defaultValue, FLAGS & NOT_ALLOWED_RET_NULL_MASKS, (optionalUserParser == null) ? null : optionalUserParser::test ), ja, boolean.class, (Boolean s, int i) -> retArr[i] = s.booleanValue(), retArr );
-
intArr
public static int[] intArr (JsonArray ja, int defaultValue, int FLAGS, java.util.function.ToIntFunction<java.lang.String> optionalUserParser)
JsonArray of IntegersInvokes: RJArrIntoPrimStream.intArr(JsonArray, int, int, ToIntFunction)And-Then: toArray(), as explained in the comments at the top of this class- Code:
- Exact Method Body:
return RJArrIntoPrimStream .intArr(ja, defaultValue, FLAGS, optionalUserParser) .toArray();
-
longArr
public static long[] longArr (JsonArray ja, long defaultValue, int FLAGS, java.util.function.ToLongFunction<java.lang.String> optionalUserParser)
JsonArray of LongsInvokes: RJArrIntoPrimStream.longArr(JsonArray, long, int, ToLongFunction)And-Then: toArray(), as explained in the comments at the top of this class- Code:
- Exact Method Body:
return RJArrIntoPrimStream .longArr(ja, defaultValue, FLAGS, optionalUserParser) .toArray();
-
doubleArr
public static double[] doubleArr (JsonArray ja, double defaultValue, int FLAGS, java.util.function.ToDoubleFunction<java.lang.String> optionalUserParser)
JsonArray of DoublesInvokes: RJArrIntoPrimStream.doubleArr(JsonArray, double, int, ToDoubleFunction)And-Then: toArray(), as explained in the comments at the top of this class- Code:
- Exact Method Body:
return RJArrIntoPrimStream .doubleArr(ja, defaultValue, FLAGS, optionalUserParser) .toArray();
-
-