Class MultiTypeWrapper

java.lang.Object
tenapull.data.persistence.MultiTypeWrapper

public final class MultiTypeWrapper
extends java.lang.Object
Used to represent a field which may have multiple JSON primitive data types. When entering into the DB, a varchar(255) field is used where the first character represents the primary data type and the remaining characters represent the value. The "primary type" refers to the type used -- e.g. an AtomicInteger may be grouped with an Integer, etc
  • Nested Class Summary

    Nested Classes 
    Modifier and Type Class Description
    static class  MultiTypeWrapper.Converter
    Hibernate converter, for converting between a string for the DB and a MultiTypeWrapper instance
  • Field Summary

    Fields 
    Modifier and Type Field Description
    static java.util.List<java.lang.Class> BIGDECIMAL_TYPES
    The constant BIGDECIMAL_TYPES.
    static java.util.List<java.lang.Class> BIGINT_TYPES
    The constant BIGINT_TYPES.
    static java.util.List<java.lang.Class> BOOLEAN_TYPES
    The constant BOOLEAN_TYPES.
    static java.util.List<java.lang.Class> BYTE_TYPES
    The constant BYTE_TYPES.
    static java.util.List<java.lang.Class> DOUBLE_TYPES
    The constant DOUBLE_TYPES.
    static java.util.List<java.lang.Class> FLOAT_TYPES
    The constant FLOAT_TYPES.
    static java.util.List<java.lang.Class> INT_TYPES
    The constant INT_TYPES.
    static java.util.List<java.lang.Class> LONG_TYPES
    The constant LONG_TYPES.
    static java.lang.String MISSING_TYPE
    The MISSING_TYPE error string
    static java.lang.String MISSING_VALUE
    The MISSING_VALUE error string
    static java.lang.String NULL_TYPE
    The NULL_TYPE error message
    static java.lang.String NULL_TYPE_STRING
    The NULL_TYPE_STRING error message
    static java.lang.String NULL_VALUE
    The NULL_VALUE error message
    static java.util.List<java.lang.Class> SHORT_TYPES
    The constant SHORT_TYPES.
    static java.util.List<java.lang.Class> STRING_TYPES
    The constant STRING_TYPES.
    static java.util.Map<java.lang.Character,​java.util.List<java.lang.Class>> TYPE_MAP
    The map of types, with their type-character prefix as the key.
    static char UNKNOWN
    The constant UNKNOWN, used as the data type prefix for Objects of a type not represented by the defined "primary types"
  • Method Summary

    Modifier and Type Method Description
    static MultiTypeWrapper buildFrom​(java.lang.String dbString)
    Build a MultiTypeWrapper from the provided dbString, or provide an already-constructed one if it already exists
    static void clearInstances()
    Clear instances by replacing the instances trackers.
    boolean equals​(java.lang.Object o)  
    static long getCounter()
    Gets the number of instances constructed total, including ones which may have been GC'd
    java.lang.Object getObject()
    Gets the value which the MultiTypeWrapper is wrapping
    java.lang.Class getPrimaryType()
    Gets primary type for a MultiTypeWrapper
    static java.lang.Class getPrimaryType​(java.lang.Object object)
    Gets the primary type of a provided object
    static java.util.Map.Entry<java.lang.Character,​java.lang.Class> getPrimaryTypeWithChar​(java.lang.Object object)
    Gets the primary type based on the character prefix from the DB
    java.lang.String getTypeString()
    Gets type string for a MultiTypeWrapper
    int hashCode()  
    static java.lang.String makeDbStringFor​(java.lang.Object object)
    Make the MultiTypeWrapper db string for a provided object
    static void resetCounter()
    Reset the counter.
    static int size()
    Returns the size of the MultiTypeWrapper's instances tracker (aka, the number of viable instances of MultiTypeWrapper currently in working memory)
    java.lang.String toDb()
    Gets the db string for a MultiTypeWrapper
    java.lang.String toString()  
    static MultiTypeWrapper wrap​(java.lang.Object object)
    Creates a multi-type wrapper for the provided object (or an unequivilent in its primary type or returns an already existing one which represents an equivalent value of its primary type.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • UNKNOWN

      public static char UNKNOWN
      The constant UNKNOWN, used as the data type prefix for Objects of a type not represented by the defined "primary types"
    • STRING_TYPES

      public static final java.util.List<java.lang.Class> STRING_TYPES
      The constant STRING_TYPES.
    • INT_TYPES

      public static final java.util.List<java.lang.Class> INT_TYPES
      The constant INT_TYPES.
    • BOOLEAN_TYPES

      public static final java.util.List<java.lang.Class> BOOLEAN_TYPES
      The constant BOOLEAN_TYPES.
    • DOUBLE_TYPES

      public static final java.util.List<java.lang.Class> DOUBLE_TYPES
      The constant DOUBLE_TYPES.
    • LONG_TYPES

      public static final java.util.List<java.lang.Class> LONG_TYPES
      The constant LONG_TYPES.
    • BYTE_TYPES

      public static final java.util.List<java.lang.Class> BYTE_TYPES
      The constant BYTE_TYPES.
    • SHORT_TYPES

      public static final java.util.List<java.lang.Class> SHORT_TYPES
      The constant SHORT_TYPES.
    • FLOAT_TYPES

      public static final java.util.List<java.lang.Class> FLOAT_TYPES
      The constant FLOAT_TYPES.
    • BIGINT_TYPES

      public static final java.util.List<java.lang.Class> BIGINT_TYPES
      The constant BIGINT_TYPES.
    • BIGDECIMAL_TYPES

      public static final java.util.List<java.lang.Class> BIGDECIMAL_TYPES
      The constant BIGDECIMAL_TYPES.
    • TYPE_MAP

      public static final java.util.Map<java.lang.Character,​java.util.List<java.lang.Class>> TYPE_MAP
      The map of types, with their type-character prefix as the key. The first class in each list is the "Primary type", that will be used when instantiating entities from DB varchar values. Character == first character of DB varchar value, to indicate the type of the subsequent string All primary types MUST have a single-argument String constructor
    • NULL_VALUE

      public static final java.lang.String NULL_VALUE
      The NULL_VALUE error message
    • NULL_TYPE

      public static final java.lang.String NULL_TYPE
      The NULL_TYPE error message
    • NULL_TYPE_STRING

      public static final java.lang.String NULL_TYPE_STRING
      The NULL_TYPE_STRING error message
    • MISSING_TYPE

      public static final java.lang.String MISSING_TYPE
      The MISSING_TYPE error string
    • MISSING_VALUE

      public static final java.lang.String MISSING_VALUE
      The MISSING_VALUE error string
  • Method Details

    • wrap

      public static MultiTypeWrapper wrap​(java.lang.Object object)
      Creates a multi-type wrapper for the provided object (or an unequivilent in its primary type or returns an already existing one which represents an equivalent value of its primary type.
      Parameters:
      object - the object needing a MultiTypeWrapper representation
      Returns:
      the multi type wrapper representing the passed value
    • buildFrom

      public static MultiTypeWrapper buildFrom​(java.lang.String dbString)
      Build a MultiTypeWrapper from the provided dbString, or provide an already-constructed one if it already exists
      Parameters:
      dbString - the db string
      Returns:
      the multi type wrapper
    • size

      public static int size()
      Returns the size of the MultiTypeWrapper's instances tracker (aka, the number of viable instances of MultiTypeWrapper currently in working memory)
      Returns:
      the int
    • getCounter

      public static long getCounter()
      Gets the number of instances constructed total, including ones which may have been GC'd
      Returns:
      the counter
    • resetCounter

      public static void resetCounter()
      Reset the counter. Used mostly for benchamrking and testing
    • clearInstances

      public static void clearInstances()
      Clear instances by replacing the instances trackers. Used mostly for benchmarking and testing
    • getPrimaryType

      public static java.lang.Class getPrimaryType​(java.lang.Object object)
      Gets the primary type of a provided object
      Parameters:
      object - the object
      Returns:
      the primary type
    • getPrimaryTypeWithChar

      public static java.util.Map.Entry<java.lang.Character,​java.lang.Class> getPrimaryTypeWithChar​(java.lang.Object object)
      Gets the primary type based on the character prefix from the DB
      Parameters:
      object - the object
      Returns:
      the primary type with char
    • makeDbStringFor

      public static java.lang.String makeDbStringFor​(java.lang.Object object)
      Make the MultiTypeWrapper db string for a provided object
      Parameters:
      object - the object
      Returns:
      the db string
    • toString

      public java.lang.String toString()
      Overrides:
      toString in class java.lang.Object
    • getTypeString

      public java.lang.String getTypeString()
      Gets type string for a MultiTypeWrapper
      Returns:
      the type string
    • getPrimaryType

      public java.lang.Class getPrimaryType()
      Gets primary type for a MultiTypeWrapper
      Returns:
      the primary type
    • toDb

      public java.lang.String toDb()
      Gets the db string for a MultiTypeWrapper
      Returns:
      the string
    • getObject

      public java.lang.Object getObject()
      Gets the value which the MultiTypeWrapper is wrapping
      Returns:
      the object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class java.lang.Object
    • equals

      public boolean equals​(java.lang.Object o)
      Overrides:
      equals in class java.lang.Object