public class Wrapper extends Number implements DataUnit, DataConverter
Modifier and Type | Field and Description |
---|---|
static int |
BOOLEAN |
static int |
BYTE |
static int |
CHAR |
static int |
DOUBLE |
protected double |
doubleValue |
static int |
FLOAT |
static int |
INT |
static int |
LONG |
protected long |
longValue |
static int |
NONE |
static Wrapper[] |
noParameter
This is a zero length Wrapper array.
|
static int |
OBJECT |
protected Object |
objValue |
static int |
SHORT |
protected int |
type |
static int |
VOID |
Constructor and Description |
---|
Wrapper()
Create a Wrapper with the type set to NONE.
|
Modifier and Type | Method and Description |
---|---|
boolean |
booleanValue() |
void |
cache()
Cache this Wrapper for re-use.
|
static void |
cache(Wrapper used)
Cache a Wrapper for re-use.
|
void |
cached() |
Wrapper |
clear()
Clear any stored value in the Wrapper and set the type to NONE.
|
int |
compareTo(Object other)
Compare this object with another.
|
boolean |
convertData(Wrapper source,
Class sourceType,
Wrapper dest,
Class destType)
Return true if the conversion was successfull.
|
void |
copyFrom(Object other)
Copy all appropriate data from another object.
|
static boolean |
doConvertData(Locale forLocale,
Wrapper source,
Class sourceType,
Wrapper dest,
Class destType)
The Locale implementation of DataConvert.convertData() calls this method.
|
static Object |
doConvertData(Object sourceData,
Class sourceType,
Class destType) |
static boolean |
doConvertData(Wrapper source,
Class sourceType,
Wrapper dest,
Class destType) |
double |
doubleValue()
Return the value of this
Number as a float . |
float |
floatValue()
Return the value of this
Number as a float . |
Wrapper |
fromJavaWrapper(Object javaWrapper) |
Wrapper |
fromJavaWrapper(Object javaWrapper,
Class destinationType)
Set this Wrapper value from the specified standard Java Wrapper.
|
void |
fromString(String what) |
Object |
getArray()
Return the Object stored in the Wrapper only if it is an array.
|
boolean |
getBoolean()
Return the boolean value stored in the Wrapper.
|
byte |
getByte()
Return the byte value stored in the Wrapper.
|
static Wrapper |
getCached()
Get a re-used Wrapper from a global SoftSet of wrappers.
|
char |
getChar()
Return the char value stored in the Wrapper.
|
Object |
getCopy()
Return a copy of this object.
|
Class |
getDataClass()
Return a Class representing the type of the currently stored data.
|
double |
getDouble()
Return the double value stored in the Wrapper.
|
float |
getFloat()
Return the float value stored in the Wrapper.
|
boolean |
getFromField(Field f,
Object source)
Get the value stored in the field f in the object source into this Wrapper.
|
int |
getInt()
Return the int value stored in the Wrapper.
|
long |
getLong()
Return the long value stored in the Wrapper.
|
Object |
getNew()
Return a new Object which is of the same class as the original.
|
Object |
getObject()
Return the Object/Array stored in the Wrapper.
|
Object |
getObject(Class ofType)
Return the object value of the Wrapper only if it is of the specified type.
|
static Object |
getObject(Wrapper source,
Class ofType)
Return the object value of the Wrapper only if it is of the specified type
and if the Wrapper is not null.
|
short |
getShort()
Return the short value stored in the Wrapper.
|
int |
getType()
Return the type of the stored data, or NONE if no data has been stored.
|
static int |
getWrapperType(Object javaWrapper)
Given a Java Wrapper object (like Integer, Short, etc.) return the Wrapper type (e.g
INTEGER, SHORT, etc.) of the wrapper.
|
int |
intValue()
Return the value of this
Number as an int . |
boolean |
isCompatibleWith(int aType) |
boolean |
isInstance(Class c)
Returns true if the type IS an Object AND the Object is of the specified type.
|
static boolean |
isJavaWrapper(Object obj)
Returns if the specified object is a standard Java primitive data wrapper (e.g.
|
boolean |
isNull()
Returns true if the type is not an Object OR if the Object it is set to is null.
|
long |
longValue()
Return the value of this
Number as a long . |
boolean |
putInField(Field f,
Object dest)
Put the value stored in this Wrapper in the specified field in the specified object.
|
Wrapper |
setBoolean(boolean v) |
Wrapper |
setByte(byte v) |
Wrapper |
setChar(char v) |
Wrapper |
setDouble(double d) |
Wrapper |
setFloat(float v) |
Wrapper |
setInt(int v) |
Wrapper |
setLong(long v) |
Wrapper |
setObject(Object v) |
Wrapper |
setShort(short v) |
Wrapper |
setType(int type) |
double |
toDouble()
Convert the value stored in the Wrapper to a double as long as it is of type
FLOAT or DOUBLE.
|
static Wrapper |
toEveWrapper(Object possibleJavaWrapper)
Deprecated.
- use toEveWrapper(Object possibleJavaWrapper,Class javaType)
Convert an Object to an Eve Wrapper.
|
static Wrapper |
toEveWrapper(Object possibleJavaWrapper,
Class javaType)
Convert an Object to an Eve Wrapper.
|
static Wrapper[] |
toEveWrappers(Object[] javaWrappers)
Deprecated.
- use toEveWrappers(Object[] javaWrappers,Class[] types) instead.
|
static Wrapper[] |
toEveWrappers(Object[] javaWrappers,
Class[] types)
Convert an array of standard Java wrapper objects to an array of Eve Wrappers.
|
int |
toInt()
Convert the value stored in the Wrapper to an int as long as it is of type
BYTE, CHAR, SHORT or INT.
|
Object |
toJavaWrapper()
Convert this Wrapper to a standard java Wrapper such as Integer, Double, etc.
|
static Object |
toJavaWrapper(Object possibleEveWrapper)
Return a Java wrapper for an Object which may be an Eve Wrapper.
|
static Object[] |
toJavaWrappers(Wrapper[] wrappers)
Convert an array of Eve Wrappers to an array of standard Java wrapper Objects.
|
long |
toLong()
Convert the value stored in the Wrapper to an int as long as it is of type
BYTE, CHAR, SHORT, INT or LONG.
|
short |
toShort()
Convert the value stored in the Wrapper to a short as long as it is of type SHORT or BYTE.
|
String |
toString()
Return a String representation of this object.
|
CharArray |
toString(CharArray dest) |
CharArray |
toString(CharArray dest,
Locale locale) |
static int |
toWrapperType(Class aType)
Determine the Wrapper type given the type represented by the class.
|
static Object |
widenJavaWrapper(Object value,
Class type)
Widen a Java wrapper object to a specified primitive type.
|
Wrapper |
zero()
Set the values to zero and return this Wrapper without changing the type.
|
Wrapper |
zero(Class type) |
Wrapper |
zero(int type)
Set the type to the specified type and then set the values to zero and return this Wrapper.
|
byteValue, shortValue
protected int type
protected Object objValue
protected long longValue
protected double doubleValue
public static final int NONE
public static final int VOID
public static final int BYTE
public static final int CHAR
public static final int SHORT
public static final int INT
public static final int BOOLEAN
public static final int FLOAT
public static final int LONG
public static final int DOUBLE
public static final int OBJECT
public static final Wrapper[] noParameter
public static Wrapper getCached()
public static void cache(Wrapper used)
used
- the Wrapper that is no longer in use.public void cache()
public Wrapper clear()
public static int toWrapperType(Class aType)
aType
- the type.public Wrapper setType(int type)
public Wrapper setLong(long v)
public Wrapper setDouble(double d)
public Wrapper setByte(byte v)
public Wrapper setChar(char v)
public Wrapper setShort(short v)
public Wrapper setInt(int v)
public Wrapper setBoolean(boolean v)
public Wrapper setFloat(float v)
public int getType()
public boolean isNull()
public boolean isInstance(Class c)
public int getInt() throws IllegalStateException
IllegalStateException
- if the type is incorrect and not NONE.public short getShort() throws IllegalStateException
IllegalStateException
- if the type is incorrect and not NONE.public char getChar() throws IllegalStateException
IllegalStateException
- if the type is incorrect and not NONE.public byte getByte() throws IllegalStateException
IllegalStateException
- if the type is incorrect and not NONE.public boolean getBoolean() throws IllegalStateException
IllegalStateException
- if the type is incorrect and not NONE.public float getFloat()
IllegalStateException
- if the type is incorrect and not NONE.public Object getObject() throws IllegalStateException
IllegalStateException
- if the type is incorrect and not NONE.public Object getObject(Class ofType)
ofType
- the type of the Object expected.public static Object getObject(Wrapper source, Class ofType)
source
- a Wrapper possibly containing an object of the specified type, or
possibly null.ofType
- the type of the Object expected.public Object getArray() throws IllegalStateException
IllegalStateException
- if the type is incorrect and not NONE.public long getLong() throws IllegalStateException
IllegalStateException
- if the type is incorrect and not NONE.public double getDouble() throws IllegalStateException
IllegalStateException
- if the type is incorrect and not NONE.public short toShort() throws IllegalStateException
IllegalStateException
- if the type is not SHORT or BYTE or NONE.public int toInt() throws IllegalStateException
IllegalStateException
- if the type is not BYTE, CHAR, SHORT or INT.public long toLong() throws IllegalStateException
IllegalStateException
- if the type is not BYTE, CHAR, SHORT, INT or LONG.public double toDouble() throws IllegalStateException
IllegalStateException
- if the type is not FLOAT or DOUBLE.public void copyFrom(Object other)
public Wrapper zero(int type)
type
- The type to set to (e.g. 'C', 'I').public Wrapper zero()
public static Object doConvertData(Object sourceData, Class sourceType, Class destType)
public static boolean doConvertData(Locale forLocale, Wrapper source, Class sourceType, Wrapper dest, Class destType)
forLocale
- source
- sourceType
- dest
- destType
- public static boolean doConvertData(Wrapper source, Class sourceType, Wrapper dest, Class destType)
public boolean convertData(Wrapper source, Class sourceType, Wrapper dest, Class destType)
DataConverter
convertData
in interface DataConverter
public String toString()
Object
public void fromString(String what)
public boolean isCompatibleWith(int aType)
public int compareTo(Object other)
Comparable
compareTo
in interface Comparable
public Object toJavaWrapper() throws IllegalStateException
IllegalStateException
- if the Wrapper is not of a valid type.public static Object toJavaWrapper(Object possibleEveWrapper) throws IllegalStateException
possibleEveWrapper
- the object that may be an Eve Wrapper.IllegalStateException
- if it is an Eve wrapper but its state is unknown.public static int getWrapperType(Object javaWrapper)
public Wrapper fromJavaWrapper(Object javaWrapper, Class destinationType)
public boolean putInField(Field f, Object dest)
f
- The field to store the data in.dest
- The destination object.public boolean getFromField(Field f, Object source)
f
- The field to get the data from.source
- The source object.public static boolean isJavaWrapper(Object obj)
public static Object widenJavaWrapper(Object value, Class type) throws IllegalArgumentException
value
- The Java wrapper object to widen.type
- the target primitive Java type.IllegalArgumentException
- if the value is incompatible with the type.public static Object[] toJavaWrappers(Wrapper[] wrappers)
wrappers
- the array of Eve Wrappers.public static Wrapper toEveWrapper(Object possibleJavaWrapper)
possibleJavaWrapper
- if this is already an Eve Wrapper it will be
returned. If it is a Java Wrapper it will be converted to an Eve Wrapper and
returned. If it is neither a new Eve Wrapper will be created and have setObject(null)
called on it and then returned.public static Wrapper toEveWrapper(Object possibleJavaWrapper, Class javaType)
possibleJavaWrapper
- if this is already an Eve Wrapper it will be
returned. If it is a Java Wrapper it will be converted to an Eve Wrapper and
returned. If it is neither a new Eve Wrapper will be created and have setObject(null)
called on it and then returned.javaType
- the Java type represented by the possible wrapper - this can
be null indicating that the Java type is not known.public static Wrapper[] toEveWrappers(Object[] javaWrappers)
javaWrappers
- public static Wrapper[] toEveWrappers(Object[] javaWrappers, Class[] types)
javaWrappers
- the array of Java wrapper objects.types
- an array of types for each Java Wrapper.public Class getDataClass()
public Object getCopy()
Copyable
public int intValue()
Number
Number
as an int
.public long longValue()
Number
Number
as a long
.public float floatValue()
Number
Number
as a float
.floatValue
in class Number
public double doubleValue()
Number
Number
as a float
.doubleValue
in class Number
public boolean booleanValue()
public Object getNew()
DataUnit
public void cached()