jimmc.util
Class Duration

java.lang.Object
  |
  +--jimmc.util.Duration
All Implemented Interfaces:
java.io.Serializable

public class Duration
extends java.lang.Object
implements java.io.Serializable

A Duration is an elapsed time measured in seconds.

See Also:
Serialized Form

Field Summary
protected  java.math.BigDecimal duration
          Our value.
protected  int fractionPrecision
          The number of fractional digits to display.
 
Constructor Summary
Duration(double duration)
          Create a Duration from a double.
Duration(int duration)
          Create a Duration from an int.
Duration(java.lang.Number num)
          Create a Duration from any kind of Number.
 
Method Summary
 float floatValue()
          Get the value of this duration as a float.
 double fractionalValue()
          Get the fractional part of our duration.
 int getFractionPrecision()
          Get the number of fractional digits to display.
 int intValue()
          Get the value of this duration as an int.
static double parseDoubleDuration(java.lang.String s)
          Parse a string into a double-valued duration.
protected static double parseFraction(java.lang.String s)
          Parse a fractional number.
static int parseIntDuration(java.lang.String s)
          Parse a string into an integer-valued duration.
 void setFractionPrecision(int digits)
          Set the number of fractional digits to display.
 java.lang.String toString()
          Convert to a string.
static java.lang.String toString(int seconds)
          Convert seconds to a Duration string.
protected static void toString(java.lang.StringBuffer sb, int seconds)
          Convert seconds to string in a buffer.
static Duration valueOf(java.lang.String s)
          Return a new Duration initialized to the value of the specified String.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

duration

protected java.math.BigDecimal duration
Our value.

fractionPrecision

protected int fractionPrecision
The number of fractional digits to display.
Constructor Detail

Duration

public Duration(int duration)
Create a Duration from an int. The fractionPrecision is set to 0.

Duration

public Duration(double duration)
Create a Duration from a double. The fractionPrecision is set to 2.

Duration

public Duration(java.lang.Number num)
Create a Duration from any kind of Number. If the number is a Float, Double, or BigDecimal, the fractionPrecision is set to 2; otherwise, it is set to 0.
Method Detail

setFractionPrecision

public void setFractionPrecision(int digits)
Set the number of fractional digits to display.

getFractionPrecision

public int getFractionPrecision()
Get the number of fractional digits to display.

intValue

public int intValue()
Get the value of this duration as an int.

floatValue

public float floatValue()
Get the value of this duration as a float.

fractionalValue

public double fractionalValue()
Get the fractional part of our duration.

toString

public java.lang.String toString()
Convert to a string.
Overrides:
toString in class java.lang.Object

toString

public static java.lang.String toString(int seconds)
Convert seconds to a Duration string.

toString

protected static void toString(java.lang.StringBuffer sb,
                               int seconds)
Convert seconds to string in a buffer.

parseIntDuration

public static int parseIntDuration(java.lang.String s)
Parse a string into an integer-valued duration.
Returns:
The number of seconds in the duration.

parseDoubleDuration

public static double parseDoubleDuration(java.lang.String s)
Parse a string into a double-valued duration.
Returns:
The number of seconds in the duration.

parseFraction

protected static double parseFraction(java.lang.String s)
Parse a fractional number.
Parameters:
s - The fractional part, starting with the digit just after the decimal point. Digits only.
Returns:
The fractional part, between 0 inclusive and 1 exclusive.

valueOf

public static Duration valueOf(java.lang.String s)
Return a new Duration initialized to the value of the specified String.