com.davisor.data
Class CountType

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.CountType
All Implemented Interfaces:
java.lang.Cloneable, java.util.Comparator, com.davisor.core.Dupable, NumberType, java.io.Serializable

public class CountType
extends SimpleNumberType

CountType defines a data type that interprets repetitions of a counter token string as non-negative values. In other words, 'n' repetitions of a token equals integer value 'n'.

The default token string is "*", but it can be set to any string with the 'setSpecs' method.

Since:
JDK1.1
See Also:
CountData, Serialized Form

Nested Class Summary
 
Nested classes inherited from class java.text.Format
java.text.Format.Field
 
Field Summary
static java.lang.String TOKEN
          Default token ("*").
static java.lang.String TYPENAME
          Type name ("COUNT").
 
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
  CountType()
          Default constructor.
  CountType(CountType ct)
          Copy constructor.
  CountType(java.lang.String dataName)
          Creates a new default type with no identity.
  CountType(java.lang.String dataName, java.lang.String id, java.lang.String token)
          Creates a new count type.
protected CountType(java.lang.String typeName, java.lang.String dataName, java.lang.String id, java.util.Map metaData, java.lang.String token)
          Creates a new count type.
 
Method Summary
 java.lang.Short countValue(java.lang.String stringValue, java.text.ParsePosition status)
          Convert string to a counter value.
 com.davisor.core.Dupable dup()
          Makes a deep copy of this object.
 float getCompatibility(java.lang.Class type)
          Gets an estimate of how well this type could represent objects of the given class.
 java.lang.String getSpecs()
          Get the counter token string.
 int getSQLCode()
          Gets SQL type code, as defined byt java.sql.Types.
 java.lang.String getToken()
          Gets the current token string.
 java.lang.Class getValueClass()
          Gets value container class.
 void setSpecs(java.lang.String specs)
          Set the counter token string.
 java.lang.String stringValue(short value)
          Convert an integer to concatenated token strings.
 DataValue toData(java.sql.CallableStatement statement, int column)
          Converts a callable statement variable to a data value.
 DataValue toData(java.lang.Object objectValue)
          Converts an object to a data value.
 DataValue toData(java.sql.ResultSet resultSet, int column)
          Converts a result set column value to a data value.
 DataValue toData(java.lang.String stringValue, java.text.ParsePosition status)
          Converts a string to a data value.
 
Methods inherited from class com.davisor.data.SimpleNumberType
byteValue, byteValue, createFormatter, doubleValue, doubleValue, floatValue, floatValue, intValue, intValue, longValue, longValue, numberValue, shortValue, shortValue, stringValue, stringValue, stringValue, stringValue, stringValue, stringValue, zero
 
Methods inherited from class com.davisor.data.FormatType
clearFormatter, equals, 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, getSQLName, getSQLName, getTypeName, isNull, parseObject, register, register, setDataName, setId, setID, setMetaData, setMetaData, 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 ("COUNT").

See Also:
Constant Field Values

TOKEN

public static final java.lang.String TOKEN
Default token ("*").

See Also:
Constant Field Values
Constructor Detail

CountType

public CountType()
Default constructor.


CountType

public CountType(CountType ct)
Copy constructor.


CountType

public CountType(java.lang.String dataName)
Creates a new default type with no identity.

Parameters:
dataName - data name (may be null)

CountType

public CountType(java.lang.String dataName,
                 java.lang.String id,
                 java.lang.String token)
Creates a new count type.

This is the constructor the SQL type mapper Type.create(Integer,String,String,String) method will call to create a type that matches given SQL type.

Parameters:
dataName - data name (may be null)
id - type identity (may be null)
token - token string

CountType

protected CountType(java.lang.String typeName,
                    java.lang.String dataName,
                    java.lang.String id,
                    java.util.Map metaData,
                    java.lang.String token)
Creates a new count 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)
token - token string
Method Detail

dup

public com.davisor.core.Dupable dup()
Makes a deep copy of this object.

