Java 类java.time.format.ResolverStyle 实例源码

项目:openjdk-jdk10    文件:IsoChronology.java   
@Override  // override for performance
LocalDate resolveYMD(Map <TemporalField, Long> fieldValues, ResolverStyle resolverStyle) {
    int y = YEAR.checkValidIntValue(fieldValues.remove(YEAR));
    if (resolverStyle == ResolverStyle.LENIENT) {
        long months = Math.subtractExact(fieldValues.remove(MONTH_OF_YEAR), 1);
        long days = Math.subtractExact(fieldValues.remove(DAY_OF_MONTH), 1);
        return LocalDate.of(y, 1, 1).plusMonths(months).plusDays(days);
    }
    int moy = MONTH_OF_YEAR.checkValidIntValue(fieldValues.remove(MONTH_OF_YEAR));
    int dom = DAY_OF_MONTH.checkValidIntValue(fieldValues.remove(DAY_OF_MONTH));
    if (resolverStyle == ResolverStyle.SMART) {  // previous valid
        if (moy == 4 || moy == 6 || moy == 9 || moy == 11) {
            dom = Math.min(dom, 30);
        } else if (moy == 2) {
            dom = Math.min(dom, Month.FEBRUARY.length(Year.isLeap(y)));

        }
    }
    return LocalDate.of(y, moy, dom);
}
项目:OpenJSharp    文件:IsoChronology.java   
@Override  // override for performance
LocalDate resolveYMD(Map <TemporalField, Long> fieldValues, ResolverStyle resolverStyle) {
    int y = YEAR.checkValidIntValue(fieldValues.remove(YEAR));
    if (resolverStyle == ResolverStyle.LENIENT) {
        long months = Math.subtractExact(fieldValues.remove(MONTH_OF_YEAR), 1);
        long days = Math.subtractExact(fieldValues.remove(DAY_OF_MONTH), 1);
        return LocalDate.of(y, 1, 1).plusMonths(months).plusDays(days);
    }
    int moy = MONTH_OF_YEAR.checkValidIntValue(fieldValues.remove(MONTH_OF_YEAR));
    int dom = DAY_OF_MONTH.checkValidIntValue(fieldValues.remove(DAY_OF_MONTH));
    if (resolverStyle == ResolverStyle.SMART) {  // previous valid
        if (moy == 4 || moy == 6 || moy == 9 || moy == 11) {
            dom = Math.min(dom, 30);
        } else if (moy == 2) {
            dom = Math.min(dom, Month.FEBRUARY.length(Year.isLeap(y)));

        }
    }
    return LocalDate.of(y, moy, dom);
}
项目:openjdk-jdk10    文件:AbstractChronology.java   
ChronoLocalDate resolveYMD(Map<TemporalField, Long> fieldValues, ResolverStyle resolverStyle) {
    int y = range(YEAR).checkValidIntValue(fieldValues.remove(YEAR), YEAR);
    if (resolverStyle == ResolverStyle.LENIENT) {
        long months = Math.subtractExact(fieldValues.remove(MONTH_OF_YEAR), 1);
        long days = Math.subtractExact(fieldValues.remove(DAY_OF_MONTH), 1);
        return date(y, 1, 1).plus(months, MONTHS).plus(days, DAYS);
    }
    int moy = range(MONTH_OF_YEAR).checkValidIntValue(fieldValues.remove(MONTH_OF_YEAR), MONTH_OF_YEAR);
    ValueRange domRange = range(DAY_OF_MONTH);
    int dom = domRange.checkValidIntValue(fieldValues.remove(DAY_OF_MONTH), DAY_OF_MONTH);
    if (resolverStyle == ResolverStyle.SMART) {  // previous valid
        try {
            return date(y, moy, dom);
        } catch (DateTimeException ex) {
            return date(y, moy, 1).with(TemporalAdjusters.lastDayOfMonth());
        }
    }
    return date(y, moy, dom);
}
项目:openjdk-jdk10    文件:TCKDateTimeParseResolver.java   
@Test(dataProvider="resolveFourToTime")
public void test_resolveFourToDateTime(ResolverStyle style,
                   long hour, long min, long sec, long nano, LocalTime expectedTime, Period excessPeriod) {
    DateTimeFormatter f = new DateTimeFormatterBuilder()
            .parseDefaulting(YEAR, 2012).parseDefaulting(MONTH_OF_YEAR, 6).parseDefaulting(DAY_OF_MONTH, 30)
            .parseDefaulting(HOUR_OF_DAY, hour)
            .parseDefaulting(MINUTE_OF_HOUR, min)
            .parseDefaulting(SECOND_OF_MINUTE, sec)
            .parseDefaulting(NANO_OF_SECOND, nano).toFormatter();

    ResolverStyle[] styles = (style != null ? new ResolverStyle[] {style} : ResolverStyle.values());
    if (expectedTime != null && excessPeriod != null) {
        LocalDate expectedDate = LocalDate.of(2012, 6, 30).plus(excessPeriod);
        for (ResolverStyle s : styles) {
            TemporalAccessor accessor = f.withResolverStyle(s).parse("");
            assertEquals(accessor.query(TemporalQueries.localDate()), expectedDate, "ResolverStyle: " + s);
            assertEquals(accessor.query(TemporalQueries.localTime()), expectedTime, "ResolverStyle: " + s);
            assertEquals(accessor.query(DateTimeFormatter.parsedExcessDays()), Period.ZERO, "ResolverStyle: " + s);
        }
    }
}
项目:openjdk-jdk10    文件:TCKIsoChronology.java   
@Test(dataProvider = "resolve_ymaa")
public void test_resolve_ymaa_strict(int y, int m, int w, int d, LocalDate expected, boolean smart, boolean strict) {
    Map<TemporalField, Long> fieldValues = new HashMap<>();
    fieldValues.put(ChronoField.YEAR, (long) y);
    fieldValues.put(ChronoField.MONTH_OF_YEAR, (long) m);
    fieldValues.put(ChronoField.ALIGNED_WEEK_OF_MONTH, (long) w);
    fieldValues.put(ChronoField.ALIGNED_DAY_OF_WEEK_IN_MONTH, (long) d);
    if (strict) {
        LocalDate date = IsoChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT);
        assertEquals(date, expected);
        assertEquals(fieldValues.size(), 0);
    } else {
        try {
            IsoChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT);
            fail("Should have failed");
        } catch (DateTimeException ex) {
            // expected
        }
    }
}
项目:jdk8u-jdk    文件:TCKThaiBuddhistChronology.java   
@Test(dataProvider = "resolve_ymd")
public void test_resolve_ymd_strict(int y, int m, int d, ThaiBuddhistDate expected, Object smart, boolean strict) {
    Map<TemporalField, Long> fieldValues = new HashMap<>();
    fieldValues.put(ChronoField.YEAR, (long) y);
    fieldValues.put(ChronoField.MONTH_OF_YEAR, (long) m);
    fieldValues.put(ChronoField.DAY_OF_MONTH, (long) d);
    if (strict) {
        ThaiBuddhistDate date = ThaiBuddhistChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT);
        assertEquals(date, expected);
        assertEquals(fieldValues.size(), 0);
    } else {
        try {
            ThaiBuddhistChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT);
            fail("Should have failed");
        } catch (DateTimeException ex) {
            // expected
        }
    }
}
项目:openjdk-jdk10    文件:TCKIsoChronology.java   
@Test(dataProvider = "resolve_ymaa")
public void test_resolve_ymaa_smart(int y, int m, int w, int d, LocalDate expected, boolean smart, boolean strict) {
    Map<TemporalField, Long> fieldValues = new HashMap<>();
    fieldValues.put(ChronoField.YEAR, (long) y);
    fieldValues.put(ChronoField.MONTH_OF_YEAR, (long) m);
    fieldValues.put(ChronoField.ALIGNED_WEEK_OF_MONTH, (long) w);
    fieldValues.put(ChronoField.ALIGNED_DAY_OF_WEEK_IN_MONTH, (long) d);
    if (smart) {
        LocalDate date = IsoChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.SMART);
        assertEquals(date, expected);
        assertEquals(fieldValues.size(), 0);
    } else {
        try {
            IsoChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.SMART);
            fail("Should have failed");
        } catch (DateTimeException ex) {
            // expected
        }
    }
}
项目:jdk8u-jdk    文件:TCKIsoChronology.java   
@Test(dataProvider = "resolve_yearOfEra")
public void test_resolve_yearOfEra(ResolverStyle style, Integer e, Integer yoe, Integer y, ChronoField field, Integer expected) {
    Map<TemporalField, Long> fieldValues = new HashMap<>();
    if (e != null) {
        fieldValues.put(ChronoField.ERA, (long) e);
    }
    if (yoe != null) {
        fieldValues.put(ChronoField.YEAR_OF_ERA, (long) yoe);
    }
    if (y != null) {
        fieldValues.put(ChronoField.YEAR, (long) y);
    }
    if (field != null) {
        LocalDate date = IsoChronology.INSTANCE.resolveDate(fieldValues, style);
        assertEquals(date, null);
        assertEquals(fieldValues.get(field), (Long) expected.longValue());
        assertEquals(fieldValues.size(), 1);
    } else {
        try {
            IsoChronology.INSTANCE.resolveDate(fieldValues, style);
            fail("Should have failed");
        } catch (DateTimeException ex) {
            // expected
        }
    }
}
项目:openjdk-jdk10    文件:TCKDateTimeParseResolver.java   
@Test(dataProvider="resolveSecondOfDay")
public void test_resolveSecondOfDay(ResolverStyle style, long value, Integer expectedSecond, int expectedDays) {
    String str = Long.toString(value);
    DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(SECOND_OF_DAY).toFormatter();

    if (expectedSecond != null) {
        TemporalAccessor accessor = f.withResolverStyle(style).parse(str);
        assertEquals(accessor.query(TemporalQueries.localDate()), null);
        assertEquals(accessor.query(TemporalQueries.localTime()), LocalTime.ofSecondOfDay(expectedSecond));
        assertEquals(accessor.query(DateTimeFormatter.parsedExcessDays()), Period.ofDays(expectedDays));
    } else {
        try {
            f.withResolverStyle(style).parse(str);
            fail();
        } catch (DateTimeParseException ex) {
            // expected
        }
    }
}
项目:openjdk-jdk10    文件:TCKThaiBuddhistChronology.java   
@Test(dataProvider = "resolve_ymd")
public void test_resolve_ymd_strict(int y, int m, int d, ThaiBuddhistDate expected, Object smart, boolean strict) {
    Map<TemporalField, Long> fieldValues = new HashMap<>();
    fieldValues.put(ChronoField.YEAR, (long) y);
    fieldValues.put(ChronoField.MONTH_OF_YEAR, (long) m);
    fieldValues.put(ChronoField.DAY_OF_MONTH, (long) d);
    if (strict) {
        ThaiBuddhistDate date = ThaiBuddhistChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT);
        assertEquals(date, expected);
        assertEquals(fieldValues.size(), 0);
    } else {
        try {
            ThaiBuddhistChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT);
            fail("Should have failed");
        } catch (DateTimeException ex) {
            // expected
        }
    }
}
项目:jdk8u-jdk    文件:TCKIsoChronology.java   
@Test(dataProvider = "resolve_ymd")
public void test_resolve_ymd_strict(int y, int m, int d, LocalDate expected, Object smart, boolean strict) {
    Map<TemporalField, Long> fieldValues = new HashMap<>();
    fieldValues.put(ChronoField.YEAR, (long) y);
    fieldValues.put(ChronoField.MONTH_OF_YEAR, (long) m);
    fieldValues.put(ChronoField.DAY_OF_MONTH, (long) d);
    if (strict) {
        LocalDate date = IsoChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT);
        assertEquals(date, expected);
        assertEquals(fieldValues.size(), 0);
    } else {
        try {
            IsoChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT);
            fail("Should have failed");
        } catch (DateTimeException ex) {
            // expected
        }
    }
}
项目:jdk8u-jdk    文件:TCKIsoFields.java   
@Test(dataProvider = "parseLenientWeek")
public void test_parse_parseLenientWeek_SMART(String str, LocalDate expected, boolean smart) {
    DateTimeFormatter f = new DateTimeFormatterBuilder()
            .appendValue(IsoFields.WEEK_BASED_YEAR).appendLiteral(':')
            .appendValue(IsoFields.WEEK_OF_WEEK_BASED_YEAR).appendLiteral(':')
            .appendValue(DAY_OF_WEEK)
            .toFormatter().withResolverStyle(ResolverStyle.SMART);
    if (smart) {
        LocalDate parsed = LocalDate.parse(str, f);
        assertEquals(parsed, expected);
    } else {
        try {
            LocalDate.parse(str, f);
            fail("Should have failed");
        } catch (DateTimeParseException ex) {
            // expected
        }
    }
}
项目:jdk8u-jdk    文件:TCKMinguoChronology.java   
@Test(dataProvider = "resolve_yd")
public void test_resolve_yd_smart(int y, int d, MinguoDate expected, boolean smart, boolean strict) {
    Map<TemporalField, Long> fieldValues = new HashMap<>();
    fieldValues.put(ChronoField.YEAR, (long) y);
    fieldValues.put(ChronoField.DAY_OF_YEAR, (long) d);
    if (smart) {
        MinguoDate date = MinguoChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.SMART);
        assertEquals(date, expected);
        assertEquals(fieldValues.size(), 0);
    } else {
        try {
            MinguoChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.SMART);
            fail("Should have failed");
        } catch (DateTimeException ex) {
            // expected
        }
    }
}
项目:openjdk-jdk10    文件:TCKThaiBuddhistChronology.java   
@Test(dataProvider = "resolve_yd")
public void test_resolve_yd_smart(int y, int d, ThaiBuddhistDate expected, boolean smart, boolean strict) {
    Map<TemporalField, Long> fieldValues = new HashMap<>();
    fieldValues.put(ChronoField.YEAR, (long) y);
    fieldValues.put(ChronoField.DAY_OF_YEAR, (long) d);
    if (smart) {
        ThaiBuddhistDate date = ThaiBuddhistChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.SMART);
        assertEquals(date, expected);
        assertEquals(fieldValues.size(), 0);
    } else {
        try {
            ThaiBuddhistChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.SMART);
            fail("Should have failed");
        } catch (DateTimeException ex) {
            // expected
        }
    }
}
项目:jdk8u-jdk    文件:TCKThaiBuddhistChronology.java   
@Test(dataProvider = "resolve_yd")
public void test_resolve_yd_smart(int y, int d, ThaiBuddhistDate expected, boolean smart, boolean strict) {
    Map<TemporalField, Long> fieldValues = new HashMap<>();
    fieldValues.put(ChronoField.YEAR, (long) y);
    fieldValues.put(ChronoField.DAY_OF_YEAR, (long) d);
    if (smart) {
        ThaiBuddhistDate date = ThaiBuddhistChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.SMART);
        assertEquals(date, expected);
        assertEquals(fieldValues.size(), 0);
    } else {
        try {
            ThaiBuddhistChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.SMART);
            fail("Should have failed");
        } catch (DateTimeException ex) {
            // expected
        }
    }
}
项目:jdk8u-jdk    文件:TCKDateTimeParseResolver.java   
@Test(dataProvider="resolveFourToTime")
public void test_resolveThreeToTime(ResolverStyle style,
                                   long hour, long min, long sec, long nano, LocalTime expectedTime, Period excessPeriod) {
    DateTimeFormatter f = new DateTimeFormatterBuilder()
            .parseDefaulting(HOUR_OF_DAY, hour)
            .parseDefaulting(MINUTE_OF_HOUR, min)
            .parseDefaulting(SECOND_OF_MINUTE, sec).toFormatter();

    ResolverStyle[] styles = (style != null ? new ResolverStyle[] {style} : ResolverStyle.values());
    for (ResolverStyle s : styles) {
        if (expectedTime != null) {
            TemporalAccessor accessor = f.withResolverStyle(s).parse("");
            assertEquals(accessor.query(TemporalQueries.localDate()), null, "ResolverStyle: " + s);
            assertEquals(accessor.query(TemporalQueries.localTime()), expectedTime.minusNanos(nano), "ResolverStyle: " + s);
            assertEquals(accessor.query(DateTimeFormatter.parsedExcessDays()), excessPeriod, "ResolverStyle: " + s);
        } else {
            try {
                f.withResolverStyle(style).parse("");
                fail();
            } catch (DateTimeParseException ex) {
                // expected
            }
        }
    }
}
项目:jdk8u-jdk    文件:TCKDateTimeParseResolver.java   
@Test(dataProvider="resolveFourToTime")
public void test_resolveFourToDateTime(ResolverStyle style,
                   long hour, long min, long sec, long nano, LocalTime expectedTime, Period excessPeriod) {
    DateTimeFormatter f = new DateTimeFormatterBuilder()
            .parseDefaulting(YEAR, 2012).parseDefaulting(MONTH_OF_YEAR, 6).parseDefaulting(DAY_OF_MONTH, 30)
            .parseDefaulting(HOUR_OF_DAY, hour)
            .parseDefaulting(MINUTE_OF_HOUR, min)
            .parseDefaulting(SECOND_OF_MINUTE, sec)
            .parseDefaulting(NANO_OF_SECOND, nano).toFormatter();

    ResolverStyle[] styles = (style != null ? new ResolverStyle[] {style} : ResolverStyle.values());
    if (expectedTime != null && excessPeriod != null) {
        LocalDate expectedDate = LocalDate.of(2012, 6, 30).plus(excessPeriod);
        for (ResolverStyle s : styles) {
            TemporalAccessor accessor = f.withResolverStyle(s).parse("");
            assertEquals(accessor.query(TemporalQueries.localDate()), expectedDate, "ResolverStyle: " + s);
            assertEquals(accessor.query(TemporalQueries.localTime()), expectedTime, "ResolverStyle: " + s);
            assertEquals(accessor.query(DateTimeFormatter.parsedExcessDays()), Period.ZERO, "ResolverStyle: " + s);
        }
    }
}
项目:jdk8u-jdk    文件:TCKDateTimeParseResolver.java   
@Test(dataProvider="resolveSecondOfDay")
public void test_resolveSecondOfDay(ResolverStyle style, long value, Integer expectedSecond, int expectedDays) {
    String str = Long.toString(value);
    DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(SECOND_OF_DAY).toFormatter();

    if (expectedSecond != null) {
        TemporalAccessor accessor = f.withResolverStyle(style).parse(str);
        assertEquals(accessor.query(TemporalQueries.localDate()), null);
        assertEquals(accessor.query(TemporalQueries.localTime()), LocalTime.ofSecondOfDay(expectedSecond));
        assertEquals(accessor.query(DateTimeFormatter.parsedExcessDays()), Period.ofDays(expectedDays));
    } else {
        try {
            f.withResolverStyle(style).parse(str);
            fail();
        } catch (DateTimeParseException ex) {
            // expected
        }
    }
}
项目:jdk8u-jdk    文件:TCKThaiBuddhistChronology.java   
@Test(dataProvider = "resolve_yearOfEra")
public void test_resolve_yearOfEra(ResolverStyle style, Integer e, Integer yoe, Integer y, ChronoField field, Integer expected) {
    Map<TemporalField, Long> fieldValues = new HashMap<>();
    if (e != null) {
        fieldValues.put(ChronoField.ERA, (long) e);
    }
    if (yoe != null) {
        fieldValues.put(ChronoField.YEAR_OF_ERA, (long) yoe);
    }
    if (y != null) {
        fieldValues.put(ChronoField.YEAR, (long) y);
    }
    if (field != null) {
        ThaiBuddhistDate date = ThaiBuddhistChronology.INSTANCE.resolveDate(fieldValues, style);
        assertEquals(date, null);
        assertEquals(fieldValues.get(field), (Long) expected.longValue());
        assertEquals(fieldValues.size(), 1);
    } else {
        try {
            ThaiBuddhistChronology.INSTANCE.resolveDate(fieldValues, style);
            fail("Should have failed");
        } catch (DateTimeException ex) {
            // expected
        }
    }
}
项目:jdk8u-jdk    文件:TCKDateTimeParseResolver.java   
@Test(dataProvider="resolveClockHourOfDay")
public void test_resolveClockHourOfDay(ResolverStyle style, long value, Integer expectedHour, int expectedDays) {
    String str = Long.toString(value);
    DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(CLOCK_HOUR_OF_DAY).toFormatter();

    if (expectedHour != null) {
        TemporalAccessor accessor = f.withResolverStyle(style).parse(str);
        assertEquals(accessor.query(TemporalQueries.localDate()), null);
        assertEquals(accessor.query(TemporalQueries.localTime()), LocalTime.of(expectedHour, 0));
        assertEquals(accessor.query(DateTimeFormatter.parsedExcessDays()), Period.ofDays(expectedDays));
    } else {
        try {
            f.withResolverStyle(style).parse(str);
            fail();
        } catch (DateTimeParseException ex) {
            // expected
        }
    }
}
项目:jdk8u-jdk    文件:TCKDateTimeParseResolver.java   
@Test(dataProvider="resolveClockHourOfAmPm")
public void test_resolveClockHourOfAmPm(ResolverStyle style, long value, Integer expectedValue) {
    String str = Long.toString(value);
    DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(CLOCK_HOUR_OF_AMPM).toFormatter();

    if (expectedValue != null) {
        TemporalAccessor accessor = f.withResolverStyle(style).parse(str);
        assertEquals(accessor.query(TemporalQueries.localDate()), null);
        assertEquals(accessor.query(TemporalQueries.localTime()), null);
        assertEquals(accessor.isSupported(CLOCK_HOUR_OF_AMPM), false);
        assertEquals(accessor.isSupported(HOUR_OF_AMPM), true);
        assertEquals(accessor.getLong(HOUR_OF_AMPM), expectedValue.longValue());
    } else {
        try {
            f.withResolverStyle(style).parse(str);
            fail();
        } catch (DateTimeParseException ex) {
            // expected
        }
    }
}
项目:jdk8u-jdk    文件:TCKDateTimeParseResolver.java   
@Test(dataProvider="resolveAmPm")
public void test_resolveAmPm(ResolverStyle style, long value, Integer expectedValue) {
    String str = Long.toString(value);
    DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(AMPM_OF_DAY).toFormatter();

    if (expectedValue != null) {
        TemporalAccessor accessor = f.withResolverStyle(style).parse(str);
        assertEquals(accessor.query(TemporalQueries.localDate()), null);
        assertEquals(accessor.query(TemporalQueries.localTime()), null);
        assertEquals(accessor.isSupported(AMPM_OF_DAY), true);
        assertEquals(accessor.getLong(AMPM_OF_DAY), expectedValue.longValue());
    } else {
        try {
            f.withResolverStyle(style).parse(str);
            fail();
        } catch (DateTimeParseException ex) {
            // expected
        }
    }
}
项目:openjdk-jdk10    文件:TCKIsoChronology.java   
@Test(dataProvider = "resolve_ymd")
public void test_resolve_ymd_strict(int y, int m, int d, LocalDate expected, Object smart, boolean strict) {
    Map<TemporalField, Long> fieldValues = new HashMap<>();
    fieldValues.put(ChronoField.YEAR, (long) y);
    fieldValues.put(ChronoField.MONTH_OF_YEAR, (long) m);
    fieldValues.put(ChronoField.DAY_OF_MONTH, (long) d);
    if (strict) {
        LocalDate date = IsoChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT);
        assertEquals(date, expected);
        assertEquals(fieldValues.size(), 0);
    } else {
        try {
            IsoChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT);
            fail("Should have failed");
        } catch (DateTimeException ex) {
            // expected
        }
    }
}
项目:openjdk-jdk10    文件:TCKJapaneseChronology.java   
@Test(dataProvider = "resolve_ymd")
public void test_resolve_ymd_strict(int y, int m, int d, JapaneseDate expected, Object smart, boolean strict) {
    Map<TemporalField, Long> fieldValues = new HashMap<>();
    fieldValues.put(ChronoField.YEAR, (long) y);
    fieldValues.put(ChronoField.MONTH_OF_YEAR, (long) m);
    fieldValues.put(ChronoField.DAY_OF_MONTH, (long) d);
    if (strict) {
        JapaneseDate date = JapaneseChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT);
        assertEquals(date, expected);
        assertEquals(fieldValues.size(), 0);
    } else {
        try {
            JapaneseChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT);
            fail("Should have failed");
        } catch (DateTimeException ex) {
            // expected
        }
    }
}
项目:openjdk-jdk10    文件:TCKMinguoChronology.java   
@Test(dataProvider = "resolve_ymaa")
public void test_resolve_ymaa_strict(int y, int m, int w, int d, MinguoDate expected, boolean smart, boolean strict) {
    Map<TemporalField, Long> fieldValues = new HashMap<>();
    fieldValues.put(ChronoField.YEAR, (long) y);
    fieldValues.put(ChronoField.MONTH_OF_YEAR, (long) m);
    fieldValues.put(ChronoField.ALIGNED_WEEK_OF_MONTH, (long) w);
    fieldValues.put(ChronoField.ALIGNED_DAY_OF_WEEK_IN_MONTH, (long) d);
    if (strict) {
        MinguoDate date = MinguoChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT);
        assertEquals(date, expected);
        assertEquals(fieldValues.size(), 0);
    } else {
        try {
            MinguoChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT);
            fail("Should have failed");
        } catch (DateTimeException ex) {
            // expected
        }
    }
}
项目:openjdk-jdk10    文件:TCKMinguoChronology.java   
@Test(dataProvider = "resolve_yd")
public void test_resolve_yd_smart(int y, int d, MinguoDate expected, boolean smart, boolean strict) {
    Map<TemporalField, Long> fieldValues = new HashMap<>();
    fieldValues.put(ChronoField.YEAR, (long) y);
    fieldValues.put(ChronoField.DAY_OF_YEAR, (long) d);
    if (smart) {
        MinguoDate date = MinguoChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.SMART);
        assertEquals(date, expected);
        assertEquals(fieldValues.size(), 0);
    } else {
        try {
            MinguoChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.SMART);
            fail("Should have failed");
        } catch (DateTimeException ex) {
            // expected
        }
    }
}
项目:jdk8u-jdk    文件:TCKIsoChronology.java   
@Test(dataProvider = "resolve_yd")
public void test_resolve_yd_smart(int y, int d, LocalDate expected, boolean smart, boolean strict) {
    Map<TemporalField, Long> fieldValues = new HashMap<>();
    fieldValues.put(ChronoField.YEAR, (long) y);
    fieldValues.put(ChronoField.DAY_OF_YEAR, (long) d);
    if (smart) {
        LocalDate date = IsoChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.SMART);
        assertEquals(date, expected);
        assertEquals(fieldValues.size(), 0);
    } else {
        try {
            IsoChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.SMART);
            fail("Should have failed");
        } catch (DateTimeException ex) {
            // expected
        }
    }
}
项目:jdk8u-jdk    文件:TCKJapaneseChronology.java   
@Test(dataProvider = "resolve_ymd")
public void test_resolve_ymd_strict(int y, int m, int d, JapaneseDate expected, Object smart, boolean strict) {
    Map<TemporalField, Long> fieldValues = new HashMap<>();
    fieldValues.put(ChronoField.YEAR, (long) y);
    fieldValues.put(ChronoField.MONTH_OF_YEAR, (long) m);
    fieldValues.put(ChronoField.DAY_OF_MONTH, (long) d);
    if (strict) {
        JapaneseDate date = JapaneseChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT);
        assertEquals(date, expected);
        assertEquals(fieldValues.size(), 0);
    } else {
        try {
            JapaneseChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT);
            fail("Should have failed");
        } catch (DateTimeException ex) {
            // expected
        }
    }
}
项目:openjdk-jdk10    文件:TCKMinguoChronology.java   
@Test(dataProvider = "resolve_yearOfEra")
public void test_resolve_yearOfEra(ResolverStyle style, Integer e, Integer yoe, Integer y, ChronoField field, Integer expected) {
    Map<TemporalField, Long> fieldValues = new HashMap<>();
    if (e != null) {
        fieldValues.put(ChronoField.ERA, (long) e);
    }
    if (yoe != null) {
        fieldValues.put(ChronoField.YEAR_OF_ERA, (long) yoe);
    }
    if (y != null) {
        fieldValues.put(ChronoField.YEAR, (long) y);
    }
    if (field != null) {
        MinguoDate date = MinguoChronology.INSTANCE.resolveDate(fieldValues, style);
        assertEquals(date, null);
        assertEquals(fieldValues.get(field), (Long) expected.longValue());
        assertEquals(fieldValues.size(), 1);
    } else {
        try {
            MinguoChronology.INSTANCE.resolveDate(fieldValues, style);
            fail("Should have failed");
        } catch (DateTimeException ex) {
            // expected
        }
    }
}
项目:jdk8u-jdk    文件:TCKJapaneseChronology.java   
@Test(dataProvider = "resolve_eymd")
public void test_resolve_eymd(ResolverStyle style, JapaneseEra era, int yoe, int m, int d, JapaneseDate expected) {
    Map<TemporalField, Long> fieldValues = new HashMap<>();
    fieldValues.put(ChronoField.ERA, (long) era.getValue());
    fieldValues.put(ChronoField.YEAR_OF_ERA, (long) yoe);
    fieldValues.put(ChronoField.MONTH_OF_YEAR, (long) m);
    fieldValues.put(ChronoField.DAY_OF_MONTH, (long) d);
    if (expected != null) {
        JapaneseDate date = JapaneseChronology.INSTANCE.resolveDate(fieldValues, style);
        assertEquals(date, expected);
        assertEquals(fieldValues.size(), 0);
    } else {
        try {
            JapaneseChronology.INSTANCE.resolveDate(fieldValues, style);
            fail("Should have failed");
        } catch (DateTimeException ex) {
            // expected
        }
    }
}
项目:openjdk-jdk10    文件:TCKJapaneseChronology.java   
@Test(dataProvider = "resolve_eymd")
public void test_resolve_eymd(ResolverStyle style, JapaneseEra era, int yoe, int m, int d, JapaneseDate expected) {
    Map<TemporalField, Long> fieldValues = new HashMap<>();
    fieldValues.put(ChronoField.ERA, (long) era.getValue());
    fieldValues.put(ChronoField.YEAR_OF_ERA, (long) yoe);
    fieldValues.put(ChronoField.MONTH_OF_YEAR, (long) m);
    fieldValues.put(ChronoField.DAY_OF_MONTH, (long) d);
    if (expected != null) {
        JapaneseDate date = JapaneseChronology.INSTANCE.resolveDate(fieldValues, style);
        assertEquals(date, expected);
        assertEquals(fieldValues.size(), 0);
    } else {
        try {
            JapaneseChronology.INSTANCE.resolveDate(fieldValues, style);
            fail("Should have failed");
        } catch (DateTimeException ex) {
            // expected
        }
    }
}
项目:OpenJSharp    文件:IsoFields.java   
@Override
public ChronoLocalDate resolve(
        Map<TemporalField, Long> fieldValues, TemporalAccessor partialTemporal, ResolverStyle resolverStyle) {
    Long yearLong = fieldValues.get(YEAR);
    Long qoyLong = fieldValues.get(QUARTER_OF_YEAR);
    if (yearLong == null || qoyLong == null) {
        return null;
    }
    int y = YEAR.checkValidIntValue(yearLong);  // always validate
    long doq = fieldValues.get(DAY_OF_QUARTER);
    ensureIso(partialTemporal);
    LocalDate date;
    if (resolverStyle == ResolverStyle.LENIENT) {
        date = LocalDate.of(y, 1, 1).plusMonths(Math.multiplyExact(Math.subtractExact(qoyLong, 1), 3));
        doq = Math.subtractExact(doq, 1);
    } else {
        int qoy = QUARTER_OF_YEAR.range().checkValidIntValue(qoyLong, QUARTER_OF_YEAR);  // validated
        date = LocalDate.of(y, ((qoy - 1) * 3) + 1, 1);
        if (doq < 1 || doq > 90) {
            if (resolverStyle == ResolverStyle.STRICT) {
                rangeRefinedBy(date).checkValidValue(doq, this);  // only allow exact range
            } else {  // SMART
                range().checkValidValue(doq, this);  // allow 1-92 rolling into next quarter
            }
        }
        doq--;
    }
    fieldValues.remove(this);
    fieldValues.remove(YEAR);
    fieldValues.remove(QUARTER_OF_YEAR);
    return date.plusDays(doq);
}
项目:OpenJSharp    文件:JulianFields.java   
@Override
public ChronoLocalDate resolve(
        Map<TemporalField, Long> fieldValues, TemporalAccessor partialTemporal, ResolverStyle resolverStyle) {
    long value = fieldValues.remove(this);
    Chronology chrono = Chronology.from(partialTemporal);
    if (resolverStyle == ResolverStyle.LENIENT) {
        return chrono.dateEpochDay(Math.subtractExact(value, offset));
    }
    range().checkValidValue(value, this);
    return chrono.dateEpochDay(value - offset);
}
项目:OpenJSharp    文件:JapaneseChronology.java   
private ChronoLocalDate resolveYD(JapaneseEra era, int yoe, Map <TemporalField,Long> fieldValues, ResolverStyle resolverStyle) {
    fieldValues.remove(ERA);
    fieldValues.remove(YEAR_OF_ERA);
    if (resolverStyle == ResolverStyle.LENIENT) {
        int y = prolepticYearLenient(era, yoe);
        long days = Math.subtractExact(fieldValues.remove(DAY_OF_YEAR), 1);
        return dateYearDay(y, 1).plus(days, DAYS);
    }
    int doy = range(DAY_OF_YEAR).checkValidIntValue(fieldValues.remove(DAY_OF_YEAR), DAY_OF_YEAR);
    return dateYearDay(era, yoe, doy);  // smart is same as strict
}
项目:jdk8u-jdk    文件:TCKHijrahChronology.java   
@Test(dataProvider = "resolve_styleByEra")
public void test_resolve_yearOfEra_eraAndYearOnly_valid(ResolverStyle style, HijrahEra era) {
    Map<TemporalField, Long> fieldValues = new HashMap<>();
    fieldValues.put(ChronoField.ERA, (long) era.getValue());
    fieldValues.put(ChronoField.YEAR, 1343L);
    HijrahDate date = HijrahChronology.INSTANCE.resolveDate(fieldValues, style);
    assertEquals(date, null);
    assertEquals(fieldValues.get(ChronoField.ERA), (Long) (long) era.getValue());
    assertEquals(fieldValues.get(ChronoField.YEAR), (Long) 1343L);
    assertEquals(fieldValues.size(), 2);
}
项目:OpenJSharp    文件:AbstractChronology.java   
void resolveProlepticMonth(Map<TemporalField, Long> fieldValues, ResolverStyle resolverStyle) {
    Long pMonth = fieldValues.remove(PROLEPTIC_MONTH);
    if (pMonth != null) {
        if (resolverStyle != ResolverStyle.LENIENT) {
            PROLEPTIC_MONTH.checkValidValue(pMonth);
        }
        // first day-of-month is likely to be safest for setting proleptic-month
        // cannot add to year zero, as not all chronologies have a year zero
        ChronoLocalDate chronoDate = dateNow()
                .with(DAY_OF_MONTH, 1).with(PROLEPTIC_MONTH, pMonth);
        addFieldValue(fieldValues, MONTH_OF_YEAR, chronoDate.get(MONTH_OF_YEAR));
        addFieldValue(fieldValues, YEAR, chronoDate.get(YEAR));
    }
}
项目:OpenJSharp    文件:AbstractChronology.java   
ChronoLocalDate resolveYD(Map<TemporalField, Long> fieldValues, ResolverStyle resolverStyle) {
    int y = range(YEAR).checkValidIntValue(fieldValues.remove(YEAR), YEAR);
    if (resolverStyle == ResolverStyle.LENIENT) {
        long days = Math.subtractExact(fieldValues.remove(DAY_OF_YEAR), 1);
        return dateYearDay(y, 1).plus(days, DAYS);
    }
    int doy = range(DAY_OF_YEAR).checkValidIntValue(fieldValues.remove(DAY_OF_YEAR), DAY_OF_YEAR);
    return dateYearDay(y, doy);  // smart is same as strict
}
项目:jdk8u-jdk    文件:IsoFields.java   
@Override
public ChronoLocalDate resolve(
        Map<TemporalField, Long> fieldValues, TemporalAccessor partialTemporal, ResolverStyle resolverStyle) {
    Long yearLong = fieldValues.get(YEAR);
    Long qoyLong = fieldValues.get(QUARTER_OF_YEAR);
    if (yearLong == null || qoyLong == null) {
        return null;
    }
    int y = YEAR.checkValidIntValue(yearLong);  // always validate
    long doq = fieldValues.get(DAY_OF_QUARTER);
    ensureIso(partialTemporal);
    LocalDate date;
    if (resolverStyle == ResolverStyle.LENIENT) {
        date = LocalDate.of(y, 1, 1).plusMonths(Math.multiplyExact(Math.subtractExact(qoyLong, 1), 3));
        doq = Math.subtractExact(doq, 1);
    } else {
        int qoy = QUARTER_OF_YEAR.range().checkValidIntValue(qoyLong, QUARTER_OF_YEAR);  // validated
        date = LocalDate.of(y, ((qoy - 1) * 3) + 1, 1);
        if (doq < 1 || doq > 90) {
            if (resolverStyle == ResolverStyle.STRICT) {
                rangeRefinedBy(date).checkValidValue(doq, this);  // only allow exact range
            } else {  // SMART
                range().checkValidValue(doq, this);  // allow 1-92 rolling into next quarter
            }
        }
        doq--;
    }
    fieldValues.remove(this);
    fieldValues.remove(YEAR);
    fieldValues.remove(QUARTER_OF_YEAR);
    return date.plusDays(doq);
}
项目:openjdk-jdk10    文件:AbstractChronology.java   
ChronoLocalDate resolveYAA(Map<TemporalField, Long> fieldValues, ResolverStyle resolverStyle) {
    int y = range(YEAR).checkValidIntValue(fieldValues.remove(YEAR), YEAR);
    if (resolverStyle == ResolverStyle.LENIENT) {
        long weeks = Math.subtractExact(fieldValues.remove(ALIGNED_WEEK_OF_YEAR), 1);
        long days = Math.subtractExact(fieldValues.remove(ALIGNED_DAY_OF_WEEK_IN_YEAR), 1);
        return dateYearDay(y, 1).plus(weeks, WEEKS).plus(days, DAYS);
    }
    int aw = range(ALIGNED_WEEK_OF_YEAR).checkValidIntValue(fieldValues.remove(ALIGNED_WEEK_OF_YEAR), ALIGNED_WEEK_OF_YEAR);
    int ad = range(ALIGNED_DAY_OF_WEEK_IN_YEAR).checkValidIntValue(fieldValues.remove(ALIGNED_DAY_OF_WEEK_IN_YEAR), ALIGNED_DAY_OF_WEEK_IN_YEAR);
    ChronoLocalDate date = dateYearDay(y, 1).plus((aw - 1) * 7 + (ad - 1), DAYS);
    if (resolverStyle == ResolverStyle.STRICT && date.get(YEAR) != y) {
        throw new DateTimeException("Strict mode rejected resolved date as it is in a different year");
    }
    return date;
}
项目:jdk8u-jdk    文件:IsoChronology.java   
@Override  // override for enhanced behaviour
LocalDate resolveYearOfEra(Map<TemporalField, Long> fieldValues, ResolverStyle resolverStyle) {
    Long yoeLong = fieldValues.remove(YEAR_OF_ERA);
    if (yoeLong != null) {
        if (resolverStyle != ResolverStyle.LENIENT) {
            YEAR_OF_ERA.checkValidValue(yoeLong);
        }
        Long era = fieldValues.remove(ERA);
        if (era == null) {
            Long year = fieldValues.get(YEAR);
            if (resolverStyle == ResolverStyle.STRICT) {
                // do not invent era if strict, but do cross-check with year
                if (year != null) {
                    addFieldValue(fieldValues, YEAR, (year > 0 ? yoeLong: Math.subtractExact(1, yoeLong)));
                } else {
                    // reinstate the field removed earlier, no cross-check issues
                    fieldValues.put(YEAR_OF_ERA, yoeLong);
                }
            } else {
                // invent era
                addFieldValue(fieldValues, YEAR, (year == null || year > 0 ? yoeLong: Math.subtractExact(1, yoeLong)));
            }
        } else if (era.longValue() == 1L) {
            addFieldValue(fieldValues, YEAR, yoeLong);
        } else if (era.longValue() == 0L) {
            addFieldValue(fieldValues, YEAR, Math.subtractExact(1, yoeLong));
        } else {
            throw new DateTimeException("Invalid value for era: " + era);
        }
    } else if (fieldValues.containsKey(ERA)) {
        ERA.checkValidValue(fieldValues.get(ERA));  // always validated
    }
    return null;
}