Data Request Broker
2-3-release

fr.gael.drb.value
Class Duration

java.lang.Object
  extended by fr.gael.drb.value.DayTimeDuration
      extended by fr.gael.drb.value.Duration
All Implemented Interfaces:
DrbItem, Arithmetic, Comparison, Sumable, Value, Serializable

public class Duration
extends DayTimeDuration

The DateTime class is a generic wrapper for Date values. WARNING : In this implementation, a year is fixed to 365.25 sideral days.

See Also:
Serialized Form

Field Summary
protected  long yearMonth
          The year/month part of this duration (in months).
 
Fields inherited from class fr.gael.drb.value.DayTimeDuration
dayTime
 
Fields inherited from interface fr.gael.drb.value.Value
ARRAY_ID, BINARY_ID, BINARY_INTEGER_ID, BOOLEAN_ID, BYTE_ID, DATE_ID, DATE_TIME_ID, DAY_ID, DAY_TIME_DURATION_ID, DECIMAL_ID, DOUBLE_ID, DURATION_ID, FLOAT_ID, INT_ID, INTEGER_ID, LONG_ID, MONTH_DAY_ID, MONTH_ID, NULL_ID, NUMERIC_ID, OTHER_ID, SHORT_ID, STRING_ID, TIME_ID, UNKNOWN_ID, UNSIGNED_BYTE_ID, UNSIGNED_INT_ID, UNSIGNED_LONG_ID, UNSIGNED_SHORT_ID, YEAR_ID, YEAR_MONTH_DURATION_ID, YEAR_MONTH_ID
 
Fields inherited from interface fr.gael.drb.DrbItem
ATTRIBUTE_ITEM, NODE_ITEM, UNDEFINED_ITEM, VALUE_ITEM
 
Constructor Summary
Duration(long year_month, double day_time)
          Build a duration from a number of month and a time.
 
Method Summary
 Value add(Value x)
          Compute an addition.
 void assign(Value v)
          Assign a new Value.
 int compareTo(Value v)
          Compare this value with another value.
 Value convertTo(int type)
          Convert the value into the specified type.
 Value divide(Value x)
          Compute a division.
 int getItemType()
          A code that identifies the value items.
 String getName()
          Name of the item.
 String getNamespaceURI()
          Get namespace URI.
 int getPriority()
          The absolute priority of the value.
 int getType()
          The type identifier of the value.
 Value getValue()
          The value of the item.
static void main(String[] args)
          Makes this class runnable for testing.
 Value modulus(Value x)
          Compute a modulus.
 Value multiply(Value x)
          Compute a multiplication.
static Duration parseDuration(String s)
          Attempts to interpret the string s as a representation of an ISO 8601 duration.
 void rename(String name)
          Changes the name of the item.
 void setNamespaceURI(String namespace_uri)
          Sets a namespace resource identifier.
 Value setValue(Value value)
          Changes the value of the item.
 Value sub(Value x)
          Compute a substraction.
 Numeric toNumeric()
          Convert the value into the numeric type.
 String toString()
          Return the duration in a string.
 Value unaryMinus()
          Compute an unary minus.
 
Methods inherited from class fr.gael.drb.value.DayTimeDuration
getDayTime
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

yearMonth

protected long yearMonth
The year/month part of this duration (in months).

Constructor Detail

Duration

public Duration(long year_month,
                double day_time)
Build a duration from a number of month and a time. The year and month part of this duration is given separely from the day and time. We advised not to mix months and days in order to avoid inconsistencies while computing arithmetic operations. Thus, when the number of month is specified, the leading number of seconds should be zero.

Parameters:
year_month - number of month in this duration
day_time - number of second in this duration
See Also:
Date
Method Detail

parseDuration

public static Duration parseDuration(String s)
Attempts to interpret the string s as a representation of an ISO 8601 duration. The pattern is [-]PnYnMTnHnMnS where the number of seconds can be fractionnal.

Parameters:
s - string to be parsed as a duration.
Returns:
the interpreted Duration.
See Also:
Date

toString

public String toString()
Return the duration in a string.

Overrides:
toString in class DayTimeDuration
Returns:
The formatted string.

getType

public int getType()
The type identifier of the value.

Specified by:
getType in interface Value
Overrides:
getType in class DayTimeDuration
Returns:
an identifier of the value type.

convertTo

public Value convertTo(int type)
                throws ClassCastException
Convert the value into the specified type. In case of identity conversion the value itself should be returned. If the conversion is not allowed a ClassCastException is thrown.

Specified by:
convertTo in interface Value
Overrides:
convertTo in class DayTimeDuration
Parameters:
type - The target type.
Returns:
The converted value.
Throws:
ClassCastException - if the conversion is impossible.

assign

public void assign(Value v)
Assign a new Value. An implicit conversion may be performed to make the assignment.

Specified by:
assign in interface Value
Overrides:
assign in class DayTimeDuration
Parameters:
v - the value to be assigned.

getPriority

public int getPriority()
The absolute priority of the value.

Specified by:
getPriority in interface Value
Overrides:
getPriority in class DayTimeDuration
Returns:
The value priority.

