Class ArrayBuilder

java.lang.Object
org.apache.commons.jexl3.internal.ArrayBuilder
All Implemented Interfaces:
JexlArithmetic.ArrayBuilder

public class ArrayBuilder extends Object implements JexlArithmetic.ArrayBuilder
Helper class to create typed arrays.
  • Field Details

    • PRIMITIVE_SIZE

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

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

      protected 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 Object[] untyped
      The untyped list of items being added.
    • added

      protected int added
      Number of added items.
    • extended

      protected final boolean extended
      Extended?
  • Constructor Details

    • 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 Details

    • unboxingClass

      protected static Class<?> unboxingClass(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
    • add

      public void add(Object value)
      Description copied from interface: JexlArithmetic.ArrayBuilder
      Adds a literal to the array.
      Specified by:
      add in interface JexlArithmetic.ArrayBuilder
      Parameters:
      value - the item to add
    • create

      public Object create(boolean e)
      Description copied from interface: JexlArithmetic.ArrayBuilder
      Creates the actual "array" instance.
      Specified by:
      create in interface JexlArithmetic.ArrayBuilder
      Parameters:
      e - true when the last argument is ', ...'
      Returns:
      the array
    • getCommonSuperClass

      protected Class<?> getCommonSuperClass(Class<?> baseClass, 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> List<T> newList(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