Class ArrayBuilder

    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected int added
      Number of added items.
      private static java.util.Map<java.lang.Class<?>,​java.lang.Class<?>> BOXING_CLASSES
      The boxing types to primitive conversion map.
      protected java.lang.Class<?> commonClass
      The intended class array.
      protected boolean extended
      Extended?
      protected boolean isNumber
      Whether the array stores numbers.
      private static int PRIMITIVE_SIZE
      The number of primitive types.
      protected boolean unboxing
      Whether we can try unboxing.
      protected java.lang.Object[] untyped
      The untyped list of items being added.
    • Constructor Summary

      Constructors 
      Constructor Description
      ArrayBuilder​(int size)
      Creates a new builder.
      ArrayBuilder​(int size, boolean extended)
      Creates a new builder.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void add​(java.lang.Object value)
      Adds a literal to the array.
      java.lang.Object create​(boolean e)
      Creates the actual "array" instance.
      protected java.lang.Class<?> getCommonSuperClass​(java.lang.Class<?> baseClass, java.lang.Class<?> other)
      Computes the best super class/super interface.
      protected <T> java.util.List<T> newList​(java.lang.Class<? extends T> clazz, int size)
      Creates a new list (aka extended array)/
      protected static java.lang.Class<?> unboxingClass​(java.lang.Class<?> parm)
      Gets the primitive type of given class (when it exists).
      • Methods inherited from class java.lang.Object

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

      • PRIMITIVE_SIZE

        private static final int PRIMITIVE_SIZE
        The number of primitive types.
        See Also:
        Constant Field Values
      • BOXING_CLASSES

        private static final java.util.Map<java.lang.Class<?>,​java.lang.Class<?>> BOXING_CLASSES
        The boxing types to primitive conversion map.
      • commonClass

        protected java.lang.Class<?> commonClass
        The intended class array.
      • isNumber

        protected boolean isNumber
        Whether the array stores numbers.
      • unboxing

        protected boolean unboxing
        Whether we can try unboxing.
      • untyped

        protected final java.lang.Object[] untyped
        The untyped list of items being added.
      • added

        protected int added
        Number of added items.
      • extended

        protected final boolean extended
        Extended?
    • Constructor Detail

      • ArrayBuilder

        public ArrayBuilder​(int size)
        Creates a new builder.
        Parameters:
        size - the exact array size
      • ArrayBuilder

        public ArrayBuilder​(int size,
                            boolean extended)
        Creates a new builder.
        Parameters:
        size - the exact array size
        extended - whether the array is extended
    • Method Detail

      • unboxingClass

        protected static java.lang.Class<?> unboxingClass​(java.lang.Class<?> parm)
        Gets the primitive type of given class (when it exists).
        Parameters:
        parm - a class
        Returns:
        the primitive type or null it the argument is not unboxable
      • getCommonSuperClass

        protected java.lang.Class<?> getCommonSuperClass​(java.lang.Class<?> baseClass,
                                                         java.lang.Class<?> other)
        Computes the best super class/super interface.

        Used to try and maintain type safe arrays.

        Parameters:
        baseClass - the baseClass
        other - another class
        Returns:
        a common ancestor, class or interface, worst case being class Object
      • newList

        protected <T> java.util.List<T> newList​(java.lang.Class<? extends T> clazz,
                                                int size)
        Creates a new list (aka extended array)/
        Type Parameters:
        T - the type
        Parameters:
        clazz - the class
        size - the size
        Returns:
        the instance