bsh

Class Primitive

public class Primitive extends Object implements ParserConstants, Serializable

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.
Field Summary
static PrimitiveNULL
static PrimitiveVOID
VOID means "no type".
Constructor Summary
Primitive(Number number)
Primitive(Boolean value)
Primitive(Byte value)
Primitive(Short value)
Primitive(Character value)
Primitive(Integer value)
Primitive(Long value)
Primitive(Float value)
Primitive(Double value)
Primitive(boolean value)
Primitive(byte value)
Primitive(short value)
Primitive(char value)
Primitive(int value)
Primitive(long value)
Primitive(float value)
Primitive(double value)
Method Summary
static ObjectbinaryOperation(Object obj1, Object obj2, int kind)
Perform a binary operation on two Primitives or wrapper types.
booleanbooleanValue()
booleanequals(Object obj)
Primitives compare equal with other Primitives containing an equal wrapped value.
static PrimitivegetDefaultValue(Class type)
Get the appropriate default value per JLS 4.5.4
ClassgetType()
Get the corresponding primitive TYPE class for the Primitive
ObjectgetValue()
Return the primitive value stored in its java.lang wrapper class
inthashCode()
The hash of the Primitive is tied to the hash of the wrapped value but shifted so that they are not the same.
intintValue()
booleanisNumber()
Determine if this primitive is a numeric type. i.e. not boolean, null, or void (but including char)
NumbernumberValue()
StringtoString()
static PrimitiveunaryOperation(Primitive val, int kind)
static Objectunwrap(Object obj)
Unwrap primitive values and map voids to nulls.

Field Detail

NULL

public static final Primitive NULL

VOID

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.

Constructor Detail

Primitive

public Primitive(Number number)

Primitive

public Primitive(Boolean value)

Primitive

public Primitive(Byte value)

Primitive

public Primitive(Short value)

Primitive

public Primitive(Character value)

Primitive

public Primitive(Integer value)

Primitive

public Primitive(Long value)

Primitive

public Primitive(Float value)

Primitive

public Primitive(Double value)

Primitive

public Primitive(boolean value)

Primitive

public Primitive(byte value)

Primitive

public Primitive(short value)

Primitive

public Primitive(char value)

Primitive

public Primitive(int value)

Primitive

public Primitive(long value)

Primitive

public Primitive(float value)

Primitive

public Primitive(double value)

Method Detail

binaryOperation

public static Object binaryOperation(Object obj1, Object obj2, int kind)
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 eithe way.

booleanValue

public boolean booleanValue()

equals

public boolean equals(Object obj)
Primitives compare equal with other Primitives containing an equal wrapped value.

getDefaultValue

public static Primitive getDefaultValue(Class type)
Get the appropriate default value per JLS 4.5.4

getType

public Class getType()
Get the corresponding primitive TYPE class for the Primitive

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

getValue

public Object getValue()
Return the primitive value stored in its java.lang wrapper class

hashCode

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.

intValue

public int intValue()

isNumber

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

numberValue

public Number numberValue()

toString

public String toString()

unaryOperation

public static Primitive unaryOperation(Primitive val, int kind)

unwrap

public static Object unwrap(Object obj)
Unwrap primitive values and map voids to nulls. Normal (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.

B) 2000 pat@pat.net :-)