Class ArrayBuilder
- java.lang.Object
-
- org.apache.commons.jexl3.internal.ArrayBuilder
-
- All Implemented Interfaces:
JexlArithmetic.ArrayBuilder
public class ArrayBuilder extends java.lang.Object implements JexlArithmetic.ArrayBuilder
Helper class to create typed arrays.
-
-
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).
-
-
-
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?
-
-
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
-
add
public void add(java.lang.Object value)
Description copied from interface:JexlArithmetic.ArrayBuilder
Adds a literal to the array.- Specified by:
add
in interfaceJexlArithmetic.ArrayBuilder
- Parameters:
value
- the item to add
-
create
public java.lang.Object create(boolean e)
Description copied from interface:JexlArithmetic.ArrayBuilder
Creates the actual "array" instance.- Specified by:
create
in interfaceJexlArithmetic.ArrayBuilder
- Parameters:
e
- true when the last argument is ', ...'- Returns:
- the array
-
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 baseClassother
- 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 classsize
- the size- Returns:
- the instance
-
-