Top Description Inners Fields Constructors Methods
bsh

public final Class Primitive

extends Object
implements ParserConstants, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, bsh.ParserConstants
Imports
java.util.Hashtable

Wrapper for primitive types in Bsh. This is package public because it is used in the implementation of some bsh commands. See the note in LHS.java about wrapping objects.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
public static final Primitive
private Object
value

The primitive value stored in its java.lang wrapper class

public static final Primitive
VOID

Hides bsh.ParserConstants.VOID.

VOID means "no type".
pack-priv static Hashtable<K, V>

Constructor Summary

AccessConstructor and Description
public
public
Primitive(boolean value)

public
Primitive(byte value)

public
Primitive(short value)

public
Primitive(char value)

public
Primitive(int value)

public
Primitive(long value)

public
Primitive(float value)

public
Primitive(double value)

Method Summary

Modifier and TypeMethod and Description
public static Object
binaryOperation(Object obj1, Object obj2, int kind)

Perform a binary operation on two Primitives or wrapper types.

pack-priv static Object
binaryOperationImpl(Object lhs, Object rhs, int kind)

pack-priv static Boolean
pack-priv static boolean
public boolean
public static Class<T>
boxType(Class<T> primitiveType)

Get the corresponding java.lang wrapper class for the primitive TYPE class.

pack-priv static Primitive
castPrimitive(Class<T> toType, Class<T> fromType, Primitive fromValue, boolean checkOnly, int operation)

public Primitive
castToType(Class<T>
is the java object or primitive TYPE class
toType
,
int operation)

Cast this bsh.Primitive value to a new bsh.Primitive value This is usually a numeric type cast.

pack-priv static Object
castWrapper(Class<T>
is the java TYPE type
toType
,
Object
is the value in java.lang wrapper. value may not be null.
value
)

Cast a primitive value represented by its java.lang wrapper type to the specified java.lang wrapper type.

pack-priv static Object
pack-priv static double
public boolean
equals(Object
the reference object with which to compare.
obj
)

Overrides java.lang.Object.equals.

Primitives compare equal with other Primitives containing an equal wrapped value.
pack-priv static Object
floatBinaryOperation(Float F1, Float F2, int kind)

pack-priv static float
public static Primitive
getDefaultValue(Class<T> type)

Get the appropriate default value per JLS 4.5.4

public Class<T>

Returns:

the primitive TYPE class type of the value or Void.TYPE for Primitive.VOID or null value for type of Primitive.NULL
getType
()

Get the corresponding Java primitive TYPE class for this Primitive.

public Object
getValue()

Return the primitive value stored in its java.lang wrapper class

public int
hashCode()

Overrides java.lang.Object.hashCode.

The hash of the Primitive is tied to the hash of the wrapped value but shifted so that they are not the same.
pack-priv static Object
pack-priv static int
public int
public boolean
isNumber()

Determine if this primitive is a numeric type.

public static boolean
pack-priv static Object
longBinaryOperation(Long L1, Long L2, int kind)

pack-priv static long
longUnaryOperation(Long L, int kind)

public Number
pack-priv static Object[]
promotePrimitives(Object lhs, Object rhs)

Promote the pair of primitives to the maximum type of the two.

pack-priv static Object
promoteToInteger(Object wrapper)

Promote primitive wrapper type to to Integer wrapper type

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
public static Primitive
unaryOperation(Primitive val, int kind)

public static Class<T>
unboxType(Class<T> wrapperType)

Get the corresponding primitive TYPE class for the java.lang wrapper class type.

public static Object

Returns:

corresponding "normal" Java type, "unwrapping" any bsh.Primitive types to their wrapper types.
unwrap
(Object
object type which may be bsh.Primitive
obj
)

Unwrap primitive values and map voids to nulls.

public static Object[]
unwrap(Object[] args)

public static Object[]
wrap(Object[] args, Class<T>[] paramTypes)

public static Object
wrap(Object value, Class<T> type)

Wrap primitive values (as indicated by type param) and nulls in the Primitive class.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

NULLback to summary
public static final Primitive NULL

Hides bsh.ParserConstants.NULL.

valueback to summary
private Object value

The primitive value stored in its java.lang wrapper class

VOIDback to summary
public static final Primitive VOID

Hides bsh.ParserConstants.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.

wrapperMapback to summary
pack-priv static Hashtable<K, V> wrapperMap

Constructor Detail

Primitiveback to summary
public Primitive(Object value)
Primitiveback to summary
public Primitive(boolean value)
Primitiveback to summary
public Primitive(byte value)
Primitiveback to summary
public Primitive(short value)
Primitiveback to summary
public Primitive(char value)
Primitiveback to summary
public Primitive(int value)
Primitiveback to summary
public Primitive(long value)
Primitiveback to summary
public Primitive(float value)
Primitiveback to summary
public Primitive(double value)

Method Detail

binaryOperationback to summary
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.

