Package org.apache.uima.internal.util
Class TimeSpan
java.lang.Object
org.apache.uima.internal.util.TimeSpan
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
FieldsModifier and TypeFieldDescriptionprivate long
private int
private static final String
private int
private static final String
private boolean
private boolean
private int
private int
private static final String
private static final long
private static final long
private static final long
private static final long
private static final String
private static final long
private int
private static final String
private static final String
private int
private static final String
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate void
private void
int
getDays()
Get the day fraction of this object.long
Get the length of theTimeSpan
as milliseconds.int
getHours()
Get the hour fraction of this object.int
Get the millisecond fraction of this object.int
Get the minute fraction of this object.int
Get the second fraction of this object.int
getYears()
Get the year fraction of this object.boolean
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
.toString()
-
Field Details
-
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:
-
msMinute
private static final long msMinute- See Also:
-
msHour
private static final long msHour- See Also:
-
msDay
private static final long msDay- See Also:
-
msYear
private static final long msYear- See Also:
-
yearsString
- See Also:
-
daysString
- See Also:
-
hoursString
- See Also:
-
minutesString
- See Also:
-
secondsString
- See Also:
-
msString
- See Also:
-
unknownTime
- See Also:
-
-
Constructor Details
-
TimeSpan
public TimeSpan()Create an uninstantiatedTimeSpan
. -
TimeSpan
public TimeSpan(long milliseconds) Create aTimeSpan
from a ms interval.- Parameters:
milliseconds
- The interval in ms. Ifmilliseconds < 0
, an uninstantiatedTimeSpan
is created.
-
-
Method Details
-
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
-
ensureAll
private void ensureAll() -
ensureFull
private void ensureFull()
-