U - generic type of calendrical unitspublic abstract class SingleUnitTimeSpan<U extends IsoDateUnit,D extends SingleUnitTimeSpan<U,D>> extends Object implements TimeSpan<U>, Comparable<D>, Serializable
Represents a time span in one calendrical unit only.
TimeSpan.Item<U>| Modifier and Type | Method and Description |
|---|---|
D |
abs()
Yields a copy with the absolute amount.
|
<T extends TimePoint<? super U,T>> |
addTo(T time)
Adds this time span to given time point.
|
int |
compareTo(D other) |
boolean |
contains(IsoDateUnit unit)
Queries if given time unit is part of this time span.
|
boolean |
equals(Object obj) |
int |
getAmount()
Yields the count of units as integer-based amount.
|
long |
getPartialAmount(IsoDateUnit unit)
Yields the partial amount associated with given time unit.
|
List<TimeSpan.Item<U>> |
getTotalLength()
Yields all containted time span items with amount and unit in
the order from largest to smallest time units.
|
U |
getUnit()
Yields the associated unit.
|
int |
hashCode() |
D |
inverse()
Yields a copy with the negated amount.
|
boolean |
isEmpty()
Queries if this time span is empty.
|
boolean |
isNegative()
Queries if this time span is negative.
|
boolean |
isPositive()
Queries if this time span is positive.
|
D |
minus(D duration)
Yields a copy with the subtracted duration.
|
D |
minus(int amount)
Yields a copy with the subtracted amount.
|
D |
multipliedBy(int factor)
Yields a copy with the multiplied amount.
|
D |
plus(D duration)
Yields a copy with the added duration.
|
D |
plus(int amount)
Yields a copy with the added amount.
|
<T extends TimePoint<? super U,T>> |
subtractFrom(T time)
Subtracts this time span from given time point.
|
Duration<U> |
toStdDuration()
Converts this instance to a general duration with the same amount and unit.
|
String |
toString()
Prints in ISO-8601-format "PnU" (n=amount, U=unit).
|
String |
toString(Locale locale,
TextWidth width)
Prints this duration in a localized way with given text width.
|
public int getAmount()
Yields the count of units as integer-based amount.
public U getUnit()
Yields the associated unit.
public int compareTo(D other)
compareTo in interface Comparable<D extends SingleUnitTimeSpan<U,D>>public List<TimeSpan.Item<U>> getTotalLength()
TimeSpanYields all containted time span items with amount and unit in the order from largest to smallest time units.
getTotalLength in interface TimeSpan<U extends IsoDateUnit>public boolean contains(IsoDateUnit unit)
TimeSpanQueries if given time unit is part of this time span.
By default the implementation uses following expression:
for (Item<?> item : getTotalLength()) {
if (item.getUnit().equals(unit)) {
return (item.getAmount() > 0);
}
}
return false;
contains in interface TimeSpan<U extends IsoDateUnit>unit - time unit to be asked (optional)true if exists else falsegetPartialAmount(U)public long getPartialAmount(IsoDateUnit unit)
TimeSpanYields the partial amount associated with given time unit.
The method returns 0 if this time span does not contain
given time unit. In order to get the total length/amount of this
time span users have to evaluate the method TimeSpan.getTotalLength()
instead.
getPartialAmount in interface TimeSpan<U extends IsoDateUnit>unit - time unit (optional)>= 0)public boolean isNegative()
TimeSpanQueries if this time span is negative.
A negative time span relates to the subtraction of two time points where first one is after second one. The partial amounts of every time span are never negative. Hence this attribute is not associated with the partial amounts but only with the time span itself.
Note: An empty time span itself is never negative in agreement
with the mathematical relation (-1) * 0 = 0.
isNegative in interface TimeSpan<U extends IsoDateUnit>true if negative and not empty else falsepublic boolean isPositive()
TimeSpanQueries if this time span is positive.
A time span is positive if it is neither empty nor negative.
isPositive in interface TimeSpan<U extends IsoDateUnit>true if positive and not empty else falseTimeSpan.isEmpty(),
TimeSpan.isNegative()public boolean isEmpty()
TimeSpanQueries if this time span is empty.
Per definition an empty time span has no items with a partial
amount different from 0.
isEmpty in interface TimeSpan<U extends IsoDateUnit>true if empty else falsepublic <T extends TimePoint<? super U,T>> T addTo(T time)
TimeSpanAdds this time span to given time point.
Is equivalent to the expression time.plus(this). Due to better readability usage of the
TimePoint-method is recommended. Implementations are
required to document the used algorithm in detailed manner.
addTo in interface TimeSpan<U extends IsoDateUnit>T - generic type of time pointtime - reference time point to add this time span toTimeSpan.subtractFrom(TimePoint)public <T extends TimePoint<? super U,T>> T subtractFrom(T time)
TimeSpanSubtracts this time span from given time point.
Is equivalent to the expression time.minus(this). Due to better readability usage of the
TimePoint-method is recommended. Implementations are
required to document the used algorithm in detailed manner.
subtractFrom in interface TimeSpan<U extends IsoDateUnit>T - generic type of time pointtime - reference time point to subtract this time span fromTimeSpan.addTo(TimePoint)public String toString()
Prints in ISO-8601-format "PnU" (n=amount, U=unit).
Negative durations will get a preceding sign before "P". Note that gregorian and week-based years have the same representation using the symbol Y.
public String toString(Locale locale, TextWidth width)
Prints this duration in a localized way with given text width.
locale - the locale to be appliedwidth - the text width to be appliedpublic D abs()
Yields a copy with the absolute amount.
ArithmeticException - if numeric overflow occurs (only in case of Integer.MIN_VALUE)public D inverse()
Yields a copy with the negated amount.
ArithmeticException - if numeric overflow occurs (only in case of Integer.MIN_VALUE)public D plus(int amount)
Yields a copy with the added amount.
amount - the amount to be addedArithmeticException - if numeric overflow occurspublic D plus(D duration)
Yields a copy with the added duration.
duration - the duration to be addedArithmeticException - if numeric overflow occurspublic D minus(int amount)
Yields a copy with the subtracted amount.
amount - the amount to be subtractedArithmeticException - if numeric overflow occurspublic D minus(D duration)
Yields a copy with the subtracted duration.
duration - the duration to be addedArithmeticException - if numeric overflow occurspublic D multipliedBy(int factor)
Yields a copy with the multiplied amount.
factor - multiplication factor to be appliedArithmeticException - if numeric overflow occursCopyright © 2014–2021. All rights reserved.