@Override public void marshal(final Object source, final HierarchicalStreamWriter writer, final MarshallingContext context) { final ValueRange valueRange = (ValueRange)source; write("maxLargest", valueRange.getMaximum(), writer); write("maxSmallest", valueRange.getSmallestMaximum(), writer); write("minLargest", valueRange.getLargestMinimum(), writer); write("minSmallest", valueRange.getMinimum(), writer); }
Neo4JTemporalField( String name, TemporalUnit baseUnit, TemporalUnit rangeUnit, int years ) { this.name = name; this.baseUnit = baseUnit; this.rangeUnit = rangeUnit; this.years = years; this.range = ValueRange.of( Year.MIN_VALUE / years, Year.MAX_VALUE / years ); }
@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() ); }
private Checker parseSub(String cronExpression, ChronoField chronoField, String sub, Map<String, Integer> names) { final int min = (int) chronoField.range().getMinimum(); final int max = (int) chronoField.range().getMaximum();
@Override public ValueRange range(ChronoField field) { switch (field) { case PROLEPTIC_MONTH: { ValueRange range = PROLEPTIC_MONTH.range(); return ValueRange.of(range.getMinimum() + YEARS_DIFFERENCE * 12L, range.getMaximum() + YEARS_DIFFERENCE * 12L); } case YEAR_OF_ERA: { ValueRange range = YEAR.range(); return ValueRange.of(1, -(range.getMinimum() + YEARS_DIFFERENCE) + 1, range.getMaximum() + YEARS_DIFFERENCE); } case YEAR: { ValueRange range = YEAR.range(); return ValueRange.of(range.getMinimum() + YEARS_DIFFERENCE, range.getMaximum() + YEARS_DIFFERENCE); } } return field.range(); }
/** * @param temporal temporal to check * @return true if temporal is the last day in the month */ private static boolean isLastDayInMonth(Temporal temporal) { final int day = temporal.get(ChronoField.DAY_OF_MONTH); final int max = (int) ChronoField.DAY_OF_MONTH.rangeRefinedBy(temporal).getMaximum(); return day == max; }
/** * Converts a value for this field to a fraction between 0 and 1. * <p> * The fractional value is between 0 (inclusive) and 1 (exclusive). * It can only be returned if the {@link TemporalField#range() value range} is fixed. * The fraction is obtained by calculation from the field range using 9 decimal * places and a rounding mode of {@link RoundingMode#FLOOR FLOOR}. * The calculation is inaccurate if the values do not run continuously from smallest to largest. * <p> * For example, the second-of-minute value of 15 would be returned as 0.25, * assuming the standard definition of 60 seconds in a minute. * * @param value the value to convert, must be valid for this rule * @return the value as a fraction within the range, from 0 to 1, not null * @throws DateTimeException if the value cannot be converted to a fraction */ private BigDecimal convertToFraction(long value) { ValueRange range = field.range(); range.checkValidValue(value, field); BigDecimal minBD = BigDecimal.valueOf(range.getMinimum()); BigDecimal rangeBD = BigDecimal.valueOf(range.getMaximum()).subtract(minBD).add(BigDecimal.ONE); BigDecimal valueBD = BigDecimal.valueOf(value).subtract(minBD); BigDecimal fraction = valueBD.divide(rangeBD, 9, RoundingMode.FLOOR); // stripTrailingZeros bug return fraction.compareTo(BigDecimal.ZERO) == 0 ? BigDecimal.ZERO : fraction.stripTrailingZeros(); }
@Override public ChronoPeriod normalized() { if (chronology.range(ChronoField.MONTH_OF_YEAR).isFixed()) { long monthLength = chronology.range(ChronoField.MONTH_OF_YEAR).getMaximum() - chronology.range(ChronoField.MONTH_OF_YEAR).getMinimum() + 1; long total = years * monthLength + months; int years = Jdk8Methods.safeToInt(total / monthLength); int months = Jdk8Methods.safeToInt(total % monthLength); return new ChronoPeriodImpl(chronology, years, months, days); } return this; }
@Override protected boolean matchesSafely(final T actual, final Description mismatchDesc) { int actualValue = this.adapter.asTemporalField(actual, zone); ValueRange range = this.rangeAdapter.asTemporalFieldRange(actual, zone); if (range.getMinimum() != actualValue) { mismatchDesc.appendText("date is the " + actualValue + " " + this.formatter.describe(this.datePart) + " instead of " + range.getMinimum() + " " + this.formatter.describe(this.datePart)); return false; } else { return true; } }
@Override public int prolepticYear(Era era, int yearOfEra) { if (era instanceof JapaneseEra == false) { throw new ClassCastException("Era must be JapaneseEra"); } JapaneseEra jera = (JapaneseEra) era; int isoYear = jera.startDate().getYear() + yearOfEra - 1; ValueRange range = ValueRange.of(1, jera.endDate().getYear() - jera.startDate().getYear() + 1); range.checkValidValue(yearOfEra, YEAR_OF_ERA); return isoYear; }
@Override public MinguoDate with(TemporalField field, long newValue) { if (field instanceof ChronoField) { ChronoField f = (ChronoField) field; if (getLong(f) == newValue) { return this; } switch (f) { case PROLEPTIC_MONTH: getChronology().range(f).checkValidValue(newValue, f); return plusMonths(newValue - getProlepticMonth()); case YEAR_OF_ERA: case YEAR: case ERA: { int nvalue = getChronology().range(f).checkValidIntValue(newValue, f); switch (f) { case YEAR_OF_ERA: return with(isoDate.withYear(getProlepticYear() >= 1 ? nvalue + YEARS_DIFFERENCE : (1 - nvalue) + YEARS_DIFFERENCE)); case YEAR: return with(isoDate.withYear(nvalue + YEARS_DIFFERENCE)); case ERA: return with(isoDate.withYear((1 - getProlepticYear()) + YEARS_DIFFERENCE)); } } } return with(isoDate.with(field, newValue)); } return field.adjustInto(this, newValue); }
/** * Checks if the value is within the valid range. * <p> * This checks that the value is within the stored range of values. * * @param value the value to check * @return true if the value is valid */ public boolean isValidValue(long value) { return (value >= getMinimum() && value <= getMaximum()); }
@Override public ValueRange range(ChronoField field) { switch (field) { case PROLEPTIC_MONTH: { ValueRange range = PROLEPTIC_MONTH.range(); return ValueRange.of(range.getMinimum() - YEARS_DIFFERENCE * 12L, range.getMaximum() - YEARS_DIFFERENCE * 12L); } case YEAR_OF_ERA: { ValueRange range = YEAR.range(); return ValueRange.of(1, range.getMaximum() - YEARS_DIFFERENCE, -range.getMinimum() + 1 + YEARS_DIFFERENCE); } case YEAR: { ValueRange range = YEAR.range(); return ValueRange.of(range.getMinimum() - YEARS_DIFFERENCE, range.getMaximum() - YEARS_DIFFERENCE); } } return field.range(); }
/** * @param temporal temporal to check * @return true if temporal is the last week day in this month. I.e. the last Saturday */ private static boolean isLastOfThisWeekDayInMonth(Temporal temporal) { final int day = temporal.get(ChronoField.DAY_OF_MONTH); final int max = (int) ChronoField.DAY_OF_MONTH.rangeRefinedBy(temporal).getMaximum(); return day + 7 > max; }
public LocalDateTime evaluate(LocalDateTime ldt, EventBean[] eventsPerStream, boolean isNewData, ExprEvaluatorContext context) { ValueRange range = ldt.range(fieldName.getChronoField()); return ldt.with(fieldName.getChronoField(), range.getMinimum()); }
@Override public ThaiBuddhistDate with(TemporalField field, long newValue) { if (field instanceof ChronoField) { ChronoField f = (ChronoField) field; if (getLong(f) == newValue) { return this; } switch (f) { case PROLEPTIC_MONTH: getChronology().range(f).checkValidValue(newValue, f); return plusMonths(newValue - getProlepticMonth()); case YEAR_OF_ERA: case YEAR: case ERA: { int nvalue = getChronology().range(f).checkValidIntValue(newValue, f); switch (f) { case YEAR_OF_ERA: return with(isoDate.withYear((getProlepticYear() >= 1 ? nvalue : 1 - nvalue) - YEARS_DIFFERENCE)); case YEAR: return with(isoDate.withYear(nvalue - YEARS_DIFFERENCE)); case ERA: return with(isoDate.withYear((1 - getProlepticYear()) - YEARS_DIFFERENCE)); } } } return with(isoDate.with(field, newValue)); } return field.adjustInto(this, newValue); }
public boolean isValidValue(long value) { return (value >= getMinimum() && value <= getMaximum()); }
@Override public ValueRange range(TemporalField field) { if (field instanceof ChronoField) { if (isSupported(field)) { ChronoField f = (ChronoField) field; switch (f) { case DAY_OF_MONTH: case DAY_OF_YEAR: case ALIGNED_WEEK_OF_MONTH: return isoDate.range(field); case YEAR_OF_ERA: { ValueRange range = YEAR.range(); long max = (getProlepticYear() <= 0 ? -(range.getMinimum() + YEARS_DIFFERENCE) + 1 : range.getMaximum() + YEARS_DIFFERENCE); return ValueRange.of(1, max); } } return getChronology().range(f); } throw new UnsupportedTemporalTypeException("Unsupported field: " + field); } return field.rangeRefinedBy(this); }
/** * @param temporal temporal to check * @return true if temporal is the last working day in the month */ private static boolean isLastWorkingDayInMonth(Temporal temporal) { final int day = temporal.get(ChronoField.DAY_OF_MONTH); final DayOfWeek type = DayOfWeek.of(temporal.get(ChronoField.DAY_OF_WEEK)); final int max = (int) ChronoField.DAY_OF_MONTH.rangeRefinedBy(temporal).getMaximum(); switch (type) { case MONDAY: case TUESDAY: case WEDNESDAY: case THURSDAY: return day == max; case FRIDAY: return day + 2 >= max; default: case SATURDAY: case SUNDAY: return false; } }
@Override public void marshal(final Object source, final HierarchicalStreamWriter writer, final MarshallingContext context) { final ValueRange valueRange = (ValueRange)source; write("maxLargest", valueRange.getMaximum(), writer); write("maxSmallest", valueRange.getSmallestMaximum(), writer); write("minLargest", valueRange.getLargestMinimum(), writer); write("minSmallest", valueRange.getMinimum(), writer); }