Class RJArrIntoStream


  • public class RJArrIntoStream
    extends java.lang.Object
    This class provides just two methods for extracting String-Data or Object-Data from a JsonArray and placing them into standard Java-Streams.
    Utilities for parsing Json Array's and sending the parsed values into a Java Stream.

    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 and JsonObject


    JSON Binding Helper-Class:
    JSON-Binding is the art of converting data that has been stored, saved or transmitted using Java-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


    Optimize Loops:
    For each method within this class, there are actually two different variants of what is, essentially, the exact same method. Methods in this class whose name ends with the letters 'Rec' are methods that will produce what is known as a 'Settings Record', (see class SettingsRec<T, U>).

    Every one of the Json-Processing classes (in this Json Java-Package) that begin with the letters 'RJArr' are classes which iterate JsonArray's. First, the class does some form of processing and testing to ensure that the contents of the arrays are properly converted into standard Java-Types. After the elements of a JsonArray are successfully processed, they are then sent to either a Java-Array, a Stream or a User-Provided Consumer.

    In order to guarantee that there is a homogenous algorithm for processing these array indices, only four Java 'for-loops' have actually been written. (These loops may be easily inspected by clicking on the 'Hi-Lited Source-Code' button inside of class ProcessJsonArray). In this class, in order to differentiate between a JsonArray which is to be converted into a Java int[]-Array, and one which is to be placed into a Java long[]-Array, a particular "Settings Record" is constructed (which "configures" the loop's body).

    If only one invocation of a method is needed, then using the method that ends with 'Arr' should be perfectly sufficient! If the methods in this class are going to be invoked from inside of a loop (or invoked many times), then it would be much wiser to, first, obtain an instance of the SettingsRec, and then invoke the Array-Processing code yourself.

    In this way, generating twice as many short-lived, ephemeral, object instances (that are immediately discarded, and then collected by the Garbage-Collector) can be avoided. To do this is quite simple. Please review the documentation for the methods in this class whose name ends with 'Rec' - and look at the example code provided for how to use them.

    The Loop Optimized variants of the methods in this class are, very simple, two step procedures (as opposed to just a single method invocation).

    1. First, generate an instance of the SettingsRec class. Make sure to heed to Generic-Type Parameters returned by the Settings-Record Generator-Method you have called.

    2. Second, simply call the specified Json-Array Processing method from class ProcessJsonArray
    See Also:
    Json, JsonArray



    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
    • 4 Method(s), 4 declared static
    • 0 Field(s)


    • Method Summary

       
      Read the Contents of a Json-Array into a Java-Stream
      Modifier and Type Method
      static <T> Stream<T> objArr​(JsonArray ja, T defaultValue, int FLAGS, Class<T> returnClass)
      static Stream<String> strArr​(JsonArray ja, String defaultValue, int FLAGS)
       
      Loop Optimization: Generate a Reusable SettingsRec Instance
      Modifier and Type Method
      static <T> SettingsRec<T,
           ​Stream<T>>
      objRec​(T defaultValue, int FLAGS, Class<T> returnClass)
      static SettingsRec<String,
           ​Stream<String>>
      strRec​(String defaultValue, int FLAGS)
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • objArr

        🡇         External-Java:      🗕  🗗  🗖
        public static <T> java.util.stream.Stream<T> objArr​
                    (JsonArray ja,
                     T defaultValue,
                     int FLAGS,
                     java.lang.Class<T> returnClass)
        
        Generate a Java Stream of Object <T>
        Invokes:   ProcessJsonArray.objToJava(JsonArray, SettingsRec)
        Passes:  Object-Retrieval Settings-Record.
          Object must be of Captured, Parameterized-Type, <T>
        See: Class JFlag for information about the 'FLAGS' parameter.
           
        Producing a YourTypeT[] Array from this Method is as Follows:

        Java Line of Code:
        YourTypeT[] arr = RJArrIntoStream.objArr
            (ja, null, 0, YourTypeT.class).toArray(YourTypeT[]::new);
        
      • strArr

        🡅  🡇         External-Java:      🗕  🗗  🗖
        public static java.util.stream.Stream<java.lang.String> strArr​
                    (JsonArray ja,
                     java.lang.String defaultValue,
                     int FLAGS)
        
        Generate a Java Stream of String's
        Invokes:   ProcessJsonArray.strToJava(JsonArray, SettingsRec)
        Passes:  String-Retrieval Settings-Record.
        See: Class JFlag for information about the 'FLAGS' parameter.
           
        Producing a String[] Array from this Method is as Follows:

        Java Line of Code:
        String[] arr = RJArrIntoStream.strArr(ja, "", 0).toArray(String[]::new);
        
      • objRec

        🡅  🡇         External-Java:      🗕  🗗  🗖
        public static <T> SettingsRec<T,​java.util.stream.Stream<T>> objRec​
                    (T defaultValue,
                     int FLAGS,
                     java.lang.Class<T> returnClass)
        
        Generate a Java Settings-Record for producing Stream<T>
        Generates:  Object-Retrieval Settings-Record.
          Object must be of Captured, Parameterized-Type, <T>
        Used For: The record produced from this method may be used as a parameter to invoke:
            ProcessJsonArray.objToJava(JsonArray, SettingsRec)
        See: Class JFlag for information about the 'FLAGS' parameter.
           
        Producing an Object-Stream (Stream<YourTypeT>> by using this record is a two step process.
        It may be acheived as Follows:

        Example:
        SettingsRec<YouTypeT, Stream<YourTypeT>> rec =
            RJArrIntoStream.objRec(null, 0, YourTypeT.class);
        
        // Reuse the same record in each loop-iteration: only 1 Constructor-Invocation
        for (JsonArray ja : someJsonArraySource) ProcessJsonArray
            .objToJava(ja, rec)             // Returns a Stream<YourTypeT>
            .forEach(System.out::println);  // Prints out each number in the stream
        
      • strRec

        🡅         External-Java:      🗕  🗗  🗖
        public static SettingsRec<java.lang.String,​java.util.stream.Stream<java.lang.String>> strRec​
                    (java.lang.String defaultValue,
                     int FLAGS)
        
        Generate a Java Settings-Record for producing Stream<String>
        Generates:  String-Retrieval Settings-Record.
        Used For: The record produced from this method may be used as a parameter to invoke:
            ProcessJsonArray.strToJava(JsonArray, SettingsRec)
        See: Class JFlag for information about the 'FLAGS' parameter.
           
        Producing a String-Stream by using this record is a two step process.
        It may be acheived as Follows:

        Example:
        SettingsRec<String, Stream<String>> rec =
            RJArrIntoStream.strRec("", 0);
        
        // Reuse the same record in each loop-iteration: only 1 Constructor-Invocation
        for (JsonArray ja : someJsonArraySource) ProcessJsonArray
            .strToJava(ja, rec)             // Returns a Stream<String>
            .forEach(System.out::println);  // Prints out each number in the stream