add

public Value add(Value x)
Compute an addition.

Specified by:
add in interface Sumable
Overrides:
add in class DayTimeDuration
Parameters:
x - another value.
Returns:
the sum of the two values.

unaryMinus

public Value unaryMinus()
Compute an unary minus.

Specified by:
unaryMinus in interface Arithmetic
Overrides:
unaryMinus in class DayTimeDuration
Returns:
The unary minus of the value.

sub

public Value sub(Value x)
Compute a substraction.

Specified by:
sub in interface Arithmetic
Overrides:
sub in class DayTimeDuration
Parameters:
x - another value.
Returns:
the difference between the two values.

multiply

public Value multiply(Value x)
Compute a multiplication.

Specified by:
multiply in interface Arithmetic
Overrides:
multiply in class DayTimeDuration
Parameters:
x - another value.
Returns:
the product of the two values.

divide

public Value divide(Value x)
Compute a division.

Specified by:
divide in interface Arithmetic
Overrides:
divide in class DayTimeDuration
Parameters:
x - another value.
Returns:
the ratio of the two values.

modulus

public Value modulus(Value x)
Compute a modulus.

Specified by:
modulus in interface Arithmetic
Overrides:
modulus in class DayTimeDuration
Parameters:
x - another value.
Returns:
the modulus of the values.

compareTo

public int compareTo(Value v)
Compare this value with another value.

Specified by:
compareTo in interface Comparison
Overrides:
compareTo in class DayTimeDuration
Parameters:
v - another value.
Returns:
The returned value is :
  • negative if this value is lower than another value
  • zero if the two values are equal
  • positive if this value is greater than another value

main

public static void main(String[] args)
Makes this class runnable for testing.

Parameters:
args - the given arguments in command line.

getItemType

public int getItemType()
A code that identifies the value items.

Specified by:
getItemType in interface DrbItem
Returns:
The code of value items.

getName

public String getName()
Name of the item. This method always returns null.

Specified by:
getName in interface DrbItem
Returns:
null

rename

public void rename(String name)
            throws NullPointerException,
                   UnsupportedOperationException
Changes the name of the item. This method always throw an UnsupportedOperationException.

Specified by:
rename in interface DrbItem
Parameters:
name - Reference to the new name.
Throws:
UnsupportedOperationException - This exception always raised because the name property is not defined for values.
NullPointerException - This exception is overriden by an UnsupportedOperationException.

getNamespaceURI

public String getNamespaceURI()
Get namespace URI. This method always returns null.

Specified by:
getNamespaceURI in interface DrbItem
Returns:
null.

setNamespaceURI

public void setNamespaceURI(String namespace_uri)
                     throws NullPointerException,
                            UnsupportedOperationException
Sets a namespace resource identifier. This method always throw an UnsupportedOperationException.

Specified by:
setNamespaceURI in interface DrbItem
Parameters:
namespace_uri - A reference to the new namespace identifier.
Throws:
UnsupportedOperationException - This exception always raised because the name property is not defined for values.
NullPointerException - This exception is overriden by an UnsupportedOperationException.

getValue

public Value getValue()
The value of the item. The value is expressed according to one of the types supported by the fr.gael.drb.value package. Generally these types correspond to primitive types (e.g. integer, floatting points, etc.) or very low level types (e.g. string, date, etc.). On the contrary to DOM implementation all the types are allowed even the arrays, date etc. Only the Value.NULL_ID type is forbidden.

Specified by:
getValue in interface DrbItem
Returns:
The value of the attribute.

setValue

public Value setValue(Value value)
               throws NullPointerException,
                      ClassCastException,
                      UnsupportedOperationException
Changes the value of the item. This operation sets a new value of the current item.The value type of the item shall be compatible with the item implementation. If the type does not match exactly it is casted to a compatible one based on the the fr.gael.drb.value capabilities. A reference to the effectivelly assigned value is returned by the operation so it is possible to check if a cast has been performed and therefore assess the accuracy of the assignement. If the cast is not possible the operation raises an UnsupportedOperationException. If the assignment is possible and the item implementation has a physical representation the value is updated in the physical source in order to persist among sessions. It therefore possible that this operation consumses an variable time.

Specified by:
setValue in interface DrbItem
Parameters:
value - The new value of the node. This value shall not be null.
Returns:
The effectivelly assigned value. The type of this value may differ from the input one.
Throws:
NullPointerException - This exception is raised when the passed reference to the value is null. This exception may be overriden by an UnsupportedOperationException.
ClassCastException - This exception is raised when the implementation has not succeeded to cast the input value in a type compatible with the current node.
UnsupportedOperationException - This exception is raised when the implementation does not support the requested assignment for any reason.

toNumeric

public Numeric toNumeric()
                  throws ClassCastException
Convert the value into the numeric type. In case of identity conversion the value itself should be returned. If the conversion is not allowed a ClassCastException is thrown.

Returns:
The converted value.
Throws:
ClassCastException - is the convertion is impossible

Data Request Broker - DRB API®
2-3-release

Copyright© 2001-2009 GAEL Consultant. All rights reserved. Use is subject to license terms .