net.sf.fikin.pojostate.format
Class Duration

java.lang.Object
  extended by net.sf.fikin.pojostate.format.Duration
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.lang.Comparable

public class Duration
extends java.lang.Object
implements java.io.Serializable, java.lang.Comparable, java.lang.Cloneable

Duration data type object represented as long value of milliseconds. The Duration class wraps a value of the primitive type long in an object. An object of type Duration contains a single field whose type is long. created on Jul 19, 2005

Since:
Version:
$Revision: 1.2 $
Author:
fiykov
See Also:
Serialized Form

Constructor Summary
Duration(long milliseconds)
          Constructs a newly allocated Duration object that represents the specified long argument.
Duration(java.lang.String milliseconds)
          Constructs a newly allocated Duration object that represents the long value indicated by the String parameter.
 
Method Summary
 int compareTo(Duration anotherDuration)
          Compares two Duration objects numerically.
 int compareTo(java.lang.Object o)
          Compares this Duration object to another object.
 int getDays()
           
 int getHours()
           
 int getMilliseconds()
           
 int getMinutes()
           
 int getSeconds()
           
 int getTotalDays()
           
 int getTotalHours()
           
 long getTotalMilliseconds()
           
 long getTotalMinutes()
           
 long getTotalSeconds()
           
 int getWeeks()
           
 long longValue()
          Returns the value of this Duration as a long value representing milliseconds.
static long parseDuration(java.lang.String milliseconds)
          Parses the string argument as a signed decimal long.
 java.lang.String toString()
          Returns a String object representing this Duration's value.
static java.lang.String toString(long milliseconds)
          Returns a String object representing the specified long.
static Duration valueOf(java.lang.String milliseconds)
          Returns a Duration object holding the value of the specified String.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Duration

public Duration(long milliseconds)
Constructs a newly allocated Duration object that represents the specified long argument.

Parameters:
milliseconds - the value to be represented by the Duration object.

Duration

public Duration(java.lang.String milliseconds)
         throws java.lang.NumberFormatException
Constructs a newly allocated Duration object that represents the long value indicated by the String parameter. The string is converted to a long value in exactly the manner used by the parseDuration method for radix 10.

Parameters:
milliseconds - is duration in milliseconds to be assigned to this Duration object.
Throws:
java.lang.NumberFormatException - if the String does not contain a parsable long.
See Also:
parseDuration(String)
Method Detail

getMilliseconds

public int getMilliseconds()

getSeconds

public int getSeconds()

getMinutes

public int getMinutes()

getHours

public int getHours()

getDays

public int getDays()

getWeeks

public int getWeeks()

getTotalDays

public int getTotalDays()

getTotalHours

public int getTotalHours()

getTotalMinutes

public long getTotalMinutes()

getTotalSeconds

public long getTotalSeconds()

getTotalMilliseconds

public long getTotalMilliseconds()

longValue

public long longValue()
Returns the value of this Duration as a long value representing milliseconds.


compareTo

public int compareTo(Duration anotherDuration)
Compares two Duration objects numerically.

Parameters:
anotherDuration - the Duration to be compared.
Returns:
the value 0 if this Duration is equal to the argument Duration; a value less than 0 if this Duration is numerically less than the argument Duration; and a value greater than 0 if this Duration is numerically greater than the argument Duration (signed comparison).

compareTo

public int compareTo(java.lang.Object o)
Compares this Duration object to another object. If the object is a Duration, this function behaves like compareTo(Duration). Otherwise, it throws a ClassCastException (as Duration objects are comparable only to other Duration objects).

Specified by:
compareTo in interface java.lang.Comparable
Parameters:
o - the Object to be compared.
Returns:
the value 0 if the argument is a Duration numerically equal to this Duration; a value less than 0 if the argument is a Duration numerically greater than this Duration; and a value greater than 0 if the argument is a Duration numerically less than this Duration.
Throws:
ClassCastException - if the argument is not a Duration.
See Also:
Comparable

toString

public java.lang.String toString()
Returns a String object representing this Duration's value. The value is converted to signed decimal representation and returned as a string, exactly as if the long value were given as an argument to the toString(long) method.

Overrides:
toString in class java.lang.Object
Returns:
a string representation of the value of this object in base 10.

valueOf

public static Duration valueOf(java.lang.String milliseconds)
Returns a Duration object holding the value of the specified String. The argument is interpreted as representing a signed decimal long, exactly as if the argument were given to the parseDuration(java.lang.String) method. The result is a Duration object that represents the integer value specified by the string.

In other words, this method returns a Duration object equal to the value of:

 new Duration(Duration.parseDuration(s))
 

Parameters:
milliseconds - the string to be parsed.
Returns:
a Duration object holding the value represented by the string argument.
Throws:
java.lang.NumberFormatException - If the string cannot be parsed as a long.

toString

public static java.lang.String toString(long milliseconds)
Returns a String object representing the specified long. The argument is converted to signed decimal representation and returned as a string, exactly as if the argument and the radix 10 were given as arguments to the toString(long) method.

Parameters:
milliseconds - is duration in milliseconds to be converted.
Returns:
a string representation of the argument in "base 10".

parseDuration

public static long parseDuration(java.lang.String milliseconds)
                          throws java.lang.NumberFormatException
Parses the string argument as a signed decimal long.

The characters in the string must all be decimal digits, except that the first character may be an ASCII minus sign '-' (\u002D') to indicate a negative value. The resulting long value is returned, exactly as if the argument and the radix 10 were given as arguments to the parseDuration(String) method.

Note that neither the character L ('\u004C') nor l ('\u006C') is permitted to appear at the end of the string as a type indicator, as would be permitted in Java programming language source code.

Parameters:
milliseconds - is duration in milliseconds
Returns:
the long representing the argument in string.
Throws:
java.lang.NumberFormatException - if the string does not contain a parsable long.


Copyright © 2005 Nikolay Fiykov. All Rights Reserved.