org.jquantlib.time
Class Period
- java.lang.Object
-
- org.jquantlib.time.Period
-
- All Implemented Interfaces:
- java.lang.Cloneable
public class Period extends java.lang.Object implements java.lang.CloneableThis class provides aPeriod(length + TimeUnit) class and implements a limited algebra.
-
-
Field Summary
Fields Modifier and Type Field and Description static PeriodONE_DAY_BACKWARDConstant that can be used to represent one year period in the paststatic PeriodONE_DAY_FORWARDConstant that can be used to represent one year period forwardstatic PeriodONE_MONTH_BACKWARDConstant that can be used to represent one year period in the paststatic PeriodONE_MONTH_FORWARDConstant that can be used to represent one year period forwardstatic PeriodONE_YEAR_BACKWARDConstant that can be used to represent one year period in the paststatic PeriodONE_YEAR_FORWARDConstant that can be used to represent one year period forward
-
Constructor Summary
Constructors Constructor and Description Period()Default constructor.Period(Frequency f)To create a period by FrequencyPeriod(int length, TimeUnit units)To construct period representing the specified length and units
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description Periodadd(Period another)ReturnsthisPeriod addedanotherPeriodPeriodaddAssign(Period another)ReturnsthisPeriod added toanotherPerioddoubledays(Period p)Perioddiv(int scalar)ReturnsthisPeriod divided by a scalarPerioddivAssign(int scalar)ReturnsthisPeriod divided by a scalarbooleaneq(Period another)ComparesthistoanotherPeriodbooleanequals(java.lang.Object obj)Frequencyfrequency()To get at Frequency represented by the periodbooleange(Period another)ComparesthistoanotherPeriodjava.lang.StringgetLongFormat()Returns the name of period in long formatjava.lang.StringgetShortFormat()Returns the name of period in short format (3 letters)booleangt(Period another)ComparesthistoanotherPeriodinthashCode()booleanle(Period another)ComparesthistoanotherPeriodintlength()booleanlt(Period another)ComparesthistoanotherPerioddoublemonths(Period p)Periodmul(int scalar)ReturnsthisPeriod multiplied by a scalarPeriodnegative()booleanneq(Period another)ComparesthistoanotherPeriodvoidnormalize()Periodsub(Period another)ReturnsthisPeriod subtractedanotherPeriodPeriodsubAssign(Period another)ReturnsthisPeriod subtractedanotherPeriodjava.lang.StringtoString()TimeUnitunits()Time units represented by the perioddoubleweeks(Period p)doubleyears(Period p)
-
-
-
Field Detail
-
ONE_YEAR_FORWARD
public static final Period ONE_YEAR_FORWARD
Constant that can be used to represent one year period forward
-
ONE_YEAR_BACKWARD
public static final Period ONE_YEAR_BACKWARD
Constant that can be used to represent one year period in the past
-
ONE_MONTH_FORWARD
public static final Period ONE_MONTH_FORWARD
Constant that can be used to represent one year period forward
-
ONE_MONTH_BACKWARD
public static final Period ONE_MONTH_BACKWARD
Constant that can be used to represent one year period in the past
-
ONE_DAY_FORWARD
public static final Period ONE_DAY_FORWARD
Constant that can be used to represent one year period forward
-
ONE_DAY_BACKWARD
public static final Period ONE_DAY_BACKWARD
Constant that can be used to represent one year period in the past
-
-
Constructor Detail
-
Period
public Period()
Default constructor. Defaults to period of 0 days
-
Period
public Period(int length, TimeUnit units)To construct period representing the specified length and units- Parameters:
length-units-
-
Period
public Period(Frequency f)
To create a period by Frequency- Parameters:
f-
-
-
Method Detail
-
negative
public Period negative()
-
addAssign
public Period addAssign(Period another)
ReturnsthisPeriod added toanotherPeriod- Parameters:
another-- Returns:
- this
-
subAssign
public Period subAssign(Period another)
ReturnsthisPeriod subtractedanotherPeriod- Parameters:
another-- Returns:
- this
-
divAssign
public Period divAssign(int scalar)
ReturnsthisPeriod divided by a scalar- Parameters:
scalar-- Returns:
- this
-
mul
public Period mul(int scalar)
ReturnsthisPeriod multiplied by a scalar- Parameters:
scalar-- Returns:
- a new instance
-
add
public Period add(Period another)
ReturnsthisPeriod addedanotherPeriod- Parameters:
another-- Returns:
- a new instance
-
sub
public Period sub(Period another)
ReturnsthisPeriod subtractedanotherPeriod- Parameters:
another-- Returns:
- a new instance
-
div
public Period div(int scalar)
ReturnsthisPeriod divided by a scalar- Parameters:
another-- Returns:
- a new instance
-
eq
public boolean eq(Period another)
ComparesthistoanotherPeriod- Parameters:
another-- Returns:
trueifthisis equal toanother,falseotherwise
-
neq
public boolean neq(Period another)
ComparesthistoanotherPeriod- Parameters:
another-- Returns:
trueifthisis not equal toanother,falseotherwise
-
gt
public boolean gt(Period another)
ComparesthistoanotherPeriod- Parameters:
another-- Returns:
trueifthisis greater thananother,falseotherwise
-
le
public boolean le(Period another)
ComparesthistoanotherPeriod- Parameters:
another-- Returns:
trueifthisis less than or equal toanother,falseotherwise
-
ge
public boolean ge(Period another)
ComparesthistoanotherPeriod- Parameters:
another-- Returns:
trueifthisis greater or equal toanother,falseotherwise
-
lt
public boolean lt(Period another)
ComparesthistoanotherPeriod- Parameters:
another-- Returns:
trueifthisis less thananother,falseotherwise
-
length
public final int length()
- Returns:
- length of the period
-
units
public final TimeUnit units()
Time units represented by the period- Returns:
- time units of the period
-
frequency
public final Frequency frequency()
To get at Frequency represented by the period- Returns:
-
years
public double years(Period p)
-
months
public double months(Period p)
-
weeks
public double weeks(Period p)
-
days
public double days(Period p)
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
getLongFormat
public java.lang.String getLongFormat()
Returns the name of period in long format- Returns:
- the name of period in long format
-
getShortFormat
public java.lang.String getShortFormat()
Returns the name of period in short format (3 letters)- Returns:
- the name of period in short format (3 letters)
-
normalize
public void normalize()
-
-
DataMelt 3.0 © DataMelt by jWork.ORG