bsh
Class Primitive

java.lang.Object
  |
  +--bsh.Primitive
All Implemented Interfaces:
ParserConstants, java.io.Serializable

public class Primitive
extends java.lang.Object
implements ParserConstants, java.io.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.

See Also:
Serialized Form

Field Summary
static Primitive NULL
           
static Primitive VOID
          VOID means "no type".
 
Fields inherited from interface bsh.ParserConstants
_DEFAULT, ABSTRACT, ANDASSIGN, ANDASSIGNX, ASSIGN, BANG, BIT_AND, BIT_ANDX, BIT_OR, BIT_ORX, BOOL_AND, BOOL_ANDX, BOOL_OR, BOOL_ORX, BOOLEAN, BREAK, BYTE, CASE, CATCH, CHAR, CHARACTER_LITERAL, CLASS, COLON, COMMA, CONST, CONTINUE, DECIMAL_LITERAL, DECR, DEFAULT, DIGIT, DO, DOT, DOUBLE, ELSE, EOF, EQ, EXPONENT, FALSE, FINAL, FINALLY, FLOAT, FLOATING_POINT_LITERAL, FOR, FORMAL_COMMENT, GE, GEX, GOTO, GT, GTX, HASH_BANG_COMMENT, HEX_LITERAL, HOOK, IDENTIFIER, IF, IMPORT, INCR, INSTANCEOF, INT, INTEGER_LITERAL, INTERFACE, LBRACE, LBRACKET, LE, LETTER, LEX, LONG, LPAREN, LSHIFT, LSHIFTASSIGN, LSHIFTASSIGNX, LSHIFTX, LT, LTX, MINUS, MINUSASSIGN, MOD, MODASSIGN, MULTI_LINE_COMMENT, NATIVE, NE, NEW, NONPRINTABLE, OCTAL_LITERAL, ORASSIGN, ORASSIGNX, PLUS, PLUSASSIGN, PRIVATE, PROTECTED, PUBLIC, RBRACE, RBRACKET, RETURN, RPAREN, RSIGNEDSHIFT, RSIGNEDSHIFTASSIGN, RSIGNEDSHIFTASSIGNX, RSIGNEDSHIFTX, RUNSIGNEDSHIFT, RUNSIGNEDSHIFTASSIGN, RUNSIGNEDSHIFTASSIGNX, RUNSIGNEDSHIFTX, SEMICOLON, SHORT, SINGLE_LINE_COMMENT, SLASH, SLASHASSIGN, STAR, STARASSIGN, STATIC, STRING_LITERAL, SWITCH, SYNCHRONIZED, THROW, THROWS, TILDE, tokenImage, TRANSIENT, TRUE, TRY, VOLATILE, WHILE, XOR, XORASSIGN
 
Constructor Summary
Primitive(boolean value)
           
Primitive(java.lang.Boolean value)
           
Primitive(byte value)
           
Primitive(java.lang.Byte value)
           
Primitive(char value)
           
Primitive(java.lang.Character value)
           
Primitive(double value)
           
Primitive(java.lang.Double value)
           
Primitive(float value)
           
Primitive(java.lang.Float value)
           
Primitive(int value)
           
Primitive(java.lang.Integer value)
           
Primitive(long value)
           
Primitive(java.lang.Long value)
           
Primitive(java.lang.Number number)
           
Primitive(short value)
           
Primitive(java.lang.Short value)
           
 
Method Summary
static java.lang.Object binaryOperation(java.lang.Object obj1, java.lang.Object obj2, int kind)
          Perform a binary operation on two Primitives or wrapper types.
 boolean booleanValue()
           
 boolean equals(java.lang.Object obj)
          Primitives compare equal with other Primitives containing an equal wrapped value.
static Primitive getDefaultValue(java.lang.Class type)
          Get the appropriate default value per JLS 4.5.4
 java.lang.Class getType()
          Get the corresponding primitive TYPE class for the Primitive
 java.lang.Object getValue()
          Return the primitive value stored in its java.lang wrapper class
 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.
 int intValue()
           
 boolean isNumber()
          Determine if this primitive is a numeric type.
 java.lang.Number numberValue()
           
 java.lang.String toString()
           
static Primitive unaryOperation(Primitive val, int kind)
           
static java.lang.Object unwrap(java.lang.Object obj)
          Unwrap primitive values and map voids to nulls.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

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(java.lang.Number number)

Primitive

public Primitive(java.lang.Boolean value)

Primitive

public Primitive(java.lang.Byte value)

Primitive

public Primitive(java.lang.Short value)

Primitive

public Primitive(java.lang.Character value)

Primitive

public Primitive(java.lang.Integer value)

Primitive

public Primitive(java.lang.Long value)

Primitive

public Primitive(java.lang.Float value)

Primitive

public Primitive(java.lang.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

getValue

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


toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

getType

public java.lang.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

binaryOperation

public static java.lang.Object binaryOperation(java.lang.Object obj1,
                                               java.lang.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 eithe way.

UtilEvalError

unaryOperation

public static Primitive unaryOperation(Primitive val,
                                       int kind)
                                throws UtilEvalError
UtilEvalError

intValue

public int intValue()
             throws UtilEvalError
UtilEvalError

booleanValue

public boolean booleanValue()
                     throws UtilEvalError
UtilEvalError

isNumber

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


numberValue

public java.lang.Number numberValue()
                             throws UtilEvalError
UtilEvalError

equals

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

Overrides:
equals in class java.lang.Object

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.

Overrides:
hashCode in class java.lang.Object

unwrap

public static java.lang.Object unwrap(java.lang.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.

getDefaultValue

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



© 2000 pat@pat.net :-)