Specified by:
dup in interface com.davisor.core.Dupable
Specified by:
dup in class Type

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.5 if the given type is assignable from Short, otherwise 0.0.
See Also:
getValueClass()

getSQLCode

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

Overrides:
getSQLCode in class Type
Returns:
Types.VARCHAR.

getValueClass

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

Overrides:
getValueClass in class FormatType

toData

public DataValue toData(java.sql.CallableStatement statement,
                        int column)
                 throws InvalidDataException,
                        java.sql.SQLException
Converts a callable statement variable to a data value.

Gets statement short value, and returns a corresponding CountData value.

Overrides:
toData in class Type
Parameters:
statement - statement holding the data value to be converted
column - SQL column index for the data value to be converted
Returns:
a data value object corresponding to given object value
Throws:
InvalidDataException - if given object value could not be parsed
java.sql.SQLException - if a SQL error occurs
See Also:
toData(Object), toData(ResultSet,int), toData(String,ParsePosition), CountData

toData

public DataValue toData(java.lang.Object objectValue)
                 throws InvalidDataException
Converts an object to a data value.

Number objects are converted directly, other objects are converted first to strings, then to count values.

Overrides:
toData in class Type
Parameters:
objectValue - data object
Returns:
a data value object corresponding to the given object value
Throws:
InvalidDataException - if given object value could not be parsed
See Also:
toData(CallableStatement,int), toData(ResultSet,int), toData(String,ParsePosition), CountData

toData

public DataValue toData(java.lang.String stringValue,
                        java.text.ParsePosition status)
                 throws InvalidDataException
Converts a string to a data value.

Count type expects the given value to contain known token strings, or an integer value, and returns a corresponding CountData value

Specified by:
toData in class Type
Parameters:
stringValue - data string
status - parse status (may be null)
Returns:
a data value object corresponding given string value
Throws:
InvalidDataException - if given string value could not be parsed
See Also:
toData(CallableStatement,int), toData(Object), toData(ResultSet,int), CountData

toData

public DataValue toData(java.sql.ResultSet resultSet,
                        int column)
                 throws InvalidDataException,
                        java.sql.SQLException
Converts a result set column value to a data value.

Gets result set column short value, and returns a corresponding CountData value.

Overrides:
toData in class Type
Parameters:
resultSet - resultSet holding the data value to be converted
column - SQL column index for the data value to be converted
Returns:
a data value object corresponding to the given object value
Throws:
InvalidDataException - if given object value could not be parsed
java.sql.SQLException - if a SQL error occurs
See Also:
toData(CallableStatement,int), toData(Object), toData(String,ParsePosition), CountData

getSpecs

public java.lang.String getSpecs()
Get the counter token string.

Overrides:
getSpecs in class Type
Returns:
counter token string (may be null)
See Also:
setSpecs(java.lang.String)

setSpecs

public void setSpecs(java.lang.String specs)
Set the counter token string.

Overrides:
setSpecs in class Type
Parameters:
specs - counter token string (may be null)
Returns:
A reference to this object.

countValue

public java.lang.Short countValue(java.lang.String stringValue,
                                  java.text.ParsePosition status)
                           throws InvalidDataException
Convert string to a counter value. The string is expected to contain either count tokens separated by optional white space or a non-negative integer value. null or empty string value will evaluate to null boolean value.

Parameters:
stringValue - counter value string (may be null)
status - parse status (may be null)
Returns:
counter integer value (may be null)
Throws:
InvalidDataExeption - if value cannot be decoded
InvalidDataException

getToken

public java.lang.String getToken()
Gets the current token string. If unset, it defaults to "*".

See Also:
getSpecs(), setSpecs(java.lang.String)

stringValue

public java.lang.String stringValue(short value)
Convert an integer to concatenated token strings.

Specified by:
stringValue in interface NumberType
Overrides:
stringValue in class SimpleNumberType
Parameters:
value - counter value
See Also:
FormatType.getFormatter()


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