Package Torello.Java.JSON
Class SettingsRec<T,U>
- java.lang.Object
-
- Torello.Java.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 ofJsonArray
Processing 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:RJArrIntoStream
RJArrIntoBoxedStream
RJArrIntoPrimStream
RJArrIntoConsumer
RJArrIntoBoxedConsumer
RJArrIntoPrimConsumer
RJArrIntoJavaArray
RJArrIntoPrimArray
RJArrDimN
Note that every single method in each and every one of the above mentioned classes utilize & rely on the classProcessJsonArray
to actually extract the Json-Values that are present inside of theJsonArray
that 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 ProcessJsonArray
Method-LinkNumeric-Data: numericToJava
String-Data: strToJava
Boolean-Data: booleanToJava
Object-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 theJFlag
Flag-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 thisSettingsRec
class. By first converting all of these decisions regarding the specifics of what is actually inside of theJsonArray
that 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/Java/JSON/SettingsRec.java
- Open New Browser-Tab: Torello/Java/JSON/SettingsRec.java
File Size: 14,041 Bytes Line Count: 326 '\n' Characters Found
Funtional-Interface Sources:
- View Here: BASIC_TYPES.java
- Open New Browser-Tab: BASIC_TYPES.java
File Size: 27,692 Bytes Line Count: 586 '\n' Characters Found
Funtional-Interface Sources:
- View Here: STREAM_BUILDER.java
- Open New Browser-Tab: STREAM_BUILDER.java
File Size: 10,057 Bytes Line Count: 191 '\n' Characters Found
Funtional-Interface Sources:
- View Here: PREDICATES.java
- Open New Browser-Tab: PREDICATES.java
File Size: 6,403 Bytes Line Count: 139 '\n' Characters Found
Funtional-Interface Sources:
- View Here: CHANGEABLE_CONSUMER.java
- Open New Browser-Tab: CHANGEABLE_CONSUMER.java
File Size: 2,223 Bytes Line Count: 65 '\n' Characters Found
More Lambdas / Function-Pointers:
- View Here: Lambdas.java
- Open New Browser-Tab: Lambdas.java
File Size: 3,014 Bytes Line Count: 71 '\n' Characters Found
More Lambdas / Function-Pointers:
- View Here: TempFlags.java
- Open New Browser-Tab: TempFlags.java
File Size: 10,488 Bytes Line Count: 237 '\n' Characters Found
Select a Handler by User-Input:
- View Here: ChooseNumberHandler.java
- Open New Browser-Tab: ChooseNumberHandler.java
File Size: 9,193 Bytes Line Count: 224 '\n' Characters Found
Select a Handler by User-Input:
- View Here: ChooseStringHandler.java
- Open New Browser-Tab: ChooseStringHandler.java
File Size: 6,031 Bytes Line Count: 169 '\n' Characters Found
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method void
setConsumer(Consumer<T> c)
void
setConsumer(IntIntTConsumer<T> c)
-
-
-
Method Detail
-
setConsumer
public void setConsumer(java.util.function.Consumer<T> c)
Assign a value to the internally used consumer, to whichJsonArray
data is emitted- Parameters:
c
- This parameter is aConsumer<T>
which will be invoked once for each element of aJsonArray
being processed. The generic type<T>
must match the type parameter with which thisSettingsRec<T>
instance was constructed. For example:- If this
SettingsRec
was 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 aConsumer
of an incorrect type. Still, it is important to ensure that theConsumer
you provide is explicitly aware of the correctT
to avoid confusion or unsafe casting logic inside your lambda or method reference.
If you would like to register ajava.util.function.IntConsumer
instead (for performance reasons or simpler syntax), and if yourT
isInteger
, 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::accept
is compatible withConsumer<Integer>
, thanks to Java’s method reference auto-boxing fromint
toInteger
.- If this
- Throws:
WrongModeException
- If thisSettingsRec
instance 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 ProcessJsonArray
data that is to be output to aConsumer
.
This exception will also throw if the type ofConsumer
which was used to generate thisSettingsRec
does 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 thisSettingsRec
instance. View the two types of Java-Consumer's
available, 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 whichJsonArray
data 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
SettingsRec
was 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.
IntIntTConsumer
is 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 thisSettingsRec
instance 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 ProcessJsonArray
data that is to be output to aConsumer
.
This exception will also throw if the type ofConsumer
which was used to generate thisSettingsRec
does 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 thisSettingsRec
instance. View the two types of Java-Consumer's
available, 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);
-
-