com.davisor.data
Class EnumType

java.lang.Object
  extended byjava.text.Format
      extended bycom.davisor.data.Type
          extended bycom.davisor.data.LocaleType
              extended bycom.davisor.data.FormatType
                  extended bycom.davisor.data.SimpleNumberType
                      extended bycom.davisor.data.FloatType
                          extended bycom.davisor.data.EnumType
All Implemented Interfaces:
java.lang.Cloneable, java.util.Comparator, com.davisor.core.Dupable, NumberType, java.io.Serializable
Direct Known Subclasses:
EnumDataBufferType

public abstract class EnumType
extends FloatType

EnumType defines a base class for enumerated data types that provide one-way mapping from integer indexes to enumerated values. In particular, sub-classes are expected to define backend implementation for the enumValue(int) method that does the mapping.

EnumType supports number values of any number type, including floating point values. In particular, EnumType inherits FloatType instead of for example IntegerType to allow construction and interpolation of fraction values. Fraction values are mapped to enumerated values by first trucating them to corresponding integer values, and then mapping the results to enumerated values.

Since:
JDK1.1
See Also:
FormatType.setFormat(java.util.Locale, java.lang.String), EnumData, Serialized Form

Nested Class Summary
 
Nested classes inherited from class java.text.Format
java.text.Format.Field
 
Field Summary
static java.lang.String TYPENAME
          Type name ("ENUM").
 
Fields inherited from class com.davisor.data.FloatType
DEFAULT
 
Fields inherited from class com.davisor.data.FormatType
M_pattern, M_sample
 
Fields inherited from class com.davisor.data.LocaleType
DEFAULT_LOCALE, M_locale
 
Fields inherited from class com.davisor.data.Type
METADATA_GROUP, METADATA_NAME, METADATA_PARENT, METADATA_SUBCHANNELS
 
Constructor Summary
  EnumType(EnumType et)
          Copy constructor.
protected EnumType(java.lang.String typeName, java.lang.String dataName, java.lang.String id, java.util.Map metaData, java.util.Locale locale, java.lang.String pattern, java.lang.Object sample)
          Creates a new enum type.
 
Method Summary
abstract  DataValue enumValue(int value)
          Converts the index to an enumerated value.
 DataValue enumValue(int value, DataValue defaultValue)
          Converts the index to an enumerated or default value.
 float getCompatibility(java.lang.Class type)
          Gets an estimate of how well this type could represent objects of the given class.
 int getSQLCode()
          Gets the SQL type code, as defined by java.sql.Types.
 java.lang.Class getValueClass()
          Gets value container class.
 java.lang.String stringValue(byte value)
          Converts a byte value to a string.
 java.lang.String stringValue(double value)
          Converts a double value to a string.
 java.lang.String stringValue(float value)
          Converts a float value to a string.
 java.lang.String stringValue(int value)
          Converts an integer value to a string.
 java.lang.String stringValue(long value)
          Converts a long value to a string.
 java.lang.String stringValue(java.lang.Number value)
          Converts a Number value to a string.
 java.lang.String stringValue(short value)
          Converts a short value to a string.
 
Methods inherited from class com.davisor.data.FloatType
dup, equals, toData, toData, toData, toData
 
Methods inherited from class com.davisor.data.SimpleNumberType
byteValue, byteValue, createFormatter, doubleValue, doubleValue, floatValue, floatValue, intValue, intValue, longValue, longValue, numberValue, shortValue, shortValue, zero
 
Methods inherited from class com.davisor.data.FormatType
clearFormatter, getFormat, getFormatter, getPattern, getSample, hashCode, setFormat, setFormat, setLocale, setPattern, setSample
 
Methods inherited from class com.davisor.data.LocaleType
getLocale, setLocale
 
Methods inherited from class com.davisor.data.Type
ceil, check, check, compare, create, create, create, create, create, dup, floor, format, getDataName, getId, getID, getMetaData, getMetaData, getSpecs, getSQLName, getSQLName, getTypeName, isNull, parseObject, register, register, setDataName, setId, setID, setMetaData, setMetaData, setSpecs, toString, toXML, xmlEnd, xmlStart
 
Methods inherited from class java.text.Format
clone, format, formatToCharacterIterator, parseObject
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

TYPENAME

public static final java.lang.String TYPENAME
Type name ("ENUM").

