@SuppressWarnings( "unchecked" ) @Override public <R extends Temporal> R adjustInto( R temporal, long newValue ) { int newVal = range.checkValidIntValue( newValue, this ); int oldYear = temporal.get( ChronoField.YEAR ); return (R) temporal.with( ChronoField.YEAR, (oldYear / years) * years + newVal ) .with( TemporalAdjusters.firstDayOfYear() ); }
@Override @SuppressWarnings( "unchecked" ) public final V with( TemporalField field, long newValue ) { return replacement( (T) temporal().with( field, newValue ) ); }
@Override @SuppressWarnings( "unchecked" ) public final V with( TemporalAdjuster adjuster ) { return replacement( (T) temporal().with( adjuster ) ); }
result = (Temp) result.with( IsoFields.WEEK_BASED_YEAR, safeCastIntegral( f.name(), entry.getValue(), f.defaultValue ) ); .with( temporalField, safeCastIntegral( f.name(), entry.getValue(), f.defaultValue ) ); fields.containsKey( TemporalFields.microsecond ) || fields.containsKey( TemporalFields.nanosecond )) ) result = (Temp) result.with( TemporalFields.nanosecond.field, validNano( fields.get( TemporalFields.millisecond ), fields.get( TemporalFields.microsecond ), fields.get( TemporalFields.nanosecond ) ) );
TEMP newTemporal = (TEMP) temporal.with( ChronoField.NANO_OF_SECOND, newNanos ); MapValue filtered = fields.filter( ( k, ignore ) -> !k.equals( "microsecond" ) && !k.equals( "nanosecond" ) ); AnyValue nanos = fields.get( "nanosecond" ); int newNanos = validNano( null, micros, nanos ); TEMP newTemporal = (TEMP) temporal.with( ChronoField.NANO_OF_SECOND, newNanos ); MapValue filtered = fields.filter( ( k, ignore ) -> !k.equals( "nanosecond" ) );
@Nullable Temporal isOk(Temporal t) { if (checker.matches(t)) { return null; } Temporal out = t.plus(1, type.getBaseUnit()); // Fall-through switch case. for example if type is year all cases below must also be handled. switch (type) { case YEAR: out = out.with(ChronoField.MONTH_OF_YEAR, 1); case MONTH_OF_YEAR: out = out.with(ChronoField.DAY_OF_MONTH, 1); case DAY_OF_WEEK: case DAY_OF_MONTH: out = out.with(ChronoField.HOUR_OF_DAY, 0); case HOUR_OF_DAY: out = out.with(ChronoField.MINUTE_OF_HOUR, 0); case MINUTE_OF_HOUR: out = out.with(ChronoField.SECOND_OF_MINUTE, 0); case SECOND_OF_MINUTE: return out; default: throw new IllegalArgumentException("Invalid field type " + type); } }
@Override public Temporal adjustInto(Temporal temporal) { Temporal result = temporal; for(TemporalAdjuster adjuster: copyOf) { result = result.with(adjuster); } return result; } };
@SuppressWarnings("unchecked") public <T extends Temporal> T adjustInto(final T temporal) { if (temporal instanceof CalendarDate) { return (T) this; } else { final long seconds = millis / MILLIS_PER_SECOND; final long nanos = (millis % MILLIS_PER_SECOND) * (NANOS_PER_SECOND / MILLIS_PER_SECOND); return (T) temporal.with(INSTANT_SECONDS, seconds).with(NANO_OF_SECOND, nanos); } }
@SuppressWarnings("unchecked") public <T extends Temporal> T adjustInto(final T temporal) { if (temporal instanceof CalendarDate) { return (T) this; } else { final long seconds = millis / MILLIS_PER_SECOND; final long nanos = (millis % MILLIS_PER_SECOND) * (NANOS_PER_SECOND / MILLIS_PER_SECOND); return (T) temporal.with(INSTANT_SECONDS, seconds).with(NANO_OF_SECOND, nanos); } }
@SuppressWarnings("unchecked") @Override public <R extends Temporal> R adjustInto(R temporal, long newValue) { long hour = newValue / 100; long min = newValue % 100; HOUR_OF_DAY.checkValidValue(hour); MINUTE_OF_HOUR.checkValidValue(min); return (R) temporal.with(HOUR_OF_DAY, hour).with(MINUTE_OF_HOUR, min); }
@SuppressWarnings( "unchecked" ) @Override public <R extends Temporal> R adjustInto( R temporal, long newValue ) { int newVal = range.checkValidIntValue( newValue, this ); int oldYear = temporal.get( ChronoField.YEAR ); return (R) temporal.with( ChronoField.YEAR, (oldYear / years) * years + newVal ) .with( TemporalAdjusters.firstDayOfYear() ); }
@Override public Temporal adjustInto(Temporal temporal) { long adjustedDayOfMonth = Math.min(dayOfMonth, temporal.range(ChronoField.DAY_OF_MONTH).getMaximum()); return temporal.with(ChronoField.DAY_OF_MONTH, adjustedDayOfMonth); } };
protected T readFieldFromObject(T obj, ObjectReader reader){ Temporal objTemporal = (Temporal) obj; String jsonName = reader.name(); TemporalField field = temporalFields.get(jsonName); long value = reader.valueAsLong(); return (T) objTemporal.with(field, value); } }
@Override @SuppressWarnings( "unchecked" ) public final V with( TemporalField field, long newValue ) { return replacement( (T) temporal().with( field, newValue ) ); }
@Override @SuppressWarnings( "unchecked" ) public final V with( TemporalAdjuster adjuster ) { return replacement( (T) temporal().with( adjuster ) ); }
@SuppressWarnings("unchecked") @Override public <R extends Temporal> R adjustInto(R temporal, long newValue) { long curValue = getFrom(temporal); range().checkValidValue(newValue, this); return (R) temporal.with(DAY_OF_YEAR, temporal.getLong(DAY_OF_YEAR) + (newValue - curValue)); } @Override
@SuppressWarnings("unchecked") @Override public <R extends Temporal> R adjustInto(R temporal, long newValue) { long curValue = getFrom(temporal); range().checkValidValue(newValue, this); return (R) temporal.with(MONTH_OF_YEAR, temporal.getLong(MONTH_OF_YEAR) + (newValue - curValue) * 3); } },
public static TemporalAdjuster nextOrSameDayOfMonth(int dayOfMonth) { validateDayOfMonth(dayOfMonth); TemporalAdjuster nextDayOfMonth = nextDayOfMonth(dayOfMonth); return temporal -> { int currentDayOfMonth = temporal.get(DAY_OF_MONTH); if (currentDayOfMonth == dayOfMonth || (currentDayOfMonth < dayOfMonth && currentDayOfMonth == temporal.range(DAY_OF_MONTH).getMaximum())) { return temporal; } return temporal.with(nextDayOfMonth); }; }