com.davisor.data
Class BooleanData

java.lang.Object
  extended bycom.davisor.data.VoidData
      extended bycom.davisor.data.VoidValue
          extended bycom.davisor.data.GenericValue
              extended bycom.davisor.data.BooleanData
All Implemented Interfaces:
java.lang.Comparable, Data, DataValue, com.davisor.core.Dupable, NumberValue, java.io.Serializable, SerializableData

public class BooleanData
extends GenericValue
implements com.davisor.core.Dupable, NumberValue

BooleanData objects represent boolean data values.

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

Field Summary
 
Fields inherited from class com.davisor.data.VoidData
M_type
 
Constructor Summary
BooleanData()
          Creates a boolean data object with a default boolean type and value (false).
BooleanData(boolean value)
          Create a new boolean number data object with the default type and given value.
BooleanData(java.lang.Boolean value)
          Constructs a boolean data object with a default boolean type and given value.
BooleanData(BooleanData data, boolean deep)
          Deep or shallow copy constructor.
BooleanData(BooleanType type)
          Constructs a boolean data object with a given boolean type and default value (false).
BooleanData(BooleanType type, boolean value)
          Constructs a boolean data object with a given boolean type and value.
BooleanData(BooleanType type, java.lang.Boolean value)
          Constructs a boolean data object with a given boolean type and value.
BooleanData(BooleanType type, java.lang.Number value)
          Constructs a boolean data object with a given boolean type and value.
BooleanData(BooleanType type, java.lang.String stringValue, java.text.ParsePosition status)
          Creates a boolean data value from a string value.
 
Method Summary
 DataValue abs()
          Returns absolute data value of current value.
 DataValue add(DataValue value)
          Multipies given value to the current value.
static java.lang.Boolean and(java.lang.Boolean b1, java.lang.Boolean b2)
          Computes boolean AND value in a null -safe way.
 byte byteValue()
          Gets number byte value.
 DataValue ceil(DataValue precision)
          Quantizes the current value up to an even value within given precision.
 int compareTo(java.lang.Object o)
          Compares this data with other data objects.
 double deinterpolate(DataValue min, DataValue max)
          De-interpolates the current data value to a scalar value, in respect, with the given data value range.
 DataValue div(DataValue value)
          Divides the current value with given value.
 double doubleValue()
          Gets number double value.
 com.davisor.core.Dupable dup()
          Makes a deep copy of this object.
 boolean equals(java.lang.Object o)
          Tests if this object is equal with another object.
 float floatValue()
          Gets the number float value.
 DataValue floor(DataValue precision)
          Quantizes the current value down to an even value within given precision.
 java.lang.String getFormat()
          Gets the type specification optimal for this particular value.
 java.lang.Boolean getValue()
          Gets the boolean data boolean value.
 boolean getValueDefault()
          Gets the boolean data boolean value.
 int hashCode()
          Returns a hash code value for the object.
 DataValue interpolate(double value, DataValue max)
          Interpolates the given scalar value to data value, in respect, with the range defined by this value and the given maximum value.
 int intValue()
          Gets number int value.
 boolean isNull()
          Tests if this data object value is undetermined.
 long longValue()
          Gets number long value.
 DataValue max(DataValue value)
          Finds the larger of this and the given data value.
 DataValue min(DataValue value)
          Finds the smaller of this and the given data value.
 DataValue mul(DataValue value)
          Multipies the current value with given value.
 DataValue negate()
          Returns the negation of current value.
static java.lang.Boolean not(java.lang.Boolean b)
          Computes boolean NOT value in a null -safe way.
 java.lang.Number numberValue()
          Gets the data Number value.
