com.davisor.data
Class CountData

java.lang.Object
  extended byjava.lang.Number
      extended bycom.davisor.data.SimpleNumberValue
          extended bycom.davisor.data.CountData
All Implemented Interfaces:
java.lang.Comparable, Data, DataValue, com.davisor.core.Dupable, NumberValue, java.io.Serializable, SerializableData

public class CountData
extends SimpleNumberValue

CountData objects represent non-negative integer values that have a special string representation. In particular, this string representation repeats a given string token as many times as the counter value is. The counter string token is specified by the data specification string.

For example, if the counter token is '**', then the string '******' equals to counter value three.

The data value inside may also be null. This indicates that the number value of this object is undetermined.

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

Field Summary
 
Fields inherited from class com.davisor.data.SimpleNumberValue
M_type, M_value
 
Constructor Summary
CountData(CountData data, boolean deep)
          Deep or shallow copy constructor.
CountData(CountType type)
          Constructs a new counter data object with the given count type and unspecified value.
CountData(CountType type, short value)
          Constructs a new counter data object with the given type and value.
CountData(CountType type, java.lang.String stringValue, java.text.ParsePosition status)
          Creates a count data value from a string value.
CountData(NumberType type, java.lang.Number value)
          Constructs a new counter data object with given type and value.
 
Method Summary
 DataValue abs()
          Returns absolute data value of current value.
 com.davisor.core.Dupable dup()
          Makes a deep copy of this object.
 java.lang.String getFormat()
          Gets the type specification optimal for this particular value.
 DataValue negate()
          Returns the negation of current value.
 void setValue(double value)
          Sets count double value.
 void setValue(long value)
          Sets count long value.
 void setValue(java.lang.Number value)
          Sets count Number value.
 void setValue(short value)
          Sets count short value.
 void setValue(java.lang.String stringValue, java.text.ParsePosition status)
          Sets data value from a string value.
 void toStatement(java.sql.PreparedStatement statement, int parameter)
          Convert data to a prepared statement input parameter.
 
Methods inherited from class com.davisor.data.SimpleNumberValue
add, byteValue, ceil, compareTo, deinterpolate, div, doubleValue, equals, floatValue, floor, getFormat, getType, hashCode, interpolate, intValue, isNull, longValue, max, min, mul, numberValue, setValue, setValue, setValue, shortValue, sub, toString, toXML, unit
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CountData

public CountData(CountData data,
                 boolean deep)
Deep or shallow copy constructor. If it is shallow, then the new object shares an underlying type with the original object. If it is deep, then the type is dupped.

Parameters:
data - source data (may be null)
deep - determines if the copying is deep or shallow
See Also:
SimpleNumberValue.SimpleNumberValue(SimpleNumberValue,boolean)

CountData

public CountData(CountType type)
Constructs a new counter data object with the given count type and unspecified value.

Parameters:
type - the type of data (may be null)
See Also:
SimpleNumberValue.SimpleNumberValue(NumberType)

CountData

public CountData(NumberType type,
                 java.lang.Number value)
Constructs a new counter data object with given type and value.

Parameters:
type - the type of data (may be null)
value - data value (may be null)
See Also:
SimpleNumberValue.SimpleNumberValue(NumberType,Number)

CountData

public CountData(CountType type,
                 short value)
Constructs a new counter data object with the given type and value.

Parameters:
type - the type of data (may be null)
value - data value
See Also:
SimpleNumberValue.SimpleNumberValue(NumberType,Number)

CountData

public CountData(CountType type,
                 java.lang.String stringValue,
                 java.text.ParsePosition status)
          throws InvalidDataException
Creates a count data value from a string value.

Parameters:
type - the type of data (may be null)
stringValue - string value to be parsed (may be null)
status - parse status (may be null)
Throws:
InvalidDataException - if string value could not be parser
See Also:
setValue(String,ParsePosition)
Method Detail

abs

public DataValue abs()
              throws InvalidDataException
Returns absolute data value of current value.

Absolute values must satisfy a requirement that when added to any other value, the result must be greater than or equal to the original value.

Specified by:
abs in interface DataValue
Specified by:
abs in class SimpleNumberValue
Returns:
a new data object, sharing the current type of this object
Throws:
InvalidDataException - if absolute value can not be computed

getFormat

public java.lang.String getFormat()
Gets the type specification optimal for this particular value. The specification returned may differ from the current type specification. If so, setting the current type specification equal to the value returned by this method will ensure optimal value formatting and parsing for values of the same magnitude as this value.

The count data optimal specification string is always the current specification string for the current type.

Specified by:
getFormat in interface DataValue
Overrides:
getFormat in class SimpleNumberValue
See Also:
Data.getType(), FormatType.getFormat(), FormatType.setFormat(java.util.Locale, java.lang.String)

negate

public DataValue negate()
                 throws InvalidDataException
Returns the negation of current value.

Specified by:
negate in interface DataValue
Specified by:
negate in class SimpleNumberValue
Returns:
a new data object, sharing the current type of this object
Throws:
InvalidDataException - if absolute value can not be computed

setValue

public void setValue(java.lang.String stringValue,
                     java.text.ParsePosition status)
              throws InvalidDataException
Sets data value from a string value.

Parameters:
stringValue - string value to be parsed (may be null)
status - parse status (may be null)
Throws:
InvalidDataException - if string value could not be parser
See Also:
CountType.countValue(String,ParsePosition)

toStatement

public void toStatement(java.sql.PreparedStatement statement,
                        int parameter)
                 throws java.sql.SQLException
Convert data to a prepared statement input parameter.

Throws:
java.sql.SQLException - if a SQL error occurs.

dup

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


setValue

public void setValue(double value)
              throws InvalidDataException
Sets count double value.

Specified by:
setValue in interface NumberValue
Specified by:
setValue in class SimpleNumberValue
Throws:
InvalidDataException - if the value cannot be converted to a count value

setValue

public void setValue(long value)
              throws InvalidDataException
Sets count long value.

Specified by:
setValue in interface NumberValue
Specified by:
setValue in class SimpleNumberValue
Throws:
InvalidDataException - if the value cannot be converted to a countvalue

setValue

public void setValue(short value)
              throws InvalidDataException
Sets count short value.

Specified by:
setValue in interface NumberValue
Overrides:
setValue in class SimpleNumberValue
Throws:
InvalidDataException - never

setValue

public void setValue(java.lang.Number value)
              throws InvalidDataException
Sets count Number value.

Specified by:
setValue in interface NumberValue
Specified by:
setValue in class SimpleNumberValue
Throws:
InvalidDataException - never


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