public class Interval extends Object
| Modifier and Type | Field and Description |
|---|---|
static Interval |
DEFAULT_SPAN |
static int |
UNIT_DAY
Unit for Days
|
static int |
UNIT_HOUR
Unit for Hours
|
static int |
UNIT_MINUTE
Unit for Minutes
|
static int |
UNIT_MONTH
Unit for Months
|
static int |
UNIT_SECOND
Unit for Seconds
|
static int |
UNIT_WEEK
Unit for Weeks
|
static int |
UNIT_YEAR
Unit for Years
|
static Interval |
ZERO_INTERVAL
A Zero interval
|
static Interval |
ZERO_SECONDS |
| Constructor and Description |
|---|
Interval(BigDecimal magnitude,
int unit)
Create an interval from a magnitude and a unit.
|
Interval(double magnitude,
int unit)
Create an interval from a magnitude and a unit.
|
Interval(long magnitude,
int unit)
Create an interval from a magnitude and a unit.
|
Interval(String timeDescription)
Create an interval from a string description.
|
Interval(String timeDescription,
int defaultUnit)
Constructor for an Interval that takes a default time unit.
|
| Modifier and Type | Method and Description |
|---|---|
Interval |
add(Interval rhs)
Add the given interval to this interval producing a new interval.
|
int |
compareTo(Interval rhs)
Compare two intervals - This will normalize the intervals to the same base unit and
compare them
|
boolean |
equals(Object rhs)
Check this interval for equality to another object.
|
BigDecimal |
getMagnitude()
Get the magnitude of this interval
|
int |
getUnit()
Get the unit for this interval.
|
long |
getValueInMillis() |
BigDecimal |
getValueInUnits(int desiredUnit)
Get the magnitude of this interval in the given unit.
|
int |
hashCode()
Generate the hash code for this interval
|
int |
signum()
Indicate the sign of the Interval' magnitude component
|
Interval |
subtract(Interval rhs)
Subtract the given interval from this interval to produce a new interval.
|
String |
toIntString(int desiredUnit) |
String |
toSensibleString()
Convert to an string representation, choosing a sensible
unit depending on the value of the interval
|
String |
toString()
Convert this interval to its string representation.
|
String |
toString(int desiredUnit)
Convert the interval to a string in the given unit
|
public static final int UNIT_SECOND
public static final int UNIT_MINUTE
public static final int UNIT_HOUR
public static final int UNIT_DAY
public static final int UNIT_WEEK
public static final int UNIT_MONTH
public static final int UNIT_YEAR
public static final Interval ZERO_SECONDS
public static final Interval DEFAULT_SPAN
public static final Interval ZERO_INTERVAL
public Interval(BigDecimal magnitude, int unit)
magnitude - the interval's desired magnitude.unit - the desired unit for this interval.public Interval(long magnitude,
int unit)
magnitude - the interval's desired magnitude.unit - the desired unit for this interval.public Interval(double magnitude,
int unit)
magnitude - the interval's desired magnitude.unit - the desired unit for this interval.public Interval(String timeDescription, int defaultUnit)
timeDescription - a string rep of the time intervaldefaultUnit - the unit to default to if timeDescription
contains no unitNumberFormatException - if not a valid timepublic Interval(String timeDescription)
timeDescription - The interval description consisting of a number, the magnitude
of the interval, and a word describing the unit.NumberFormatException - if not a valid timepublic BigDecimal getValueInUnits(int desiredUnit)
desiredUnit - the unit in which the interval's magnitude is desired.public long getValueInMillis()
public String toString(int desiredUnit)
desiredUnit - the unit in which the intervale is to be expressed.public String toIntString(int desiredUnit)
public String toString()
toString in class ObjectObject.toString()public String toSensibleString()
public int getUnit()
public BigDecimal getMagnitude()
public int compareTo(Interval rhs)
rhs - the interval to be compared to this onepublic boolean equals(Object rhs)
equals in class ObjectObject.equals(java.lang.Object)public int hashCode()
hashCode in class ObjectObject.hashCode()public Interval subtract(Interval rhs)
rhs - the interval to be subracted from this interval.public Interval add(Interval rhs)
rhs - the Right Hand Side of the addtionpublic int signum()
Copyright © 2024 OpenClover.org. All rights reserved.