static java.lang.Boolean or(java.lang.Boolean b1, java.lang.Boolean b2)
          Computes boolean OR value in a null -safe way.
 void setValue(boolean value)
          Sets the boolean value.
 void setValue(java.lang.Boolean value)
          Sets the boolean value.
 void setValue(byte value)
          Sets the data byte value.
 void setValue(double value)
          Sets the data double value.
 void setValue(float value)
          Sets the data float value.
 void setValue(int value)
          Sets the data int value.
 void setValue(long value)
          Sets the data long value.
 void setValue(java.lang.Number value)
          Sets the data Number value.
 void setValue(short value)
          Sets the data short value.
 void setValue(java.lang.String stringValue, java.text.ParsePosition status)
          Sets data value from a string value.
 short shortValue()
          Gets number short value.
 DataValue sub(DataValue value)
          Substracts given value from the current value.
 void toStatement(java.sql.PreparedStatement statement, int parameter)
          Convert the data to a prepared statement input parameter.
 java.lang.String toString()
          Gets the string representation of this boolean value.
 DataValue unit(DataValue targetValue, double maxSteps)
          Gets the largest suitable unit step to represent a value change between this value and the given target value.
static java.lang.Boolean xor(java.lang.Boolean b1, java.lang.Boolean b2)
          Computes boolean XOR value in a null -safe way.
 
Methods inherited from class com.davisor.data.GenericValue
toXML
 
Methods inherited from class com.davisor.data.VoidData
getDataValue, getType, setType
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.davisor.data.DataValue
toXML
 
Methods inherited from interface com.davisor.data.Data
getType
 

Constructor Detail

BooleanData

public BooleanData()
Creates a boolean data object with a default boolean type and value (false).

See Also:
BooleanData(BooleanType,boolean)

BooleanData

