Package org.apache.uima.internal.util
Class TimeSpan
- java.lang.Object
-
- org.apache.uima.internal.util.TimeSpan
-
public class TimeSpan extends java.lang.Object
Encode a span of time. The main purpose of this class is to provide a printing utility for time spans. E.g., 1081 ms should be printed as 1.081 s, 108101 ms should be printed as 1 min 48.101 s, etc.Note that the largest value you can represent with this class is 9223372036854775807 (
Long.MAX_VALUE
), or equivalently, 292471208 yrs 247 days 7 hrs 12 min 55.807 sec. Overflow is not handled gracefully by this class.Also note that for the purposes of this class, a year has 365 days. I.e., a year corresponds to
365 * 24 * 60 * 60 * 1000
ms.
-
-
Field Summary
Fields Modifier and Type Field Description private long
all
private int
days
private static java.lang.String
daysString
private int
hours
private static java.lang.String
hoursString
private boolean
knowsFull
private boolean
knowsMS
private int
milliseconds
private int
minutes
private static java.lang.String
minutesString
private static long
msDay
private static long
msHour
private static long
msMinute
private static long
msSecond
private static java.lang.String
msString
private static long
msYear
private int
seconds
private static java.lang.String
secondsString
private static java.lang.String
unknownTime
private int
years
private static java.lang.String
yearsString
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
ensureAll()
private void
ensureFull()
int
getDays()
Get the day fraction of this object.long
getFullMilliseconds()
Get the length of theTimeSpan
as milliseconds.int
getHours()
Get the hour fraction of this object.int
getMilliseconds()
Get the millisecond fraction of this object.int
getMinutes()
Get the minute fraction of this object.int
getSeconds()
Get the second fraction of this object.int
getYears()
Get the year fraction of this object.boolean
isInstantiated()
boolean
setDays(int days)
Set the day fraction of thisTimeSpan
.boolean
setFullMilliseconds(long milliseconds)
Set the fullTimeSpan
in terms of milliseconds.boolean
setHours(int hours)
Set the hour fraction of thisTimeSpan
.boolean
setMilliseconds(int milliseconds)
Set the millisecond fraction of thisTimeSpan
.boolean
setMinutes(int minutes)
Set the minute fraction of thisTimeSpan
.boolean
setSeconds(int seconds)
Set the second fraction of thisTimeSpan
.boolean
setYears(int years)
Set the year fraction of thisTimeSpan
.java.lang.String
toString()
-
-
-
Field Detail
-
all
private long all
-
years
private int years
-
days
private int days
-
hours
private int hours
-
minutes
private int minutes
-
seconds
private int seconds
-
milliseconds
private int milliseconds
-
knowsFull
private boolean knowsFull
-
knowsMS
private boolean knowsMS
-
msSecond
private static final long msSecond
- See Also:
- Constant Field Values
-
msMinute
private static final long msMinute
- See Also:
- Constant Field Values
-
msHour
private static final long msHour
- See Also:
- Constant Field Values
-
msDay
private static final long msDay
- See Also:
- Constant Field Values
-
msYear
private static final long msYear
- See Also:
- Constant Field Values
-
yearsString
private static final java.lang.String yearsString
- See Also:
- Constant Field Values
-
daysString
private static final java.lang.String daysString
- See Also:
- Constant Field Values
-
hoursString
private static final java.lang.String hoursString
- See Also:
- Constant Field Values
-
minutesString
private static final java.lang.String minutesString
- See Also:
- Constant Field Values
-
secondsString
private static final java.lang.String secondsString
- See Also:
- Constant Field Values
-
msString
private static final java.lang.String msString
- See Also:
- Constant Field Values
-
unknownTime
private static final java.lang.String unknownTime
- See Also:
- Constant Field Values
-
-
Method Detail
-
isInstantiated
public boolean isInstantiated()
- Returns:
true
, if the object has been instantiated with a legal interval;false
, else.
-
setYears
public boolean setYears(int years)
Set the year fraction of thisTimeSpan
.- Parameters:
years
- The number of years.- Returns:
false
, ifyears < 0
;true
, else.
-
setDays
public boolean setDays(int days)
Set the day fraction of thisTimeSpan
.- Parameters:
days
- The number of days.- Returns:
false
, ifdays < 0
;true
, else.
-
setHours
public boolean setHours(int hours)
Set the hour fraction of thisTimeSpan
.- Parameters:
hours
- The number of hours.- Returns:
false
, ifhours < 0
;true
, else.
-
setMinutes
public boolean setMinutes(int minutes)
Set the minute fraction of thisTimeSpan
.- Parameters:
minutes
- The number of minutes.- Returns:
false
, ifminutes < 0
;true
, else.
-
setSeconds
public boolean setSeconds(int seconds)
Set the second fraction of thisTimeSpan
.- Parameters:
seconds
- The number of seconds.- Returns:
false
, ifseconds < 0
;true
, else.
-
setMilliseconds
public boolean setMilliseconds(int milliseconds)
Set the millisecond fraction of thisTimeSpan
.- Parameters:
milliseconds
- The number of milliseconds.- Returns:
false
, ifmilliseconds < 0
;true
, else.
-
setFullMilliseconds
public boolean setFullMilliseconds(long milliseconds)
Set the fullTimeSpan
in terms of milliseconds.- Parameters:
milliseconds
- The number of milliseconds.- Returns:
false
, ifmilliseconds < 0
;true
, else.
-
getFullMilliseconds
public long getFullMilliseconds()
Get the length of theTimeSpan
as milliseconds.- Returns:
- The number of milliseconds, if known.
-1
, else (e.g., when theTimeSpan
is not instantiated).
-
getYears
public int getYears()
Get the year fraction of this object.- Returns:
-1
, if this object is not instantiated; the year fraction, else.
-
getDays
public int getDays()
Get the day fraction of this object.- Returns:
-1
, if this object is not instantiated; the day fraction, else.
-
getHours
public int getHours()
Get the hour fraction of this object.- Returns:
-1
, if this object is not instantiated; the hour fraction, else.
-
getMinutes
public int getMinutes()
Get the minute fraction of this object.- Returns:
-1
, if this object is not instantiated; the minute fraction, else.
-
getSeconds
public int getSeconds()
Get the second fraction of this object.- Returns:
-1
, if this object is not instantiated; the second fraction, else.
-
getMilliseconds
public int getMilliseconds()
Get the millisecond fraction of this object.- Returns:
-1
, if this object is not instantiated; the millisecond fraction, else.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
- Returns:
- String representation of object. See class comments.
-
ensureAll
private void ensureAll()
-
ensureFull
private void ensureFull()
-
-