binaryOperationImplback to summary
pack-priv static Object binaryOperationImpl(Object lhs, Object rhs, int kind) throws UtilEvalError
booleanBinaryOperationback to summary
pack-priv static Boolean booleanBinaryOperation(Boolean B1, Boolean B2, int kind)
booleanUnaryOperationback to summary
pack-priv static boolean booleanUnaryOperation(Boolean B, int kind) throws UtilEvalError
booleanValueback to summary
public boolean booleanValue() throws UtilEvalError
boxTypeback to summary
public static Class<T> boxType(Class<T> primitiveType)

Get the corresponding java.lang wrapper class for the primitive TYPE class. e.g. Integer.TYPE -> Integer.class

castPrimitiveback to summary
pack-priv static Primitive castPrimitive(Class<T> toType, Class<T> fromType, Primitive fromValue, boolean checkOnly, int operation) throws UtilEvalError
castToTypeback to summary
public Primitive castToType(Class<T> 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:Class<T>

is the java object or primitive TYPE class

castWrapperback to summary
pack-priv static Object castWrapper(Class<T> toType, Object value)

Cast a primitive value represented by its java.lang wrapper type to the specified java.lang wrapper type. e.g. Byte(5) to Integer(5) or Integer(5) to Byte(5)

Parameters
toType:Class<T>

is the java TYPE type

value:Object

is the value in java.lang wrapper. value may not be null.

doubleBinaryOperationback to summary
pack-priv static Object doubleBinaryOperation(Double D1, Double D2, int kind) throws UtilEvalError
doubleUnaryOperationback to summary
pack-priv static double doubleUnaryOperation(Double D, int kind)
equalsback to summary
public boolean equals(Object obj)

Overrides java.lang.Object.equals.

Primitives compare equal with other Primitives containing an equal wrapped value.

Parameters
obj:Object

Doc from java.lang.Object.equals.

the reference object with which to compare.

Returns:boolean

Doc from java.lang.Object.equals.

true if this object is the same as the obj argument; false otherwise.

floatBinaryOperationback to summary
pack-priv static Object floatBinaryOperation(Float F1, Float F2, int kind) throws UtilEvalError
floatUnaryOperationback to summary
pack-priv static float floatUnaryOperation(Float F, int kind)
getDefaultValueback to summary
public static Primitive getDefaultValue(Class<T> type)

Get the appropriate default value per JLS 4.5.4

getTypeback to summary
public Class<T> getType()

Get the corresponding Java primitive TYPE class for this Primitive.

Returns:Class<T>

the primitive TYPE class type of the value or Void.TYPE for Primitive.VOID or null value for type of Primitive.NULL

getValueback to summary
public Object getValue()

Return the primitive value stored in its java.lang wrapper class

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

The hash of the Primitive is tied to the hash of the wrapped value but shifted so that they are not the same.

Returns:int

Doc from java.lang.Object.hashCode.

a hash code value for this object.

intBinaryOperationback to summary
pack-priv static Object intBinaryOperation(Integer I1, Integer I2, int kind)
intUnaryOperationback to summary
pack-priv static int intUnaryOperation(Integer I, int kind)
intValueback to summary
public int intValue() throws UtilEvalError
isNumberback to summary
public boolean isNumber()

Determine if this primitive is a numeric type. i.e. not boolean, null, or void (but including char)

isWrapperTypeback to summary
public static boolean isWrapperType(Class<T> type)
longBinaryOperationback to summary
pack-priv static Object longBinaryOperation(Long L1, Long L2, int kind)
longUnaryOperationback to summary
pack-priv static long longUnaryOperation(Long L, int kind)
numberValueback to summary
public Number numberValue() throws UtilEvalError
promotePrimitivesback to summary
pack-priv static Object[] promotePrimitives(Object lhs, Object rhs)

Promote the pair of primitives to the maximum type of the two. e.g. [int,long]->[long,long]

promoteToIntegerback to summary
pack-priv static Object promoteToInteger(Object wrapper)

Promote primitive wrapper type to to Integer wrapper type

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

unaryOperationback to summary
public static Primitive unaryOperation(Primitive val, int kind) throws UtilEvalError
unboxTypeback to summary
public static Class<T> unboxType(Class<T> wrapperType)

Get the corresponding primitive TYPE class for the java.lang wrapper class type. e.g. Integer.class -> Integer.TYPE

unwrapback to summary
public static Object unwrap(Object obj)

Unwrap primitive values and map voids to nulls. Non Primitive types remain unchanged.

Parameters
obj:Object

object type which may be bsh.Primitive

Returns:Object

corresponding "normal" Java type, "unwrapping" any bsh.Primitive types to their wrapper types.

unwrapback to summary
public static Object[] unwrap(Object[] args)
wrapback to summary
public static Object[] wrap(Object[] args, Class<T>[] paramTypes)
wrapback to summary
public static Object wrap(Object value, Class<T> 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.

bsh back to summary

private Class Primitive.Special

extends Object
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable

Field Summary

Modifier and TypeField and Description
public static final Primitive.Special
public static final Primitive.Special

Constructor Summary

AccessConstructor and Description
private

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

NULL_VALUEback to summary
public static final Primitive.Special NULL_VALUE
VOID_TYPEback to summary
public static final Primitive.Special VOID_TYPE

Constructor Detail

Specialback to summary
private Special()