See Also:
Constant Field Values
Constructor Detail

EnumType

public EnumType(EnumType et)
Copy constructor.


EnumType

protected EnumType(java.lang.String typeName,
                   java.lang.String dataName,
                   java.lang.String id,
                   java.util.Map metaData,
                   java.util.Locale locale,
                   java.lang.String pattern,
                   java.lang.Object sample)
Creates a new enum type.

Parameters:
typeName - type name
dataName - data name (may be null)
id - type identity (may be null)
metaData - type meta data map (may be null)
locale - type locale (may be null)
pattern - format pattern (may be null)
sample - format sample (may be null)
Method Detail

stringValue

public java.lang.String stringValue(byte value)
                             throws InvalidDataException
Converts a byte value to a string.

Specified by:
stringValue in interface NumberType
Overrides:
stringValue in class SimpleNumberType
Parameters:
value - the value to be converted
Throws:
InvalidDataException - if the value cannot be converted
See Also:
stringValue(int)

stringValue

public java.lang.String stringValue(double value)
                             throws InvalidDataException
Converts a double value to a string.

Specified by:
stringValue in interface NumberType
Overrides:
stringValue in class SimpleNumberType
Parameters:
value - the value to be converted
Throws:
InvalidDataException - if the value cannot be converted
See Also:
stringValue(int)

stringValue

public java.lang.String stringValue(float value)
                             throws InvalidDataException
Converts a float value to a string.

Specified by:
stringValue in interface NumberType
Overrides:
stringValue in class SimpleNumberType
Parameters:
value - the value to be converted
Throws:
InvalidDataException - if the value cannot be converted
See Also:
stringValue(int)

stringValue

public java.lang.String stringValue(int value)
                             throws InvalidDataException
Converts an integer value to a string.

Specified by:
stringValue in interface NumberType
Overrides:
stringValue in class SimpleNumberType
Parameters:
value - the value to be converted
Throws:
InvalidDataException - if the value cannot be converted
See Also:
enumValue(int)

stringValue

public java.lang.String stringValue(long value)
                             throws InvalidDataException
Converts a long value to a string.

Specified by:
stringValue in interface NumberType
Overrides:
stringValue in class SimpleNumberType
Parameters:
value - the value to be converted
Throws:
InvalidDataException - if the value cannot be converted
See Also:
stringValue(int)

stringValue

public java.lang.String stringValue(short value)
                             throws InvalidDataException
Converts a short value to a string.

Specified by:
stringValue in interface NumberType
Overrides:
stringValue in class SimpleNumberType
Parameters:
value - the value to be converted
Throws:
InvalidDataException - if the value cannot be converted
See Also:
FormatType.getFormatter()

stringValue

public java.lang.String stringValue(java.lang.Number value)
                             throws InvalidDataException
Converts a Number value to a string.

Specified by:
stringValue in interface NumberType
Overrides:
stringValue in class SimpleNumberType
Parameters:
value - the value to be converted
Throws:
InvalidDataException - if the value cannot be converted
See Also:
stringValue(int)

enumValue

public abstract DataValue enumValue(int value)
                             throws com.davisor.core.NotFoundException
Converts the index to an enumerated value.

Parameters:
value - index of an enumerated value
Returns:
enumerated data value
Throws:
com.davisor.core.NotFoundException - the element with 'value' was not found

enumValue

public DataValue enumValue(int value,
                           DataValue defaultValue)
Converts the index to an enumerated or default value.

Parameters:
value - index of an enumerated value
defaultValue - value to return if enumerated value was not found
Returns:
enumerated or default data value

getCompatibility

public float getCompatibility(java.lang.Class type)
Gets an estimate of how well this type could represent objects of the given class.

Overrides:
getCompatibility in class Type
Parameters:
type - type to estimate
Returns:
0.0, if the types are not compatible and 1.0 if there is perfect match. Superclasses may override this method with implementations that may return something in between.
See Also:
getValueClass()

getSQLCode

public int getSQLCode()
Gets the SQL type code, as defined by java.sql.Types.

Overrides:
getSQLCode in class FloatType

getValueClass

public java.lang.Class getValueClass()
Gets value container class.

Overrides:
getValueClass in class FloatType


Copyright © 2001-2004 Davisor Oy. All Rights Reserved.