Package Torello.Java.JSON
Class RJArrIntoPrimArray
- java.lang.Object
-
- Torello.Java.JSON.RJArrIntoPrimArray
-
public class RJArrIntoPrimArray extends java.lang.Object
RJArrIntoPrimArray 🠞RJArr
- ReadJsonArray
This class is used for reading data directly from an already parsedJsonArray
instance.
Into
- Data that is extracted, is sent to a specific User-Provided Destination.
DimN
- 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 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
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, LongStream
andDoubleStream
) 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[]
.
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/RJArrIntoPrimArray.java
- Open New Browser-Tab: Torello/Java/JSON/RJArrIntoPrimArray.java
File Size: 7,629 Bytes Line Count: 214 '\n' Characters Found
Build a Settings-Record, Helper Class:
- View Here: BASIC_TYPES.java
- Open New Browser-Tab: BASIC_TYPES.java
File Size: 27,692 Bytes Line Count: 586 '\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
- 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 JsonArray
into aStream<Short>
and then to ashort[]
Removes: Any JFlag
masks which might insert null-entries in the return-streamSee: Class JFlag
for information about parameter'FLAGS'
See: Flag JFlag.NOT_ALLOWED_RET_NULL_MASKS
for a list of all disallowed & filtered flags.
-
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 JsonArray
into aStream<Byte>
and then to abyte[]
Removes: Any JFlag
masks which might insert null-entries in the return-streamSee: Class JFlag
for information about parameter'FLAGS'
See: Flag JFlag.NOT_ALLOWED_RET_NULL_MASKS
for a list of all disallowed & filtered flags.
-
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 JsonArray
into aStream<Float>
and then to afloat[]
Removes: Any JFlag
masks which might insert null-entries in the return-streamSee: Class JFlag
for information about parameter'FLAGS'
See: Flag JFlag.NOT_ALLOWED_RET_NULL_MASKS
for a list of all disallowed & filtered flags.
-
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 JsonArray
into aStream<Boolean>
and then to aboolean[]
Removes: Any JFlag
masks which might insert null-entries in the return-streamSee: Class JFlag
for information about parameter'FLAGS'
See: Flag JFlag.NOT_ALLOWED_RET_NULL_MASKS
for a list of all disallowed & filtered flags.
-
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
-
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
-
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
-
-