Prev Class | Next Class | Frames | No Frames |
Summary: Nested | Field | Method | Constr | Detail: Nested | Field | Method | Constr |
java.lang.Object
bsh.Primitive
public final class Primitive
extends java.lang.Object
implements ParserConstants, java.io.Serializable
Constructor Summary | |
| |
| |
| |
| |
| |
| |
| |
| |
|
Method Summary | |
static Object |
|
boolean | |
static Class |
|
Primitive |
|
boolean |
|
static Primitive |
|
Class |
|
Object |
|
int |
|
int |
|
boolean |
|
static boolean |
|
Number | |
String |
|
static Primitive |
|
static Class |
|
static Object |
|
static Object[] |
|
static Object |
|
static Object[] |
|
public static final Primitive VOID
VOID means "no type". Strictly speaking, this makes no sense here. But for practical reasons we'll consider the lack of a type to be a special value.
public Primitive(Object value)
public Primitive(boolean value)
public Primitive(byte value)
public Primitive(char value)
public Primitive(double value)
public Primitive(float value)
public Primitive(int value)
public Primitive(long value)
public Primitive(short value)
public static Object binaryOperation(Object obj1, Object obj2, int kind) throws UtilEvalError
Perform a binary operation on two Primitives or wrapper types. If both original args were Primitives return a Primitive result else it was mixed (wrapper/primitive) return the wrapper type. The exception is for boolean operations where we will return the primitive type either way.
public static Class boxType(Class primitiveType)
Get the corresponding java.lang wrapper class for the primitive TYPE class. e.g. Integer.TYPE -> Integer.class
public Primitive castToType(Class toType, int operation) throws UtilEvalError
Cast this bsh.Primitive value to a new bsh.Primitive value This is usually a numeric type cast. Other cases include: A boolean can be cast to boolen null can be cast to any object type and remains null Attempting to cast a void causes an exception
- Parameters:
toType
- is the java object or primitive TYPE class
public boolean equals(Object obj)
Primitives compare equal with other Primitives containing an equal wrapped value.
public static Primitive getDefaultValue(Class type)
Get the appropriate default value per JLS 4.5.4
public Class getType()
Get the corresponding Java primitive TYPE class for this Primitive.
- Returns:
- the primitive TYPE class type of the value or Void.TYPE for Primitive.VOID or null value for type of Primitive.NULL
public Object getValue()
Return the primitive value stored in its java.lang wrapper class
public int hashCode()
The hash of the Primitive is tied to the hash of the wrapped value but shifted so that they are not the same.
public boolean isNumber()
Determine if this primitive is a numeric type. i.e. not boolean, null, or void (but including char)
public static boolean isWrapperType(Class type)
public String toString()
public static Class unboxType(Class wrapperType)
Get the corresponding primitive TYPE class for the java.lang wrapper class type. e.g. Integer.class -> Integer.TYPE
public static Object unwrap(Object obj)
Unwrap primitive values and map voids to nulls. Non Primitive types remain unchanged.
- Parameters:
obj
- object type which may be bsh.Primitive
- Returns:
- corresponding "normal" Java type, "unwrapping" any bsh.Primitive types to their wrapper types.
public static Object[] unwrap(Object[] args)
public static Object wrap(Object value, Class type)
Wrap primitive values (as indicated by type param) and nulls in the Primitive class. Values not primitive or null are left unchanged. Primitive values are represented by their wrapped values in param value. The value null is mapped to Primitive.NULL. Any value specified with type Void.TYPE is mapped to Primitive.VOID.
public static Object[] wrap(Object[] args, Class[] paramTypes)