ua.gradsoft.termware
Class TypeConversion

java.lang.Object
  extended by ua.gradsoft.termware.TypeConversion

public class TypeConversion
extends Object

Conversion rules between terms and java objects.


Nested Class Summary
static class TypeConversion.ObjectToNumber
           
static class TypeConversion.ObjectToString
           
 class TypeConversion.ObjectToTerm
          callback class for object to term conversion.
static class TypeConversion.TermToBoolean
           
static class TypeConversion.TermToChar
          user can set subclass of this class to receive default mapping from terms to chars.
static class TypeConversion.TermToNumber
           
static class TypeConversion.TermToObject
           
static class TypeConversion.TermToObjectArray
          Callback class for specifying conversions of terms to array.
static class TypeConversion.TermToString
           
 
Field Summary
static int MAYBE_POSSIBLE
           
static int NOT_POSSIBLE
           
static int POSSIBLE
           
 
Method Summary
 void addObjectToNumberConverter(Class classToConvert, TypeConversion.ObjectToNumber converter)
           
 void addObjectToStringConverter(Class classToConvert, TypeConversion.ObjectToString converter)
           
 void addObjectToTermConverter(Class classToConvert, TypeConversion.ObjectToTerm converter)
           
 void addTermToBooleanConverter(Comparable nameIndex, TypeConversion.TermToBoolean converter)
           
 void addTermToCharConverter(Comparable nameIndex, TypeConversion.TermToChar converter)
           
 void addTermToNumberConverter(Comparable nameIndex, TypeConversion.TermToNumber converter)
           
 void addTermToStringConverter(Comparable nameIndex, TypeConversion.TermToString converter)
           
 Term adopt(boolean v)
           
 Term adopt(byte v)
           
 Term adopt(double v)
           
 Term adopt(float f)
           
 Term adopt(int i)
           
 Term adopt(long i)
           
 Term adopt(Object v)
          adopt object to term use default rules and custom converters.
 Term adopt(short i)
           
 Term adopt(Term t)
           
 Term adoptArray(Object[] v)
           
 Term adoptArray(Object[] v, int i, Term tail)
           
 BigDecimal getAsBigDecimal(Term t)
           
 BigInteger getAsBigInteger(Term t)
           
 boolean getAsBoolean(Term t)
          get term value as boolean.
 byte getAsByte(Term t)
           
 char getAsChar(Term t)
           
 double getAsDouble(Term t)
          convert t to double value.
 float getAsFloat(Term t)
           
 int getAsInt(Term t)
           
 long getAsLong(Term t)
          get long term value from t , convert to required type if necessory
 Number getAsNumber(Term t)
           
 Object getAsObject(Term t)
           
 Object[] getAsObjectArray(Term t)
           
 Object[] getAsObjectArrayWithClass(Class aClass, Term t)
           
 Object getAsObjectWithClass(Class<?> aClass, Term t)
           
 short getAsShort(Term t)
          get short term value, convert to required type if necessory
 String getAsString(Term t)
           
 Object getAsVoid(Term t)
           
 Number getBooleanAsNumber(boolean b)
           
 Number getCharAsNumber(char ch)
           
 BigDecimal getNumberAsBigDecimal(Number nm)
           
 BigInteger getNumberAsBigInteger(Number nm)
           
 Number getStringAsNumber(String s)
           
 void removeObjectToNumberConverter(Class classToConvert)
           
 void removeObjectToStringConverter(Class classToConvert)
           
 void removeObjectToTermConverter(Class classToConvert)
           
 void removeTermToBooleanConverter(Comparable nameIndex)
           
 void removeTermToCharConverter(Comparable nameIndex)
           
 void removeTermToNumberConverter(Comparable nameIndex)
           
 void removeTermToStringConverter(Comparable nameIndex)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

POSSIBLE

public static final int POSSIBLE
See Also:
Constant Field Values

NOT_POSSIBLE

public static final int NOT_POSSIBLE
See Also:
Constant Field Values

MAYBE_POSSIBLE

public static final int MAYBE_POSSIBLE
See Also:
Constant Field Values
Method Detail

getAsBoolean

public boolean getAsBoolean(Term t)
                     throws ConversionException
get term value as boolean. (convert, if necessory)

Throws:
ConversionException

getAsChar

public char getAsChar(Term t)
               throws ConversionException
Throws:
ConversionException

getAsString

public String getAsString(Term t)
                   throws ConversionException
Throws:
ConversionException

getAsNumber

public Number getAsNumber(Term t)
                   throws ConversionException
Throws:
ConversionException

getAsBigDecimal

