com.davisor.data
Class BooleanType

java.lang.Object
  extended byjava.text.Format
      extended bycom.davisor.data.Type
          extended bycom.davisor.data.BooleanType
All Implemented Interfaces:
java.lang.Cloneable, java.util.Comparator, com.davisor.core.Dupable, java.io.Serializable

public class BooleanType
extends Type

BooleanType defines a data type that interpretes the strings true and false as corresponding boolean values. A set of custom true and false strings can also be specified.

Format syntax

BooleanType format defines alternative custom keywords for boolean true and false values, expressed in a format string as:
trueKeyword [ " " falseKeyword ]
Once set, terms that match the given keywords are interpreted as and printed for boolean true and false values. The default keywords "true" and "false" are also always recognized, but printed only if corresponding custom keywords have not been defined.

Examples

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

Nested Class Summary
 
Nested classes inherited from class java.text.Format
java.text.Format.Field
 
Field Summary
static BooleanType DEFAULT
          Default boolean type.
static java.lang.String FALSE
          Default false string ("false").
static int FALSELENGTH
          Default false string length.
static java.lang.String TRUE
          Default true string ("true").
static int TRUELENGTH
          Default true string length.
static java.lang.String TYPENAME
          Type name ("BOOLEAN").
 
Fields inherited from class com.davisor.data.Type
METADATA_GROUP, METADATA_NAME, METADATA_PARENT, METADATA_SUBCHANNELS
 
Constructor Summary
  BooleanType()
          Default constructor.
  BooleanType(BooleanType bt)
          Copy constructor.
  BooleanType(java.lang.String dataName)
          Creates a new default type with no identity.
  BooleanType(java.lang.String dataName, java.lang.String id, java.util.Map metaData, java.lang.String trueString, java.lang.String falseString)
          Creates a new boolean type.
  BooleanType(java.lang.String dataName, java.lang.String id, java.lang.String format)
          Constructs a new type with given spesification.
protected BooleanType(java.lang.String typeName, java.lang.String dataName, java.lang.String id, java.util.Map metaData, java.lang.String trueString, java.lang.String falseString)
          Creates a new boolean type.
 
Method Summary
 java.lang.Boolean decode(java.lang.String value)
          Converts a string to a Boolean value.
 java.lang.Boolean decode(java.lang.String stringValue, java.text.ParsePosition status)
          Converts a string to a boolean value.
 com.davisor.core.Dupable dup()
          Makes a deep copy of this object.
 java.lang.String encode(java.lang.Boolean value)
          Convert Boolean to string value.
 boolean equals(java.lang.Object o)
          Tests if this object is equal with another object.
 java.lang.String getFormat()
          Gets the current boolean format.
 int getSQLCode()
          Gets the SQL type code, as defined by java.sql.Types.
 java.lang.Class getValueClass()
          Gets value container class.
 int hashCode()
          Returns a hash code value for the object.
 void setFormat(java.lang.String format)
          Sets the boolean format.
 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.
 DataValue zero()
          Gets zero data value for this type.
 
Methods inherited from class com.davisor.data.Type
ceil, check, check, compare, create, create, create, create, create, dup, floor, format, getCompatibility, 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

DEFAULT

public static final BooleanType DEFAULT
Default boolean type.


TYPENAME

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

See Also:
Constant Field Values

TRUE

public static final java.lang.String TRUE
Default true string ("true").

See Also:
Constant Field Values

TRUELENGTH

public static final int TRUELENGTH
Default true string length.


FALSE

public static final java.lang.String FALSE
Default false string ("false").

See Also:
Constant Field Values

FALSELENGTH

public static final int FALSELENGTH
Default false string length.

Constructor Detail

BooleanType

public BooleanType()
Default constructor.


BooleanType

public BooleanType(BooleanType bt)
Copy constructor.


BooleanType

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

Parameters:
dataName - data name (may be null)

BooleanType

public BooleanType(java.lang.String dataName,
                   java.lang.String id,
                   java.lang.String format)
Constructs a new type with given spesification.

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)
format - type spesification (may be null)
See Also:
setFormat(java.lang.String)

BooleanType

public BooleanType(java.lang.String dataName,
                   java.lang.String id,
                   java.util.Map metaData,
                   java.lang.String trueString,
                   java.lang.String falseString)
Creates a new boolean type.

Parameters:
dataName - data name (may be null)
id - type identity (may be null)
metaData - type meta data map (may be null)
trueString - true value keyword
falseString - false value keyword

BooleanType

protected BooleanType(java.lang.String typeName,
                      java.lang.String dataName,
                      java.lang.String id,
                      java.util.Map metaData,
                      java.lang.String trueString,
                      java.lang.String falseString)
Creates a new boolean 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)
trueString - true value keyword
falseString - false value keyword
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

equals

public boolean equals(java.lang.Object o)
Tests if this object is equal with another object.

Boolean types are equal if their super-classes and custom truth values are.

Specified by:
equals in interface java.util.Comparator
Overrides:
equals in class Type
See Also:
Compare.equals(Object,Object)

hashCode

public int hashCode()
Returns a hash code value for the object.

Overrides:
hashCode in class Type

decode

public java.lang.Boolean decode(java.lang.String value)
                         throws InvalidDataException
Converts a string to a Boolean value.

Parameters:
value - the string from which the truth value is searched for
Throws:
InvalidDataExeption - if value cannot be decoded
InvalidDataException
See Also:
decode(String,ParsePosition)

decode

public java.lang.Boolean decode(java.lang.String stringValue,
                                java.text.ParsePosition status)
                         throws InvalidDataException
Converts a string to a boolean value. If the first characters in given value are equal to either the default or current custom true string, then the boolean value will evaluate true. Likewise, if the first characters in value are equal to either the default or current custom false string, the boolean value will evaluate false. null or empty string value will evaluate to null boolean value.

Parameters:
stringValue - the string value to convert (may be null)
status - parse status (may be null)
Returns:
boolean value corresponding to given value (may be null)
Throws:
InvalidDataExeption - if value cannot be decoded
InvalidDataException
See Also:
decode(String,ParsePosition)

encode

public java.lang.String encode(java.lang.Boolean value)
Convert Boolean to string value.


getSQLCode

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

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

getValueClass

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

Specified by:
getValueClass in class Type

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 boolean value, and returns a corresponding BooleanData 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 corredponding 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), BooleanData

toData

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

Boolean and Number objects are converted directly, other objects are converted first to strings, then to boolean values.

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

toData

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

Boolean type expects the given value to be one of known boolean truth value keywords, and returns a corresponding BooleanData 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), BooleanData

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 boolean value, and returns a corresponding BooleanData 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 corredponding 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(CallableStatement,int), toData(Object), toData(String,ParsePosition), BooleanData

getFormat

public java.lang.String getFormat()
Gets the current boolean format. Please see class description for format details.

Overrides:
getFormat in class Type
Returns:
boolean format (may be null)
See Also:
setFormat(java.lang.String)

setFormat

public void setFormat(java.lang.String format)
Sets the boolean format. Please see class description for format details.

Overrides:
setFormat in class Type
Parameters:
format - boolean format (may be null)
See Also:
Type.getFormat(), DataValue.getFormat()

zero

public DataValue zero()
Gets zero data value for this type.

Specified by:
zero in class Type
Returns:
a new zero value BooleanData object sharing this type
See Also:
DataValue.deinterpolate(com.davisor.data.DataValue, com.davisor.data.DataValue), DataValue.interpolate(double, com.davisor.data.DataValue)


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