Package Torello.JSON

Class RJInternal


  • public class RJInternal
    extends java.lang.Object
    Class which provides a series of helper functions for all JSON Type-Binding Reader Classes.

    100% of the helper-methods that appear here are protected, and cannot be accessed outside of this package. They are included in the documentation solely for the purposes of (if you happen to be interested) letting you know how the JSON-Tools work. It is not intended that programmers would ever need to invoke, directly, any of the methods in this class!



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


    • Method Summary

       
      FLAG Methods: Flag-Checking Helper-Methods
      Modifier and Type Method
      protected static <T> T IOOBEX​(JsonArray ja, int index, T defaultValue, int FLAGS)
      protected static <T> T JNAEX​(JsonArray ja, int index, T defaultValue, int FLAGS, JsonValue.ValueType expectedType, Class<T> returnClass)
      protected static <T> T JNOEX​(JsonObject jo, String propertyName, T defaultValue, int FLAGS, JsonValue.ValueType expectedType, Class<T> returnClass)
      protected static <T> T JPMEX​(JsonObject jo, String propertyName, T defaultValue, int FLAGS, JsonValue.ValueType expectedType, Class<T> returnClass)
      protected static <T> T JSPAEX​(Exception e, JsonArray ja, int index, T defaultValue, int FLAGS, JsonValue retrievedValue, Class<T> returnClass)
      protected static <T> T JSPOEX​(Exception e, JsonObject jo, String propertyName, T defaultValue, int FLAGS, JsonValue retrievedValue, Class<T> returnClass)
      protected static <T> T JTAEX​(JsonArray ja, int index, T defaultValue, int FLAGS, JsonValue.ValueType expectedType, JsonValue retrievedValue, Class<T> returnClass)
      protected static <T> T JTOEX​(JsonObject jo, String propertyName, T defaultValue, int FLAGS, JsonValue.ValueType expectedType, JsonValue retrievedValue, Class<T> returnClass)
       
      HELPER Methods: Assorted Extras
      Modifier and Type Method
      protected static byte BYTE_FROM_LONG​(long l)
      protected static double DOUBLE_WITH_CHECK​(BigDecimal bd)
      protected static double DOUBLE_WITH_CHECK​(JsonNumber jn)
      protected static float FLOAT_WITH_CHECK​(BigDecimal bd)
      protected static float FLOAT_WITH_CHECK​(JsonNumber jn)
      protected static short SHORT_FROM_LONG​(long l)
      • Methods inherited from class java.lang.Object

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

      • DOUBLE_WITH_CHECK

        🡅  🡇     🗕  🗗  🗖
        protected static double DOUBLE_WITH_CHECK​(java.math.BigDecimal bd)
        Converts a BigDecimal into a Java double
        Parameters:
        bd - Any BigDecimal
        Returns:
        Java double primitive
        Throws:
        java.lang.ArithmeticException - If infinity is returned from the call to code BigDecimal.doubleValue()
        Code:
        Exact Method Body:
         double ret = bd.doubleValue();
        
         if (Double.isInfinite(ret)) throwAE_INFINITY(bd, "double");
        
         if (BigDecimal.valueOf(ret).compareTo(bd) != 0) throwAE_PRECISION(bd, "double");
        
         return ret;
        
      • FLOAT_WITH_CHECK

        🡅  🡇     🗕  🗗  🗖
        protected static float FLOAT_WITH_CHECK​(java.math.BigDecimal bd)
        Converts a BigDecimal into a Java float
        Parameters:
        bd - Any BigDecimal
        Returns:
        Java float primitive
        Throws:
        java.lang.ArithmeticException - If infinity is returned from the call to code BigDecimal.floatValue()
        Code:
        Exact Method Body:
         float ret = bd.floatValue();
        
         if (Float.isInfinite(ret)) throwAE_INFINITY(bd, "float");
        
         if (BigDecimal.valueOf(ret).compareTo(bd) != 0) throwAE_PRECISION(bd, "float");
        
         return ret;
        
      • BYTE_FROM_LONG

        🡅  🡇     🗕  🗗  🗖
        protected static byte BYTE_FROM_LONG​(long l)
        Converts a long into a Java byte
        Parameters:
        l - A long that has been produced by JsonNumber.longValueExact()
        Returns:
        A valid byte primitive
        Throws:
        java.lang.ArithmeticException - If the long doesn't fit into a byte
        Code:
        Exact Method Body:
         if ((l < Byte.MIN_VALUE) || (l > Byte.MAX_VALUE))
             throw new ArithmeticException("byte out of range: " + l);
        
         return (byte) l;
        
      • SHORT_FROM_LONG

        🡅  🡇     🗕  🗗  🗖
        protected static short SHORT_FROM_LONG​(long l)
        Converts a long into a Java short
        Parameters:
        l - A long that has been produced by JsonNumber.longValueExact()
        Returns:
        A valid short primitive
        Throws:
        java.lang.ArithmeticException - If the long doesn't fit into a short
        Code:
        Exact Method Body:
         if ((l < Short.MIN_VALUE) || (l > Short.MAX_VALUE))
             throw new ArithmeticException("short out of range: " + l);
        
         return (short) l;
        
      • IOOBEX

        🡅  🡇     🗕  🗗  🗖
        protected static <T> T IOOBEX​(JsonArray ja,
                                      int index,
                                      T defaultValue,
                                      int FLAGS)
        Flag Checker for IndexOutOfBoundsException.

        Checks whether the relevant flags were set in the users FLAGS parameter, and either returns the appropriate value accordingly, or throws IndexOutOfBoundsException.

        FLAG PRECEDENCE:
        A curosry inspection of the code in this method, below, should explain clearly the rules for the precedence of the flags. For instance, null-return flags always have higher precedence than default-value flags.
        Type Parameters:
        T - If requested, the default-value is returned, and this is its type.
        Returns:
        Can return either the user-provided default-value, or null depending on whether a match was found in the user's request settings ('FLAGS').
        Throws:
        java.lang.IndexOutOfBoundsException - If no flag was set specifying one of the two return-value options.
        See Also:
        JFlag.RETURN_NULL_ON_IOB, JFlag.RETURN_DEFVAL_ON_IOB, JFlag.RETURN_NULL_ON_ANY_ALL, JFlag.RETURN_DEFVAL_ON_ANY_ALL
        Code:
        Exact Method Body:
         if ((FLAGS & RETURN_NULL_ON_IOB) != 0)          return null;
         if ((FLAGS & RETURN_DEFVAL_ON_IOB) != 0)        return defaultValue;
         if ((FLAGS & RETURN_NULL_ON_ANY_ALL) != 0)      return null;
         if ((FLAGS & RETURN_DEFVAL_ON_ANY_ALL) != 0)    return defaultValue;
        
         ja.get(index); // Throws an IndexOutOfBoundsException
        
         // If you have reached this statment, this method was not applied properly
         throw new Torello.Java.UnreachableError();
        
      • JPMEX

        🡅  🡇     🗕  🗗  🗖
        protected static <T> T JPMEX​(JsonObject jo,
                                     java.lang.String propertyName,
                                     T defaultValue,
                                     int FLAGS,
                                     JsonValue.ValueType expectedType,
                                     java.lang.Class<T> returnClass)
        Flag Checker for JsonPropMissingException

        Checks whether the relevant flags were set in the users FLAGS parameter, and either returns the appropriate value accordingly, or throws JsonPropMissingException.

        FLAG PRECEDENCE:
        A curosry inspection of the code in this method, below, should explain clearly the rules for the precedence of the flags. For instance, null-return flags always have higher precedence than default-value flags.
        Type Parameters:
        T - If requested, the default-value is returned, and this is its type.
        Returns:
        Can return either the user-provided default-value, or null depending on whether a match was found in the user's request settings ('FLAGS').
        Throws:
        JsonPropMissingException - If no flag was set specifying one of the two return-value options.
        See Also:
        JFlag.RETURN_NULL_ON_MISSING, JFlag.RETURN_DEFVAL_ON_MISSING, JFlag.RETURN_NULL_ON_ANY_ALL, JFlag.RETURN_DEFVAL_ON_ANY_ALL
        Code:
        Exact Method Body:
         if ((FLAGS & RETURN_NULL_ON_MISSING) != 0)      return null;
         if ((FLAGS & RETURN_DEFVAL_ON_MISSING) != 0)    return defaultValue;
         if ((FLAGS & RETURN_NULL_ON_ANY_ALL) != 0)      return null;
         if ((FLAGS & RETURN_DEFVAL_ON_ANY_ALL) != 0)    return defaultValue;
        
         throw new JsonPropMissingException(jo, propertyName, expectedType, returnClass);
        
      • JNAEX

        🡅  🡇     🗕  🗗  🗖
        protected static <T> T JNAEX​(JsonArray ja,
                                     int index,
                                     T defaultValue,
                                     int FLAGS,
                                     JsonValue.ValueType expectedType,
                                     java.lang.Class<T> returnClass)
        Flag Checker for JsonNullArrException

        Checks whether the relevant flags were set in the users FLAGS parameter, and either returns the appropriate value accordingly, or throws JsonNullArrException.

        FLAG PRECEDENCE:
        A curosry inspection of the code in this method, below, should explain clearly the rules for the precedence of the flags. For instance, null-return flags always have higher precedence than default-value flags.
        Type Parameters:
        T - If requested, the default-value is returned, and this is its type.
        Returns:
        Can return either the user-provided default-value, or null depending on whether a match was found in the user's request settings ('FLAGS').
        Throws:
        JsonNullArrException - If no flag was set specifying one of the two return-value options.
        See Also:
        JFlag.RETURN_NULL_ON_NULL, JFlag.RETURN_DEFVAL_ON_NULL, JFlag.RETURN_NULL_ON_ANY_ALL, JFlag.RETURN_DEFVAL_ON_ANY_ALL
        Code:
        Exact Method Body:
         if ((FLAGS & RETURN_NULL_ON_NULL) != 0)         return null;
         if ((FLAGS & RETURN_DEFVAL_ON_NULL) != 0)       return defaultValue;
         if ((FLAGS & RETURN_NULL_ON_ANY_ALL) != 0)      return null;
         if ((FLAGS & RETURN_DEFVAL_ON_ANY_ALL) != 0)    return defaultValue;
        
         throw new JsonNullArrException(ja, index, expectedType, returnClass);
        
      • JNOEX

        🡅  🡇     🗕  🗗  🗖
        protected static <T> T JNOEX​(JsonObject jo,
                                     java.lang.String propertyName,
                                     T defaultValue,
                                     int FLAGS,
                                     JsonValue.ValueType expectedType,
                                     java.lang.Class<T> returnClass)
        Flag Checker for JsonNullObjException

        Checks whether the relevant flags were set in the users FLAGS parameter, and either returns the appropriate value accordingly, or throws JsonNullObjException.

        FLAG PRECEDENCE:
        A curosry inspection of the code in this method, below, should explain clearly the rules for the precedence of the flags. For instance, null-return flags always have higher precedence than default-value flags.
        Type Parameters:
        T - If requested, the default-value is returned, and this is its type.
        Returns:
        Can return either the user-provided default-value, or null depending on whether a match was found in the user's request settings ('FLAGS').
        Throws:
        JsonNullObjException - If no flag was set specifying one of the two return-value options.
        See Also:
        JFlag.RETURN_NULL_ON_NULL, JFlag.RETURN_DEFVAL_ON_NULL, JFlag.RETURN_NULL_ON_ANY_ALL, JFlag.RETURN_DEFVAL_ON_ANY_ALL
        Code:
        Exact Method Body:
         if ((FLAGS & RETURN_NULL_ON_NULL) != 0)         return null;
         if ((FLAGS & RETURN_DEFVAL_ON_NULL) != 0)       return defaultValue;
         if ((FLAGS & RETURN_NULL_ON_ANY_ALL) != 0)      return null;
         if ((FLAGS & RETURN_DEFVAL_ON_ANY_ALL) != 0)    return defaultValue;
        
         throw new JsonNullObjException(jo, propertyName, expectedType, returnClass);
        
      • JTAEX

        🡅  🡇     🗕  🗗  🗖
        protected static <T> T JTAEX​(JsonArray ja,
                                     int index,
                                     T defaultValue,
                                     int FLAGS,
                                     JsonValue.ValueType expectedType,
                                     JsonValue retrievedValue,
                                     java.lang.Class<T> returnClass)
        Flag Checker for JsonTypeArrException

        Checks whether the relevant flags were set in the users FLAGS parameter, and either returns the appropriate value accordingly, or throws JsonTypeArrException.

        FLAG PRECEDENCE:
        A curosry inspection of the code in this method, below, should explain clearly the rules for the precedence of the flags. For instance, null-return flags always have higher precedence than default-value flags.
        Type Parameters:
        T - If requested, the default-value is returned, and this is its type.
        Returns:
        Can return either the user-provided default-value, or null depending on whether a match was found in the user's request settings ('FLAGS').
        Throws:
        JsonTypeArrException - If no flag was set specifying one of the two return-value options.
        See Also:
        JFlag.RETURN_NULL_ON_WRONG_JSONTYPE, JFlag.RETURN_DEFVAL_ON_WRONG_JSONTYPE, JFlag.RETURN_NULL_ON_ANY_ALL, JFlag.RETURN_DEFVAL_ON_ANY_ALL
        Code:
        Exact Method Body:
         if ((FLAGS & RETURN_NULL_ON_WRONG_JSONTYPE) != 0)   return null;
         if ((FLAGS & RETURN_DEFVAL_ON_WRONG_JSONTYPE) != 0) return defaultValue;
         if ((FLAGS & RETURN_NULL_ON_ANY_ALL) != 0)          return null;
         if ((FLAGS & RETURN_DEFVAL_ON_ANY_ALL) != 0)        return defaultValue;
        
         throw new JsonTypeArrException(ja, index, expectedType, retrievedValue, returnClass);
        
      • JTOEX

        🡅  🡇     🗕  🗗  🗖
        protected static <T> T JTOEX​(JsonObject jo,
                                     java.lang.String propertyName,
                                     T defaultValue,
                                     int FLAGS,
                                     JsonValue.ValueType expectedType,
                                     JsonValue retrievedValue,
                                     java.lang.Class<T> returnClass)
        Flag Checker for JsonTypeObjException

        Checks whether the relevant flags were set in the users FLAGS parameter, and either returns the appropriate value accordingly, or throws JsonNullObjException.

        FLAG PRECEDENCE:
        A curosry inspection of the code in this method, below, should explain clearly the rules for the precedence of the flags. For instance, null-return flags always have higher precedence than default-value flags.
        Type Parameters:
        T - If requested, the default-value is returned, and this is its type.
        Returns:
        Can return either the user-provided default-value, or null depending on whether a match was found in the user's request settings ('FLAGS').
        Throws:
        JsonNullObjException - If no flag was set specifying one of the two return-value options.
        See Also:
        JFlag.RETURN_NULL_ON_WRONG_JSONTYPE, JFlag.RETURN_DEFVAL_ON_WRONG_JSONTYPE, JFlag.RETURN_NULL_ON_ANY_ALL, JFlag.RETURN_DEFVAL_ON_ANY_ALL
        Code:
        Exact Method Body:
         if ((FLAGS & RETURN_NULL_ON_WRONG_JSONTYPE) != 0)   return null;
         if ((FLAGS & RETURN_DEFVAL_ON_WRONG_JSONTYPE) != 0) return defaultValue;
         if ((FLAGS & RETURN_NULL_ON_ANY_ALL) != 0)          return null;
         if ((FLAGS & RETURN_DEFVAL_ON_ANY_ALL) != 0)        return defaultValue;
        
         throw new JsonTypeObjException
             (jo, propertyName, expectedType, retrievedValue, returnClass);
        
      • JSPAEX

        🡅  🡇     🗕  🗗  🗖
        protected static <T> T JSPAEX​(java.lang.Exception e,
                                      JsonArray ja,
                                      int index,
                                      T defaultValue,
                                      int FLAGS,
                                      JsonValue retrievedValue,
                                      java.lang.Class<T> returnClass)
        Flag Checker for JsonStrParseArrException

        Checks whether the relevant flags were set in the users FLAGS parameter, and either returns the appropriate value accordingly, or throws JsonStrParseArrException.

        FLAG PRECEDENCE:
        A curosry inspection of the code in this method, below, should explain clearly the rules for the precedence of the flags. For instance, null-return flags always have higher precedence than default-value flags.
        Type Parameters:
        T - If requested, the default-value is returned, and this is its type.
        Returns:
        Can return either the user-provided default-value, or null depending on whether a match was found in the user's request settings ('FLAGS').
        Throws:
        JsonStrParseArrException - If no flag was set specifying one of the two return-value options.
        See Also:
        JFlag.RETURN_NULL_ON_SPEX, JFlag.RETURN_DEFVAL_ON_SPEX, JFlag.RETURN_NULL_ON_ANY_ALL, JFlag.RETURN_DEFVAL_ON_ANY_ALL
        Code:
        Exact Method Body:
         if ((FLAGS & RETURN_NULL_ON_SPEX) != 0)         return null;
         if ((FLAGS & RETURN_DEFVAL_ON_SPEX) != 0)       return defaultValue;
         if ((FLAGS & RETURN_NULL_ON_ANY_ALL) != 0)      return null;
         if ((FLAGS & RETURN_DEFVAL_ON_ANY_ALL) != 0)    return defaultValue;
        
         throw new JsonStrParseArrException(e, ja, index, retrievedValue, returnClass);
        
      • JSPOEX

        🡅     🗕  🗗  🗖
        protected static <T> T JSPOEX​(java.lang.Exception e,
                                      JsonObject jo,
                                      java.lang.String propertyName,
                                      T defaultValue,
                                      int FLAGS,
                                      JsonValue retrievedValue,
                                      java.lang.Class<T> returnClass)
        Flag Checker for JsonStrParseObjException

        Checks whether the relevant flags were set in the users FLAGS parameter, and either returns the appropriate value accordingly, or throws JsonStrParseObjException.

        FLAG PRECEDENCE:
        A curosry inspection of the code in this method, below, should explain clearly the rules for the precedence of the flags. For instance, null-return flags always have higher precedence than default-value flags.
        Type Parameters:
        T - If requested, the default-value is returned, and this is its type.
        Returns:
        Can return either the user-provided default-value, or null depending on whether a match was found in the user's request settings ('FLAGS').
        Throws:
        JsonStrParseObjException - If no flag was set specifying one of the two return-value options.
        See Also:
        JFlag.RETURN_NULL_ON_SPEX, JFlag.RETURN_DEFVAL_ON_SPEX, JFlag.RETURN_NULL_ON_ANY_ALL, JFlag.RETURN_DEFVAL_ON_ANY_ALL
        Code:
        Exact Method Body:
         if ((FLAGS & RETURN_NULL_ON_SPEX) != 0)         return null;
         if ((FLAGS & RETURN_DEFVAL_ON_SPEX) != 0)       return defaultValue;
         if ((FLAGS & RETURN_NULL_ON_ANY_ALL) != 0)      return null;
         if ((FLAGS & RETURN_DEFVAL_ON_ANY_ALL) != 0)    return defaultValue;
        
         throw new JsonStrParseObjException(e, jo, propertyName, retrievedValue, returnClass);