public BigDecimal getAsBigDecimal(Term t)
                           throws ConversionException
Throws:
ConversionException

getNumberAsBigDecimal

public BigDecimal getNumberAsBigDecimal(Number nm)

getAsBigInteger

public BigInteger getAsBigInteger(Term t)
                           throws ConversionException
Throws:
ConversionException

getNumberAsBigInteger

public BigInteger getNumberAsBigInteger(Number nm)
                                 throws ConversionException
Throws:
ConversionException

getAsByte

public byte getAsByte(Term t)
               throws ConversionException
Throws:
ConversionException

getAsDouble

public double getAsDouble(Term t)
                   throws ConversionException
convert t to double value.

Parameters:
t - - term to convert.
Returns:
appropriative double value, if conversion is possible.
Throws:
ConversionException

getAsFloat

public float getAsFloat(Term t)
                 throws ConversionException
Throws:
ConversionException

getAsInt

public int getAsInt(Term t)
             throws ConversionException
Throws:
ConversionException

getAsLong

public long getAsLong(Term t)
               throws ConversionException
get long term value from t , convert to required type if necessory

Parameters:
t - - term to extract value from.
Returns:
long value.
Throws:
ConversionException

getAsShort

public short getAsShort(Term t)
                 throws ConversionException
get short term value, convert to required type if necessory

Throws:
ConversionException

getAsObject

public Object getAsObject(Term t)
                   throws ConversionException
Throws:
ConversionException

getAsObjectArray

public Object[] getAsObjectArray(Term t)
                          throws ConversionException
Throws:
ConversionException

getAsVoid

public Object getAsVoid(Term t)
                 throws ConversionException
Throws:
ConversionException

getAsObjectWithClass

public Object getAsObjectWithClass(Class<?> aClass,
                                   Term t)
                            throws ConversionException
Throws:
ConversionException

getAsObjectArrayWithClass

public Object[] getAsObjectArrayWithClass(Class aClass,
                                          Term t)
                                   throws ConversionException
Throws:
ConversionException

adopt

public Term adopt(Object v)
           throws ConversionException
adopt object to term use default rules and custom converters.

Throws:
ConversionException

adoptArray

public Term adoptArray(Object[] v)
                throws ConversionException
Throws:
ConversionException

adoptArray

public Term adoptArray(Object[] v,
                       int i,
                       Term tail)
                throws ConversionException
Throws:
ConversionException

adopt

public Term adopt(Term t)

adopt

public Term adopt(byte v)

adopt

public Term adopt(double v)

adopt

public Term adopt(float f)

adopt

public Term adopt(int i)

adopt

public Term adopt(long i)

adopt

public Term adopt(short i)

adopt

public Term adopt(boolean v)

getStringAsNumber

public Number getStringAsNumber(String s)

getCharAsNumber

public Number getCharAsNumber(char ch)
                       throws ConversionException
Throws:
ConversionException

getBooleanAsNumber

public Number getBooleanAsNumber(boolean b)

addTermToBooleanConverter

public void addTermToBooleanConverter(Comparable nameIndex,
                                      TypeConversion.TermToBoolean converter)

removeTermToBooleanConverter

public void removeTermToBooleanConverter(Comparable nameIndex)

addTermToCharConverter

public void addTermToCharConverter(Comparable nameIndex,
                                   TypeConversion.TermToChar converter)

removeTermToCharConverter

public void removeTermToCharConverter(Comparable nameIndex)

addTermToStringConverter

public void addTermToStringConverter(Comparable nameIndex,
                                     TypeConversion.TermToString converter)

removeTermToStringConverter

public void removeTermToStringConverter(Comparable nameIndex)

addTermToNumberConverter

public void addTermToNumberConverter(Comparable nameIndex,
                                     TypeConversion.TermToNumber converter)

removeTermToNumberConverter

public void removeTermToNumberConverter(Comparable nameIndex)

addObjectToStringConverter

public void addObjectToStringConverter(Class classToConvert,
                                       TypeConversion.ObjectToString converter)

removeObjectToStringConverter

public void removeObjectToStringConverter(Class classToConvert)

addObjectToNumberConverter

public void addObjectToNumberConverter(Class classToConvert,
                                       TypeConversion.ObjectToNumber converter)

removeObjectToNumberConverter

public void removeObjectToNumberConverter(Class classToConvert)

addObjectToTermConverter

public void addObjectToTermConverter(Class classToConvert,
                                     TypeConversion.ObjectToTerm converter)

removeObjectToTermConverter

public void removeObjectToTermConverter(Class classToConvert)