V - generic number type of element valuesT - generic type of target entity an operator is applied topublic interface ProportionalElement<V extends java.lang.Number,T> extends AdjustableElement<V,T>
Defines an element which can interprete its value as proportional value.
| Modifier and Type | Method and Description |
|---|---|
ChronoFunction<ChronoEntity<?>,java.math.BigDecimal> |
ratio()
Defines a query which interpretes the value of this element as
proportional rational number within the range between minimum and
maximum.
|
ChronoOperator<T> |
roundedDown(int stepwidth)
Rounds this chronological element down and makes its numerical
value an integral multiple of given step width if possible.
|
ChronoOperator<T> |
roundedHalf(int stepwidth)
Rounds this chronological element up or down and makes its
numerical value an integral multiple of given step width if
possible.
|
ChronoOperator<T> |
roundedUp(int stepwidth)
Rounds this chronological element up and makes its numerical
value an integral multiple of given step width if possible.
|
ElementOperator<T> |
setLenient(V value)
Adjusts any kind of entity such that this element will be set to
the given value in lenient mode.
|
atCeiling, atFloor, decremented, incremented, maximized, minimized, newValueat, atUTC, in, inStdTimezone, inTimezonecompare, getDefaultMaximum, getDefaultMinimum, getSymbol, getType, isDateElement, isLenient, isTimeElement, nameChronoFunction<ChronoEntity<?>,java.math.BigDecimal> ratio()
Defines a query which interpretes the value of this element as proportional rational number within the range between minimum and maximum.
Smaller elements with greater precision are not taken in account.
Following expression serves as formula for internal calculation:
(value - min) / (max - min + 1). Example:
import static net.time4j.PlainTime.MINUTE_OF_HOUR; PlainTime time = PlainTime.of(12, 45, 30); // T12:45:30 System.out.println(time.get(MINUTE_OF_HOUR.ratio())); // output: 0.75 [= (45 - 0) / (59 - 0 + 1)]
Note: In timezone-related timestamps possible jumps in local time will be conserved. That means that minimum and maximum do not take in account if they fall into a daylight saving gap or if there is any kind of offset shift between them.
ElementOperator<T> setLenient(V value)
Adjusts any kind of entity such that this element will be set to the given value in lenient mode.
import static net.time4j.PlainDate.MONTH_OF_YEAR;
System.out.println(
PlainDate.of(2011, 5, 31).with(MONTH_OF_YEAR.setLenient(13)));
// output: 2012-01-31 (addition of 13 - 5 = 8 Monaten)
Leniency does not always prevent exceptions. For example setting
of extreme values like Long.MIN_VALUE can cause an
ArithmeticException. Furthermore, moving the value of
SECOND_OF_MINUTE to the past applied on a Moment
can trigger a ChronoException if this action changes to
the pre-UTC-era before 1972.
value - new value to be set in lenient wayPlainTimestampChronoOperator<T> roundedUp(int stepwidth)
Rounds this chronological element up and makes its numerical value an integral multiple of given step width if possible.
import static net.time4j.PlainTime.MINUTE_OF_HOUR;
System.out.println(
PlainTime.of(18, 38).with(MINUTE_OF_HOUR.roundedUp(15)));
// output: T18:45
The new element value will always be set in lenient mode. Example:
import static net.time4j.PlainTime.MINUTE_OF_HOUR;
System.out.println(
PlainTime.of(18, 49).with(MINUTE_OF_HOUR.roundedUp(15)));
// output: T19 corresponding to T18:60 (60 as multiple of 15)
stepwidth - controls the limits within the rounding will occurroundedDown(int)ChronoOperator<T> roundedHalf(int stepwidth)
Rounds this chronological element up or down and makes its numerical value an integral multiple of given step width if possible.
import static net.time4j.PlainTime.MINUTE_OF_HOUR;
System.out.println(
PlainTime.of(18, 38).with(MINUTE_OF_HOUR.roundedHalf(15)));
// output: T18:45
System.out.println(
PlainTime.of(18, 37).with(MINUTE_OF_HOUR.roundedHalf(15)));
// output: T18:30
The new element value will always be set in lenient mode. Is the current value nearer to the lower limit then this function will round down else round up.
stepwidth - controls the limits within the rounding will occurroundedUp(int),
roundedDown(int)ChronoOperator<T> roundedDown(int stepwidth)
Rounds this chronological element down and makes its numerical value an integral multiple of given step width if possible.
import static net.time4j.PlainTime.MINUTE_OF_HOUR;
System.out.println(
PlainTime.of(18, 38).with(MINUTE_OF_HOUR.roundedDown(15)));
// output: T18:30
The new element value will always be set in lenient mode. Example:
import static net.time4j.PlainTime.CLOCK_HOUR_OF_DAY;
System.out.println(
PlainTime.of(2, 30).with(CLOCK_HOUR_OF_DAY.roundedDown(3)));
// output: T0
stepwidth - controls the limits within the rounding will occurroundedUp(int)