com.jstatcom.util
Class Maturity
- java.lang.Object
-
- com.jstatcom.util.Maturity
-
- All Implemented Interfaces:
- java.io.Serializable
public final class Maturity extends java.lang.Object implements java.io.SerializableImmutable representation of a maturity. This class is needed by financial tools. Instances can be created via the constructor or withvalueOffrom a string.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field and Description intCOUNTThe number of the time units.MaturityUnitsUNITTime unit (day, month, year).
-
Constructor Summary
Constructors Constructor and Description Maturity(int count, MaturityUnits unit)Creates a maturity instance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description booleanequals(java.lang.Object o)Overridesequalsto provide logical comparison of two differentMaturityobjects.inthashCode()OverrideshashCode, because equals was overwritten.java.lang.StringtoString()static MaturityvalueOf(java.lang.String toParse)Creates a maturity from a string representation.
-
-
-
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 unitsunit- time unit- Throws:
java.lang.IllegalArgumentException-if (unit == null)orif (count < 0)
-
-
Method Detail
-
valueOf
public static Maturity valueOf(java.lang.String toParse)
Creates a maturity from a string representation. The general format isx[-,' ']?[DAYS, MONTHS, YEARS], wherexis anint. Examples are:- "30 d", "30 days", "30 day", "2d", "6-d"
- "6 m", "6 month", "6 months", "2m", "6-months"
- "3 y", "3 year", "3 years", "2y", "6-year"
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()
OverrideshashCode, because equals was overwritten. The algorithm was taken from (Joshua Bloch, "Effective Java", Item 8) .- Overrides:
hashCodein classjava.lang.Object- Returns:
- hash code
-
equals
public boolean equals(java.lang.Object o)
Overridesequalsto provide logical comparison of two differentMaturityobjects.- Overrides:
equalsin classjava.lang.Object- Parameters:
o- object to compare with- Returns:
trueifCOUNTandUNITare the same,falseotherwise
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-
DMelt 3.0 © DataMelt by jWork.ORG