Package Torello.JSON
Class SettingsRec<T,U>
- java.lang.Object
-
- Torello.JSON.SettingsRec<T,U>
-
public class SettingsRec<T,U> extends java.lang.Object
The purpose of this class is to conglomerate all Functional-Interface / Method-Pointers into a single Java-Class. This JSON-Package offers a suite ofJsonArrayProcessing Methods, each of which begins with name / text "RJArr". The list of classes which are made available by this Json Helper-Package are listed, here, below:RJArrIntoStreamRJArrIntoBoxedStreamRJArrIntoPrimStreamRJArrIntoConsumerRJArrIntoBoxedConsumerRJArrIntoPrimConsumerRJArrIntoJavaArrayRJArrIntoPrimArrayRJArrDimN
Note that every single method in each and every one of the above mentioned classes utilize & rely on the classProcessJsonArrayto actually extract the Json-Values that are present inside of theJsonArraythat is passed by the user when invoking one of these methods. This "Main Loop Class" (ProcessJsonArray) actually has four variations for handling the data that is present inside of aJsonArray. Inside this class the four methods can handle:
Data Kind ProcessJsonArrayMethod-LinkNumeric-Data: numericToJavaString-Data: strToJavaBoolean-Data: booleanToJavaObject-Data: booleanToJava
What there is to know about this class'SettingsRec'is that all of the User's Choices & Decisions, based on the input from theJFlagFlag-Mask is converted, piece-meal, into a series of internally represented Lambda's & Function-Pointers - all of which are stored & saved, internallly, inside the fields of thisSettingsRecclass. By first converting all of these decisions regarding the specifics of what is actually inside of theJsonArraythat is to be processed are codified into these Functional-Interfaces. It is through the settings inside of this Record-Class that all processing of Json-Data is actually handled inside of the four methods provided byProcessJsonArray.
Hi-Lited Source-Code:This File's Source Code:
- View Here: Torello/JSON/SettingsRec.java
- Open New Browser-Tab: Torello/JSON/SettingsRec.java
File Size: 12,601 Bytes Line Count: 285 '\n' Characters Found
More Lambdas / Function-Pointers:
- View Here: ACCEPTOR.java
- Open New Browser-Tab: ACCEPTOR.java
File Size: 2,280 Bytes Line Count: 67 '\n' Characters Found
More Lambdas / Function-Pointers:
- View Here: FlagsToHandler.java
- Open New Browser-Tab: FlagsToHandler.java
File Size: 10,659 Bytes Line Count: 234 '\n' Characters Found
Select a Handler by User-Input:
- View Here: ChooseNumberHandler.java
- Open New Browser-Tab: ChooseNumberHandler.java
File Size: 9,286 Bytes Line Count: 229 '\n' Characters Found
Select a Handler by User-Input:
- View Here: ChooseStringHandler.java
- Open New Browser-Tab: ChooseStringHandler.java
File Size: 6,210 Bytes Line Count: 175 '\n' Characters Found
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method voidsetConsumer(Consumer<T> c)voidsetConsumer(IntIntTConsumer<T> c)
-
-
-
Method Detail
-
setConsumer
public void setConsumer(java.util.function.Consumer<T> c)
Assign a value to the internally used consumer, to whichJsonArraydata is emitted- Parameters:
c- This parameter is aConsumer<T>which will be invoked once for each element of aJsonArraybeing processed. The generic type<T>must match the type parameter with which thisSettingsRec<T>instance was constructed. For example:- If this
SettingsRecwas constructed forInteger, then this parameter must be aConsumer<Integer>. - If
String, then this must beConsumer<String>. - If
MyObject, then useConsumer<MyObject>, and so on.
This is enforced by Java’s compile-time generic type checking and will produce an error if you attempt to pass aConsumerof an incorrect type. Still, it is important to ensure that theConsumeryou provide is explicitly aware of the correctTto avoid confusion or unsafe casting logic inside your lambda or method reference.
If you would like to register ajava.util.function.IntConsumerinstead (for performance reasons or simpler syntax), and if yourTisInteger, you may pass your consumer using a double-colon method reference:
Example:
IntConsumer ic = (int i) -> System.out.println(i); settingsRec.setConsumer(ic::accept);
This works becauseic::acceptis compatible withConsumer<Integer>, thanks to Java’s method reference auto-boxing frominttoInteger.- If this
- Throws:
WrongModeException- If thisSettingsRecinstance was not configured to emit / output its data to aConsumer(of any variant), then this exception will throw on invocation of this method. This method is only valid in situations where this record was constructed to ProcessJsonArraydata that is to be output to aConsumer.
This exception will also throw if the type ofConsumerwhich was used to generate thisSettingsRecdoes not match the Type-Parameter of this Method-Signature.
Supported Consumer Types for JSON Array Processing. You must invoke the method that has a Consumer-Parameter which matches the original-contents that were used to build thisSettingsRecinstance. View the two types of Java-Consumer'savailable, here, in the table below:CONSUMER TYPE DESCRIPTION OF PARAMETERS Consumer<T>The method will invoke the consumer with only the array element of type T. This is used when the output handler only needs the actual value from the JSON array, such asInteger,String,MyObject, etc.IntIntTConsumer<T>The method will invoke the consumer with three arguments: int jsonArrayIndex– The original index of the element within the JSON array
int successCount– The number of valid elements processed so far (excluding skips)
T element– The parsed JSON element
This form is used when metadata such as the array index or processing count is needed during iteration, for logging, analysis, or structured output.- Code:
- Exact Method Body:
assertChangeableConsumer(); this.changeableConsumer.setConsumer(c);
-
setConsumer
public void setConsumer(IntIntTConsumer<T> c)
Assign a value to the internally used consumer, to whichJsonArraydata is emitted- Parameters:
c- This parameter is anIntIntTConsumer<T>that will be invoked once for each element of aJsonArray. This consumer receives not only the JSON value, but also two additional metadata fields: the array index, and the count of successfully parsed (non-skipped) elements.
The generic type<T>must match theSettingsRec<T>instance’s original type declaration. For example:- If this
SettingsRecwas constructed withInteger, then this parameter must beIntIntTConsumer<Integer>. - If
String, then useIntIntTConsumer<String>, and so on.
This compatibility is enforced by Java’s compile-time generic type system. Any type mismatch will cause a compile-time error.
IntIntTConsumeris useful when you need not only the parsed JSON value, but also the index and position tracking metadata during iteration.
Note: If you are only interested in the JSON values themselves, and not the extra metadata, you should consider usingsetConsumer(Consumer<T>)instead.- If this
- Throws:
WrongModeException- If thisSettingsRecinstance was not configured to emit / output its data to aConsumer(of any variant), then this exception will throw on invocation of this method. This method is only valid in situations where this record was constructed to ProcessJsonArraydata that is to be output to aConsumer.
This exception will also throw if the type ofConsumerwhich was used to generate thisSettingsRecdoes not match the Type-Parameter of this Method-Signature.
Supported Consumer Types for JSON Array Processing. You must invoke the method that has a Consumer-Parameter which matches the original-contents that were used to build thisSettingsRecinstance. View the two types of Java-Consumer'savailable, here, in the table below:CONSUMER TYPE DESCRIPTION OF PARAMETERS Consumer<T>The method will invoke the consumer with only the array element of type T. This is used when the output handler only needs the actual value from the JSON array, such asInteger,String,MyObject, etc.IntIntTConsumer<T>The method will invoke the consumer with three arguments: int jsonArrayIndex– The original index of the element within the JSON array
int successCount– The number of valid elements processed so far (excluding skips)
T element– The parsed JSON element
This form is used when metadata such as the array index or processing count is needed during iteration, for logging, analysis, or structured output.- Code:
- Exact Method Body:
assertChangeableConsumer(); this.changeableConsumer.setConsumer(c);
-
-