Package Torello.Browser
Class NumberCrap
- java.lang.Object
-
- Torello.Browser.NumberCrap
-
public class NumberCrap extends java.lang.Object
⚠️ This class is designated as an "internal use only class." While there is nothing detrimental about using this class, it is actually only declared 'public' because it's methods & fields are indeed needed in packages outside ofTorello.Browser. Classes which are declared 'public' are automatically documented by'javadoc'. Therefore this page is included for viewing, even though Java-HTML Library users probably don't actually need to know about it!
💡 Feel free to review it's contents. Perhaps there are explanations which might be of interest.Yes, this is a great name for a class.
This class can capable write all variety of numbers, and arrays of numbers to a providedJsonGeneratorinstance, no more no less.💡 Java's (somewhat) standardized "Glass Fish" implementation is great, but is a little "unfinished".
Hi-Lited Source-Code:- View Here: Torello/Browser/NumberCrap.java
- Open New Browser-Tab: Torello/Browser/NumberCrap.java
File Size: 13,737 Bytes Line Count: 342 '\n' Characters Found
Stateless Class:This class neither contains any program-state, nor can it be instantiated. The@StaticFunctionalAnnotation may also be called 'The Spaghetti Report'.Static-Functionalclasses are, essentially, C-Styled Files, without any constructors or non-static member fields. It is a concept very similar to the Java-Bean's@StatelessAnnotation.
- 1 Constructor(s), 1 declared private, zero-argument constructor
- 3 Method(s), 3 declared static
- 0 Field(s)
-
-
Method Summary
Write a number or array of numbers to a JsonGenerator Modifier and Type Method static voidhandleNumber(JsonGenerator jGen, String paramName, Number paramValue)static voidhandleNumberArr(JsonGenerator jGen, String paramName, Object paramValue)static voidhandleNumberArr2D(JsonGenerator jGen, String paramName, Object paramValue)
-
-
-
Method Detail
-
handleNumber
public static void handleNumber(JsonGenerator jGen, java.lang.String paramName, java.lang.Number paramValue)
Writes a number to an outputJsonGenerator.- Parameters:
jGen- The output Json stream used to properly format Json into a stringparamName- The Json property name for the number being written to the outputparamValue- Any one of the valid, supported types.
👉 Please review the hilited code below, in order to view which types are supported- Throws:
InvalidNumberTypeError- Throws if parameter'paramValue'is passed null, or passed an unsupported type.🧱 Note that this class inheritsErrorbecause this method is intended for internal use by the Java-HTML codebase, not for direct use by end-user code. When used by Java-HTML, this method is designed to handle only specific numeric-type instances, and must throw otherwise.
📌 Generally, this throwable replaces & enforces a standard Javaassertstatement.- Code:
- Exact Method Body:
if (paramValue == null) throw new InvalidNumberTypeError ("Parameter 'paramValue' was passed null. This should be a valid java.lang.Number"); if (paramName != null) switch (paramValue.getClass().getSimpleName()) { case "Integer" : jGen.write(paramName, ((Integer) paramValue).intValue()); break; case "Long" : jGen.write(paramName, ((Long) paramValue).longValue()); break; case "Float" : jGen.write(paramName, ((Float) paramValue).floatValue()); break; case "Double" : jGen.write(paramName, ((Double) paramValue).doubleValue()); break; case "BigInteger" : jGen.write(paramName, ((BigInteger) paramValue)); break; case "BigDecimal" : jGen.write(paramName, ((BigDecimal) paramValue)); break; default : throw new InvalidNumberTypeError( "Parameter 'paramValue' has an invalid Number-Type: " + paramValue.getClass().getCanonicalName() + '\n' ); } else switch (paramValue.getClass().getSimpleName()) { case "Integer" : jGen.write(((Integer) paramValue).intValue()); break; case "Long" : jGen.write(((Long) paramValue).longValue()); break; case "Float" : jGen.write(((Float) paramValue).floatValue()); break; case "Double" : jGen.write(((Double) paramValue).doubleValue()); break; case "BigInteger" : jGen.write(((BigInteger) paramValue)); break; case "BigDecimal" : jGen.write(((BigDecimal) paramValue)); break; default : throw new InvalidNumberTypeError( "Parameter 'paramValue' has an invalid Number-Type: " + paramValue.getClass().getCanonicalName() + '\n' ); }
-
handleNumberArr
public static void handleNumberArr(JsonGenerator jGen, java.lang.String paramName, java.lang.Object paramValue)
Writes a numeric array to an outputJsonGenerator.- Parameters:
jGen- The output Json stream used to properly format Json into a stringparamName- The Json property name for the number being written to the outputparamValue- An array having one of the pre-selected types.
👉 Please review the hilited code below, in order to view which types are supported- Throws:
InvalidNumberTypeError- Throws if parameter'paramValue'is passed null, or passed an unsupported type.🧱 Note that this class inheritsErrorbecause this method is intended for internal use by the Java-HTML codebase, not for direct use by end-user code. When used by Java-HTML, this method is designed to handle only specific numeric-type instances, and must throw otherwise.
📌 Generally, this throwable replaces & enforces a standard Javaassertstatement.- Code:
- Exact Method Body:
if (paramValue == null) throw new InvalidNumberTypeError( "Parameter 'paramValue' was passed null. This should be a valid, one dimensional " + "array of numbers" ); if (paramName == null) jGen.writeStartArray(); else jGen.writeStartArray(paramName); final String typeAsStr = paramValue.getClass().getSimpleName(); switch (typeAsStr) { // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** // primitive arrays // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** case "int[]" : for (final int i : (int[]) paramValue) jGen.write(i); break; case "long[]" : for (final long l : (long[]) paramValue) jGen.write(l); break; case "float[]" : for (final float f : (float[]) paramValue) jGen.write(f); break; case "double[]" : for (final double d : (double[]) paramValue) jGen.write(d); break; // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** // boxed arrays // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** case "Integer[]" : for (final Integer i : (Integer[]) paramValue) if (i == null) jGen.writeNull(); else jGen.write(i.intValue()); break; case "Long[]" : for (final Long l : (Long[]) paramValue) if (l == null) jGen.writeNull(); else jGen.write(l.longValue()); break; case "Float[]" : for (final Float f : (Float[]) paramValue) if (f == null) jGen.writeNull(); else jGen.write(f.floatValue()); break; case "Double[]" : for (final Double d : (Double[]) paramValue) if (d == null) jGen.writeNull(); else jGen.write(d.doubleValue()); break; case "Number[]" : for (final Number n : (Number[]) paramValue) if (n == null) jGen.writeNull(); else handleNumber(jGen, null, n); break; // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** // Other // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** default : if (typeAsStr.endsWith("[]")) throw new InvalidNumberTypeError( "Input array-parameter 'paramValue' has an invalid class / type: " + paramValue.getClass().getCanonicalName() + '\n' + "This should be a one-dimensional array of numbers. Please see this " + "class' source code for the complete list of valid array types." ); else throw new InvalidNumberTypeError( "Input array-parameter 'paramValue' isn't actually a one-dimensional array: " + paramValue.getClass().getCanonicalName() + '\n' ); } jGen.writeEnd();
-
handleNumberArr2D
public static void handleNumberArr2D(JsonGenerator jGen, java.lang.String paramName, java.lang.Object paramValue)
Writes any numeric array having any concrete implementation of the abstract Java Typejava.lang.Numberto an outputJsonGenerator.- Parameters:
jGen- The output Json stream used to properly format Json into a stringparamName- The Json property name for the number being written to the outputparamValue- Any two-dimensional array of numbers having one of the pre-selected types
👉 Please review the hilited code below, in order to view which types are supported- Throws:
InvalidNumberTypeError- Throws if parameter'paramValue'is passed null, or passed an unsupported type.🧱 Note that this class inheritsErrorbecause this method is intended for internal use by the Java-HTML codebase, not for direct use by end-user code. When used by Java-HTML, this method is designed to handle only specific numeric-type instances, and must throw otherwise.
📌 Generally, this throwable replaces & enforces a standard Javaassertstatement.- Code:
- Exact Method Body:
if (paramValue == null) throw new InvalidNumberTypeError( "Parameter 'paramValue' was passed null. This should be a valid, two dimensional " + "array of numbers" ); jGen.writeStartArray(paramName); final String typeAsStr = paramValue.getClass().getSimpleName(); switch (paramValue.getClass().getSimpleName()) { // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** // primitive arrays // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** case "int[][]" : for (final int[] iArr : (int[][]) paramValue) { jGen.writeStartArray(); for (final int i : iArr) jGen.write(i); jGen.writeEnd(); } break; case "long[][]" : for (final long[] lArr : (long[][]) paramValue) { jGen.writeStartArray(); for (final long l : lArr) jGen.write(l); jGen.writeEnd(); } break; case "float[][]" : for (final float[] fArr : (float[][]) paramValue) { jGen.writeStartArray(); for (final float f : fArr) jGen.write(f); jGen.writeEnd(); } break; case "double[][]" : for (final double[] dArr : (double[][]) paramValue) { jGen.writeStartArray(); for (final double d : dArr) jGen.write(d); jGen.writeEnd(); } break; // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** // boxed arrays // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** case "Integer[][]" : for (final Integer[] iArr : (Integer[][]) paramValue) if (iArr == null) jGen.writeNull(); else { jGen.writeStartArray(); for (final Integer i : iArr) if (i == null) jGen.writeNull(); else jGen.write(i.intValue()); jGen.writeEnd(); } break; case "Long[][]" : for (final Long[] lArr : (Long[][]) paramValue) if (lArr == null) jGen.writeNull(); else { jGen.writeStartArray(); for (final Long l : lArr) if (l == null) jGen.writeNull(); else jGen.write(l.longValue()); jGen.writeEnd(); } break; case "Float[][]" : for (final Float[] fArr : (Float[][]) paramValue) if (fArr == null) jGen.writeNull(); else { jGen.writeStartArray(); for (final Float f : fArr) if (f == null) jGen.writeNull(); else jGen.write(f.floatValue()); jGen.writeEnd(); } break; case "Double[][]" : for (final Double[] dArr : (Double[][]) paramValue) if (dArr == null) jGen.writeNull(); else { jGen.writeStartArray(); for (final Double d : dArr) if (d == null) jGen.writeNull(); else jGen.write(d.doubleValue()); jGen.writeEnd(); } break; case "Number[][]" : for (final Number[] nArr : (Number[][]) paramValue) if (nArr == null) jGen.writeNull(); else handleNumberArr(jGen, null, nArr); break; // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** // Other // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** default : if (typeAsStr.endsWith("[]")) throw new InvalidNumberTypeError( "Input array-parameter 'paramValue' has an invalid class / type: " + paramValue.getClass().getCanonicalName() + '\n' + "This should be a two-dimensional array of numbers. Please see this " + "class' source code for the complete list of valid array types." ); else throw new InvalidNumberTypeError( "Input array-parameter 'paramValue' isn't actually a two-dimensional array: " + '[' + typeAsStr + ']' ); } jGen.writeEnd();
-
-