public BooleanData(BooleanData 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:
VoidData.getType(), Type.dup()

BooleanData

public BooleanData(BooleanType type)
Constructs a boolean data object with a given boolean type and default value (false).

Parameters:
type - custom boolean type
See Also:
BooleanData(BooleanType,boolean)

BooleanData

public BooleanData(java.lang.Boolean value)
Constructs a boolean data object with a default boolean type and given value.

Parameters:
value - boolean value
See Also:
BooleanData(BooleanType,boolean)

BooleanData

public BooleanData(boolean value)
Create a new boolean number data object with the default type and given value.

Parameters:
value - data value

BooleanData

public BooleanData(BooleanType type,
                   boolean value)
Constructs a boolean data object with a given boolean type and value.

Parameters:
type - custom boolean type
value - boolean value

BooleanData

public BooleanData(BooleanType type,
                   java.lang.Boolean value)
Constructs a boolean data object with a given boolean type and value.

Parameters:
type - custom boolean type
value - boolean value
See Also:
BooleanData(BooleanType,boolean)

BooleanData

public BooleanData(BooleanType type,
                   java.lang.Number value)
Constructs a boolean data object with a given boolean type and value.

Parameters:
type - custom boolean type
value - boolean value (a non-zero int value means true)

BooleanData

public BooleanData(BooleanType type,
                   java.lang.String stringValue,
                   java.text.ParsePosition status)
            throws InvalidDataException
Creates a boolean data value from a string value.

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

compareTo

public int compareTo(java.lang.Object o)
Compares this data with other data objects.

Specified by:
compareTo in interface java.lang.Comparable
Overrides:
compareTo in class GenericValue
See Also:
Compare.compareTo(Boolean,Boolean)

isNull

public boolean isNull()
Tests if this data object value is undetermined.

Specified by:
isNull in interface SerializableData
Overrides:
isNull in class VoidValue
Returns:
always true

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
Overrides:
abs in class VoidValue
Returns:
a new data object, sharing the current type of this object
Throws:
InvalidDataException - if absolute value can not be computed

add

public DataValue add(DataValue value)
              throws InvalidDataException
Multipies given value to the current value. Adding of boolean data corresponds to an or(java.lang.Boolean, java.lang.Boolean) operation.

Specified by:
add in interface DataValue
Overrides:
add in class VoidValue
Parameters:
value - a data value to be added to this data value
Returns:
a new data object, sharing the current type of this object
Throws:
InvalidDataException - if the data values cannot be added.

ceil

public DataValue ceil(DataValue precision)
               throws InvalidDataException
Quantizes the current value up to an even value within given precision. The returned value is more than or equal with the current value, but not more than the current value added by given precision.

Boolean values are quantized by default.

Specified by:
ceil in interface DataValue
Overrides:
ceil in class VoidValue
Parameters:
precision - the precision within quantization occurs (ignored)
Returns:
a new data object, sharing the current type of this object
Throws:
InvalidDataException - if precision was of unacceptable type
See Also:
floor(com.davisor.data.DataValue)

deinterpolate

public double deinterpolate(DataValue min,
                            DataValue max)
                     throws InvalidDataException
De-interpolates the current data value to a scalar value, in respect, with the given data value range. This gives scalar values between [0,1], when the current data value in within the range, negative scalar values when the data value falls below the range and scalar values greater than 1.0 otherwise.

Boolean values are de-interpolated with a table:

                       |  own value                  
 min value | max value | false | true
-----------|-----------|-------|------
   false   |   false   |  0.5  |  1.5
   false   |   true    |   0   |   1
   true    |   true    | -0.5  |  0.5
   true    |   false   |   1   |   0
 

Specified by:
deinterpolate in interface DataValue
Overrides:
deinterpolate in class VoidValue
Parameters:
min - a data value representing a range's lower limit
max - a data value representing a range's higher limit
Returns:
de-interpolated scalar value
Throws:
InvalidDataException - if de-interpolation fails

div

public DataValue div(DataValue value)
              throws InvalidDataException
Divides the current value with given value. Division of boolean data corresponds to a xor(java.lang.Boolean, java.lang.Boolean) (exclusive or) operation.

Specified by:
div in interface DataValue
Overrides:
div in class VoidValue
Parameters:
value - the divider
Returns:
a new data object, sharing the current type of this object.
Throws:
InvalidDataException - if divider is not BooleanData.

floor

public DataValue floor(DataValue precision)
                throws InvalidDataException
Quantizes the current value down to an even value within given precision. The returned value is less than or equal with the current value, but not less than the current value substracted by given precision.

Boolean values are quantized by default.

Specified by:
floor in interface DataValue
Overrides:
floor in class VoidValue
Parameters:
precision - the precision within quantization occurs (ignored)
Returns:
a new data object, sharing the current type of this object
Throws:
InvalidDataException - if precision was of unacceptable type
See Also:
ceil(com.davisor.data.DataValue)

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 with the value returned by this method will ensure optimal value formatting and parsing for values of the same magnitude as this value.

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

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

interpolate

public DataValue interpolate(double value,
                             DataValue max)
                      throws InvalidDataException
Interpolates the given scalar value to data value, in respect, with the range defined by this value and the given maximum value. Scalar values between [0,1] result in data values between the current value and the given maximum value. Negative scalar values result in values smaller than this value and scalar values higher than 1.0 return data values above the given maximum.

Boolean values are interpolated with the table:

                          scalar values
                          resulting in
                       |
 own value | max value |  false | true
-----------|-----------|--------|-------
   false   |   false   | <= 1   |  > 1 
   false   |   true    |  < 0.5 | >= 0.5
   true    |   true    |  < 0   | >= 0 
   true    |   false   | >= 0.5 |  < 0.5
 

Specified by:
interpolate in interface DataValue
Overrides:
interpolate in class VoidValue
Parameters:
value - the scalar value to be interpolated
max - a data value representing a range's higher limit
Returns:
a new data object containing the result
Throws:
InvalidDataException - if interpolation fails

max

public DataValue max(DataValue value)
              throws InvalidDataException
Finds the larger of this and the given data value.

If the given value is null or an instance of VoidValue, a reference to this instance is returned.

Specified by:
max in interface DataValue
Overrides:
max in class GenericValue
Parameters:
value - a data value to be compared with this data value
Returns:
Returns the largest of the compared data values.
Throws:
InvalidDataException - if the data value cannot be compared.
See Also:
GenericValue.compareTo(java.lang.Object)

min

public DataValue min(DataValue value)
              throws InvalidDataException
Finds the smaller of this and the given data value.

If the given value is null or an instance of VoidValue, a reference to this instance is returned.

Specified by:
min in interface DataValue
Overrides:
min in class GenericValue
Parameters:
value - a data value to be compared with this data value
Returns:
Returns the smallest of the compared data values.
Throws:
InvalidDataException - if the data value cannot be compared.
See Also:
GenericValue.compareTo(java.lang.Object)

mul

public DataValue mul(DataValue value)
              throws InvalidDataException
Multipies the current value with given value. Multiplication of boolean data corresponds to an and(java.lang.Boolean, java.lang.Boolean) operation.

Specified by:
mul in interface DataValue
Overrides:
mul in class VoidValue
Parameters:
value - the multiplier
Returns:
a new data object, sharing the current type of this object.
Throws:
InvalidDataException - if multiplier is not BooleanData.

negate

public DataValue negate()
                 throws InvalidDataException
Returns the negation of current value. Negating boolean data corresponds to a not(java.lang.Boolean) operation.

Specified by:
negate in interface DataValue
Overrides:
negate in class VoidValue
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.

Specified by:
setValue in interface DataValue
Overrides:
setValue in class VoidValue
Parameters:
stringValue - string value to be parsed (may be null)
status - parse status (may be null)
Throws:
InvalidDataException - if string value could not be parsed
See Also:
BooleanType.decode(String,ParsePosition)

sub

public DataValue sub(DataValue value)
              throws InvalidDataException
Substracts given value from the current value. Substraction of boolean data corresponds to a xor(java.lang.Boolean, java.lang.Boolean) (exclusive or) operation.

Specified by:
sub in interface DataValue
Overrides:
sub in class VoidValue
Parameters:
value - a data value to be substracted from this data value
Returns:
a new data object, sharing the current type of this object
Throws:
InvalidDataException - if value cannot be substracted.

toStatement

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

Specified by:
toStatement in interface DataValue
Overrides:
toStatement in class GenericValue
Parameters:
statement - statement to be updated
parameter - index of the statement parameter to be updated
Throws:
java.sql.SQLException - if a SQL error occurs.
See Also:
VoidData.toString()

unit

public DataValue unit(DataValue targetValue,
                      double maxSteps)
               throws InvalidDataException
Gets the largest suitable unit step to represent a value change between this value and the given target value. If the values are equal, then the type specific default unit step is returned. If the values are not equal, the given target value must be reached from this value by adding the returned unit step to this value once or more.

Specified by:
unit in interface DataValue
Overrides:
unit in class VoidValue
Parameters:
targetValue - target value to be reached (may be null)
maxSteps - maximum number of steps (zero leaves the choise open)
Returns:
a new data object, sharing the current type of this object
Throws:
InvalidDataException - if target value is unsuitable

dup

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

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

byteValue

public byte byteValue()
Gets number byte value.

Specified by:
byteValue in interface NumberValue
Throws:
java.lang.NullPointerException - if number value is not set
See Also:
NumberType.byteValue(java.lang.String, java.text.ParsePosition)

doubleValue

public double doubleValue()
Gets number double value.

Specified by:
doubleValue in interface NumberValue
Throws:
java.lang.NullPointerException - if number value is not set
See Also:
NumberType.doubleValue(java.lang.String, java.text.ParsePosition)

floatValue

public float floatValue()
Gets the number float value.

Specified by:
floatValue in interface NumberValue
Throws:
java.lang.NullPointerException - if number value is not set
See Also:
NumberType.floatValue(java.lang.String, java.text.ParsePosition)

intValue

public int intValue()
Gets number int value.

Specified by:
intValue in interface NumberValue
Throws:
java.lang.NullPointerException - if number value is not set
See Also:
NumberType.intValue(java.lang.String, java.text.ParsePosition)

longValue

public long longValue()
Gets number long value.

Specified by:
longValue in interface NumberValue
Throws:
java.lang.NullPointerException - if number value is not set
See Also:
NumberType.longValue(java.lang.String, java.text.ParsePosition)

shortValue

public short shortValue()
Gets number short value.

Specified by:
shortValue in interface NumberValue
Throws:
java.lang.NullPointerException - if number value is not set
See Also:
NumberType.shortValue(java.lang.String, java.text.ParsePosition)

numberValue

public java.lang.Number numberValue()
Gets the data Number value.

Specified by:
numberValue in interface NumberValue

setValue

public void setValue(byte value)
              throws InvalidDataException
Sets the data byte value.

Specified by:
setValue in interface NumberValue
Throws:
InvalidDataException - if the value cannot be converted to a byte value.

setValue

public void setValue(double value)
              throws InvalidDataException
Sets the data double value.

Specified by:
setValue in interface NumberValue
Throws:
InvalidDataException - if the value cannot be converted to a double value.

setValue

public void setValue(float value)
              throws InvalidDataException
Sets the data float value.

Specified by:
setValue in interface NumberValue
Throws:
InvalidDataException - if the value cannot be converted to a float value.

setValue

public void setValue(int value)
              throws InvalidDataException
Sets the data int value.

Specified by:
setValue in interface NumberValue
Throws:
InvalidDataException - if the value cannot be converted to a int value.

setValue

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

Specified by:
setValue in interface NumberValue
Throws:
InvalidDataException - if the value cannot be converted

setValue

public void setValue(long value)
              throws InvalidDataException
Sets the data long value.

Specified by:
setValue in interface NumberValue
Throws:
InvalidDataException - if the value cannot be converted to a long value.

setValue

public void setValue(short value)
              throws InvalidDataException
Sets the data short value.

Specified by:
setValue in interface NumberValue
Throws:
InvalidDataException - if the value cannot be converted to a short value.

equals

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

Boolean data objects are equal if their super-classes and values are.

Overrides:
equals in class VoidData
See Also:
Compare.equals(Object,Object), Type.equals(Object)

hashCode

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

Overrides:
hashCode in class VoidData

toString

public java.lang.String toString()
Gets the string representation of this boolean value.

Specified by:
toString in interface DataValue
Overrides:
toString in class VoidData
See Also:
BooleanType.encode(java.lang.Boolean)

and

public static java.lang.Boolean and(java.lang.Boolean b1,
                                    java.lang.Boolean b2)
Computes boolean AND value in a null -safe way.

Parameters:
b1 - the first boolean value (may be null)
b2 - the second boolean value (may be null)

getValue

public java.lang.Boolean getValue()
Gets the boolean data boolean value.

Returns:
boolean value (may be null)

getValueDefault

public boolean getValueDefault()
Gets the boolean data boolean value. If the value is unspecified, false is returned by default.

Returns:
boolean value

not

public static java.lang.Boolean not(java.lang.Boolean b)
Computes boolean NOT value in a null -safe way.

Parameters:
b - the boolean value (may be null)

or

public static java.lang.Boolean or(java.lang.Boolean b1,
                                   java.lang.Boolean b2)
Computes boolean OR value in a null -safe way.

Parameters:
b1 - the first boolean value (may be null)
b2 - the second boolean value (may be null)

setValue

public void setValue(boolean value)
Sets the boolean value.

Parameters:
value - a boolean value
Returns:
A reference to this object.

setValue

public void setValue(java.lang.Boolean value)
Sets the boolean value.

Parameters:
value - a boolean value (may be null)
Returns:
A reference to this object.

xor

public static java.lang.Boolean xor(java.lang.Boolean b1,
                                    java.lang.Boolean b2)
Computes boolean XOR value in a null -safe way.

Parameters:
b1 - the first boolean value (may be null)
b2 - the second boolean value (may be null)


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