Interface ProportionalElement<V extends Number,T>
- Type Parameters:
V
- generic number type of element valuesT
- generic type of target entity an operator is applied to
- All Superinterfaces:
AdjustableElement<V,T>
,ChronoElement<V>
,Comparator<ChronoDisplay>
,ZonalElement<V>
Defines an element which can interprete its value as proportional value.
- Author:
- Meno Hochschild
-
Method Summary
Modifier and TypeMethodDescriptionratio()
Defines a query which interpretes the value of this element as proportional rational number within the range between minimum and maximum.roundedDown(int stepwidth)
Rounds this chronological element down and makes its numerical value an integral multiple of given step width if possible.roundedHalf(int stepwidth)
Rounds this chronological element up or down and makes its numerical value an integral multiple of given step width if possible.roundedUp(int stepwidth)
Rounds this chronological element up and makes its numerical value an integral multiple of given step width if possible.setLenient(V value)
Adjusts any kind of entity such that this element will be set to the given value in lenient mode.Methods inherited from interface net.time4j.AdjustableElement
atCeiling, atCeiling, atFloor, atFloor, decremented, incremented, maximized, minimized, newValue
Methods inherited from interface net.time4j.engine.ChronoElement
compare, getDefaultMaximum, getDefaultMinimum, getDisplayName, getSymbol, getType, isDateElement, isLenient, isTimeElement, name
Methods inherited from interface java.util.Comparator
equals, reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
Methods inherited from interface net.time4j.ZonalElement
at, atUTC, in, inStdTimezone, inTimezone
-
Method Details
-
ratio
ChronoFunction<ChronoEntity<?>,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.
- Returns:
- query for proportional value
-
setLenient
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 anArithmeticException
. Furthermore, moving the value ofSECOND_OF_MINUTE
to the past applied on aMoment
can trigger aChronoException
if this action changes to the pre-UTC-era before 1972.- Parameters:
value
- new value to be set in lenient way- Returns:
- operator directly applicable also on
PlainTimestamp
-
roundedUp
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)
- Parameters:
stepwidth
- controls the limits within the rounding will occur- Returns:
- rounding operator in ceiling mode
- See Also:
roundedDown(int)
-
roundedHalf
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.
- Parameters:
stepwidth
- controls the limits within the rounding will occur- Returns:
- rounding operator in ceiling or floor mode dependent on actual element value
- See Also:
roundedUp(int)
,roundedDown(int)
-
roundedDown
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
- Parameters:
stepwidth
- controls the limits within the rounding will occur- Returns:
- rounding operator in floor mode
- See Also:
roundedUp(int)
-