Class ProcessJsonArray


  • public class ProcessJsonArray
    extends java.lang.Object
    This class is the "Central Artery" for all Json-Array Processing done in this package. These four FOR-LOOPS handle 100% of the array processors done by all of the "RJArr" classes offered. These four methods are extremely similar, but have a few minor subtleties that prevent them from being unified into a single handler for all types.


    • Method Detail

      • numericToJava

        🡇     🗕  🗗  🗖
        public static <NUMERIC_DATA_TYPE extends java.lang.Number,​RETURN_TYPE> RETURN_TYPE numericToJava​
                    (JsonArray ja,
                     SettingsRec<NUMERIC_DATA_TYPE,​RETURN_TYPE> rec)
        
        Any and all Json-Array Processors that are intended to read an array of JsonNumber will invoke this method to do their Type-Conversions.
        Type Parameters:
        NUMERIC_DATA_TYPE - Captured & Specified by the contents of the SettingsRec which is passed as an input parameter to this method. This should name the "Expected Contents" of the Input Json-Array. This type must be one Java's 6 "Number Types", such as "Integer", "Float", "Double" etc...

        Note that Boxed-Types & Primitive-Types are used, interchangeably, here.
        RETURN_TYPE - Caputred / Designated by the User-Provided SettingsRec parameter. This Type-Parameter identifies user's "Requested Return Type." When some variant of a Java-Stream is named, that exact Stream-Type will be the value of this Type-Parameter. When the SettingsRec instance provided designates a Java-Consumer, this Type-Parameter will evaluate to the 'java.lang.Void' Singleton-Instance Type.

        Expected Values for this parameter are:
        Category Java-Types
        Streams Stream<Integer>, Stream<Long>, Stream<Double>, etc...
        Consumers Java Void-Type, always
        Primitive-Streams IntStream, LongStream, DoubleStream
        Parameters:
        ja - This should be any instance of JsonArray. It is expected that if this array does not contain explicit JsonNumber values, that is should at least contain values that are to converted or properly parsed into Java-Numbers.
        rec - This may be any instance of SettingsRec. The expect Type-Parameter Value(s) are explained above. These records configure how the for-loop in this method interprets the JsonArray-Values it finds.
        Returns:
        An instance of the type specified by Type-Parameter 'RETURN_TYPE'
        Code:
        Exact Method Body:
         rec.ja = ja;
        
         final int SIZE = ja.size();
        
         JsonValue jv;
        
        
         // If 'RETURN_TYPE' is a Stream, this builds a new Stream, and saves it to the
         // internally-used "EffectivelyFinal" instance.  It's quite simple, actually.
         //
         // If 'RETURN_TYPE' is a Consumer, this is a simple "No-Op"
        
         rec.constructNewBuilder.run();
        
         for (int i=0; i < SIZE; i++)
        
             switch ((jv = ja.get(i)).getValueType())
             {
                 // javax.json.JsonValue.ValueType.NULL
                 case NULL: rec.handlerNull.accept(i); break;
        
                 // javax.json.JsonValue.ValueType.NUMBER
                 case NUMBER: rec.handlerNumber.accept((JsonNumber) jv, i); break;
        
                 // javax.json.JsonValue.ValueType.STRING
                 case STRING: rec.handlerJsonString.accept((JsonString) jv, i); break;
        
                 // OBJECT, ARRAY, TRUE, FALSE
                 default:
        
                     if (rec.handlerWrongType != null)
                         rec.handlerWrongType.accept(i);
                     else
                         throw new JsonTypeArrException(ja, i, NUMBER, jv, rec.CLASS);
             }
        
         // Run Stream.Builder.build()
         return rec.runBuilderDotBuild.get();
        
      • booleanToJava

        🡅  🡇     🗕  🗗  🗖
        public static <RETURN_TYPE> RETURN_TYPE booleanToJava​
                    (JsonArray ja,
                     SettingsRec<java.lang.Boolean,​RETURN_TYPE> rec)
        
        Any and all Json-Array Processors that are intended to read an array of Json-Boolean Values will invoke this method to do their Type-Conversions.
        Type Parameters:
        RETURN_TYPE - Caputred / Designated by the User-Provided SettingsRec parameter. This Type-Parameter identifies user's "Requested Return Type." In this particular Method, this Type-Parameter with either be:

        • Stream<Boolean>, if a Stream is required
        • java.lang.Void, if a Java-Consumer is being deployed

        Note that this method is strictly for processing Boolean JsonArray's, and Java does not provide a Primitive-Stream Variant for the Boolean-Type.
        Parameters:
        ja - This should be any instance of JsonArray. It is expected that if this array does not contain explicit Json-Boolean values, that is should at least contain values that are to converted or properly parsed into Java-Booleans.
        rec - This may be any instance of SettingsRec. The expect Type-Parameter Value(s) are explained above. These records configure how the for-loop in this method interprets the JsonArray-Values it finds.
        Returns:
        An instance of Stream<Boolean>. If the provided instance of SettingsRec has been constructed for a Consumer, then this method will return null.
        Code:
        Exact Method Body:
         final int SIZE = ja.size();
        
         JsonValue jv = null;
        
         rec.ja = ja;
        
         // If 'RETURN_TYPE' is a Consumer, this is a simple "No-Op"
         rec.constructNewBuilder.run();
        
         for (int i=0; i < SIZE; i++)
        
             switch ((jv = ja.get(i)).getValueType())
             {
                 // javax.json.JsonValue.ValueType.NULL, TRUE, FALSE & STRING
                 case NULL:      rec.handlerNull.accept(i); break;
                 case TRUE:      rec.ACCEPTOR.accept(true, i); break;
                 case FALSE:     rec.ACCEPTOR.accept(false, i); break;
                 case STRING:    rec.handlerJsonString.accept((JsonString) jv, i); break;
        
                 // javax.json.JsonValue.ValueType.NUMBER, OBJECT, ARRAY
                 default:
                     if (rec.handlerWrongType != null) rec.handlerWrongType.accept(i);
                     else throw new JsonTypeArrException(ja, i, TRUE, jv, Boolean.class);
             }
        
        
         // Run Stream.Builder.build() - IF NEEDED
         // 'get()' simply returns null if the SettingsRec<T, U> had a "consumer"
         // for it's 'U' Type, rather than a Stream.
        
         return rec.runBuilderDotBuild.get();
        
      • objToJava

        🡅  🡇     🗕  🗗  🗖
        public static <T,​RETURN_TYPE> RETURN_TYPE objToJava​
                    (JsonArray ja,
                     SettingsRec<T,​RETURN_TYPE> rec)
        
        Used to convert JsonObject's into Java-Objects
        Type Parameters:
        T - The Class / Type of the Objects to be extracted from the JsonArray
        RETURN_TYPE - Caputred / Designated by the User-Provided SettingsRec parameter. This Type-Parameter identifies user's "Requested Return Type." In this particular Method, this Type-Parameter with either be:

        • Stream<T>, if a Java-Stream is required
        • java.lang.Void, if a Java-Consumer is being deployed
        Parameters:
        ja - This should be any instance of JsonArray. It is expected that this array contain explicit JsonObject values, that can be converted in.to 'T'
        rec - This may be any instance of SettingsRec. The expect Type-Parameter Value(s) are explained above. These records configure how the for-loop in this method interprets the JsonArray-Values it finds.
        Returns:
        An instance of the type specified by Type-Parameter 'RETURN_TYPE'.
        Code:
        Exact Method Body:
         final int SIZE = ja.size();
        
         JsonValue jv = null;
        
         rec.ja = ja;
        
        
         // For Stream<T>, this builds a new Stream.Builder
         // for Consumer<T>, this is a "No-Op"
        
         rec.constructNewBuilder.run();
        
         for (int i=0; i < SIZE; i++)
        
             switch ((jv = ja.get(i)).getValueType())
             {
                 // javax.json.JsonValue.ValueType.NULL
                 case NULL:
                     rec.handlerNull.accept(i);
                     break;
        
                 // javax.json.JsonValue.ValueType.OBJECT
                 case OBJECT:
                     T obj = rec.builder1Or2
                         ? rec.objBuilder.apply((JsonObject) jv)
                         : rec.objBuilder2.apply(i, (JsonObject) jv);
        
                     rec.ACCEPTOR.accept(obj, i);
                     break;
        
                 // javax.json.JsonValue.ValueType.NUMBER, STRING, TRUE, FALSE, ARRAY
                 default:
                     if (rec.handlerWrongType != null) rec.handlerWrongType.accept(i);
                     else throw new JsonTypeArrException(ja, i, TRUE, jv, rec.CLASS);
             }
        
        
         // For Stream<T>, this runs Stream.Builder.build()
         // For Consumer<T>, this automatically returns null
        
         return rec.runBuilderDotBuild.get();
        
      • strToJava

        🡅  🡇     🗕  🗗  🗖
        public static <RETURN_TYPE> RETURN_TYPE strToJava​
                    (JsonArray ja,
                     SettingsRec<java.lang.String,​RETURN_TYPE> rec)
        
        Any and all Json-Array Processors that are intended to read an array of JsonString Values will invoke this method to do their Type-Conversions.
        Type Parameters:
        RETURN_TYPE - Caputred / Designated by the User-Provided SettingsRec parameter. This Type-Parameter identifies user's "Requested Return Type." In this particular Method, this Type-Parameter with either be:

        • Stream<String>, if a Java-Stream is required
        • java.lang.Void, if a Java-Consumer is being deployed
        Parameters:
        ja - This should be any instance of JsonArray.
        rec - This may be any instance of SettingsRec. The expect Type-Parameter Value(s) are explained above. These records configure how the for-loop in this method interprets the JsonArray-Values it finds.
        Returns:
        An instance of Stream<String>. If the provided instance of SettingsRec has been constructed for a Consumer, then this method will return null.
        Code:
        Exact Method Body:
         final int SIZE = ja.size();
        
         JsonValue jv = null;
        
         rec.ja = ja;
        
         if (rec.constructNewBuilder != null) rec.constructNewBuilder.run();
        
         for (int i=0; i < SIZE; i++)
        
             switch ((jv = ja.get(i)).getValueType())
             {
                 // javax.json.JsonValue.ValueType.NULL
                 case NULL:
                     rec.handlerNull.accept(i);
                     break;
        
                 // javax.json.JsonValue.ValueType.STRING
                 case STRING:
                     rec.ACCEPTOR.accept(((JsonString) jv).getString(), i);
                     break;
        
                 // OBJECT, ARRAY, TRUE, FALSE, NUMBER
                 default:
                     rec.jsonStringWrongTypeHandler.accept(jv, i);
             }
        
        
         // Returns the Built-Stream, for Streams.
         // Returns 'null' for Consumer's
        
         return rec.runBuilderDotBuild.get();
        
      • numericToJavaSync

        🡅  🡇     🗕  🗗  🗖
        public static <NUMERIC_DATA_TYPE extends java.lang.Number,​RETURN_TYPE> RETURN_TYPE numericToJavaSync​
                    (JsonArray ja,
                     SettingsRec<NUMERIC_DATA_TYPE,​RETURN_TYPE> rec)
        
        Synchronized Variant of Method 'numericToJava'
        Synchronized: Nothing More than a "Synchronized Wrapper" which can be used in a Multi-Threaded Programming-Environment.
        Wraps: Method numericToJava(JsonArray, SettingsRec)
        Locking-Object: Input-Parameter 'rec', the SettingsRec instance
        IMPORTANT: Synchronization is only needed when the SettingsRec instance shall be "re-used" in other threads.
        Code:
        Exact Method Body:
         synchronized (rec) { return numericToJava(ja, rec); }
        
      • booleanToJavaSync

        🡅  🡇     🗕  🗗  🗖
        public static <RETURN_TYPE> RETURN_TYPE booleanToJavaSync​
                    (JsonArray ja,
                     SettingsRec<java.lang.Boolean,​RETURN_TYPE> rec)
        
        Synchronized Variant of Method 'booleanToJava'
        Synchronized: Nothing More than a "Synchronized Wrapper" which can be used in a Multi-Threaded Programming-Environment.
        Wraps: Method booleanToJava(JsonArray, SettingsRec)
        Locking-Object: Input-Parameter 'rec', the SettingsRec instance
        IMPORTANT: Synchronizations is only needed when the SettingsRec instance shall be "re-used" in other threads.
        Code:
        Exact Method Body:
         synchronized (rec) { return booleanToJava(ja, rec); }
        
      • objToJavaSync

        🡅  🡇     🗕  🗗  🗖
        public static <T,​RETURN_TYPE> RETURN_TYPE objToJavaSync​
                    (JsonArray ja,
                     SettingsRec<T,​RETURN_TYPE> rec)
        
        Synchronized Variant of Method 'objToJava'
        Synchronized: Nothing More than a "Synchronized Wrapper" which can be used in a Multi-Threaded Programming-Environment.
        Wraps: Method objToJava(JsonArray, SettingsRec)
        Locking-Object: Input-Parameter 'rec', the SettingsRec instance
        IMPORTANT: Synchronizations is only needed when the SettingsRec instance shall be "re-used" in other threads.
        Code:
        Exact Method Body:
         synchronized (rec) { return objToJava(ja, rec); }
        
      • strToJavaSync

        🡅     🗕  🗗  🗖
        public static <RETURN_TYPE> RETURN_TYPE strToJavaSync​
                    (JsonArray ja,
                     SettingsRec<java.lang.String,​RETURN_TYPE> rec)
        
        Synchronized Variant of Method 'strToJava'
        Synchronized: Nothing More than a "Synchronized Wrapper" which can be used in a Multi-Threaded Programming-Environment.
        Wraps: Method strToJava(JsonArray, SettingsRec)
        Locking-Object: Input-Parameter 'rec', the SettingsRec instance
        IMPORTANT: Synchronizations is only needed when the SettingsRec instance shall be "re-used" in other threads.
        Code:
        Exact Method Body:
         synchronized (rec) { return strToJava(ja, rec); }