com.jstatcom.util
Class Maturity

java.lang.Object
  extended by com.jstatcom.util.Maturity
All Implemented Interfaces:
java.io.Serializable

public final class Maturity
extends java.lang.Object
implements java.io.Serializable

Immutable representation of a maturity. This class is needed by financial tools. Instances can be created via the constructor or with valueOf from a string.

Author:
Markus Kraetzig
See Also:
Serialized Form

Field Summary
 int COUNT
          The number of the time units.
 MaturityUnits UNIT
          Time unit (day, month, year).
 
Constructor Summary
Maturity(int count, MaturityUnits unit)
          Creates a maturity instance.
 
Method Summary
 boolean equals(java.lang.Object o)
          Overrides equals to provide logical comparison of two different Maturity objects.
 int hashCode()
          Overrides hashCode, because equals was overwritten.
 java.lang.String toString()
           
static Maturity valueOf(java.lang.String toParse)
          Creates a maturity from a string representation.
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

COUNT

public final int COUNT
The number of the time units.


UNIT

public final MaturityUnits UNIT
Time unit (day, month, year).

Constructor Detail

Maturity

public Maturity(int count,
                MaturityUnits unit)
Creates a maturity instance.

Parameters:
count - number of time units
unit - time unit
Throws:
java.lang.IllegalArgumentException - if (unit == null) or if (count < 0)
Method Detail

valueOf

public static Maturity valueOf(java.lang.String toParse)
Creates a maturity from a string representation. The general format is x[-,' ']?[DAYS, MONTHS, YEARS], where x is an int. Examples are:

As can be seen, days, months, and years can be parsed from either a single character or the full name.

Parameters:
toParse -
Returns:
maturity instance

hashCode

public int hashCode()
Overrides hashCode, because equals was overwritten. The algorithm was taken from (Joshua Bloch, "Effective Java", Item 8) .

Overrides:
hashCode in class java.lang.Object
Returns:
hash code

equals

public boolean equals(java.lang.Object o)
Overrides equals to provide logical comparison of two different Maturity objects.

Overrides:
equals in class java.lang.Object
Parameters:
o - object to compare with
Returns:
true if COUNT and UNIT are the same, false otherwise

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object