8210633: Cannot parse JapaneseDate string with DateTimeFormatterBuilder Mapped-values

Reviewed-by: scolebourne, rriggs
This commit is contained in:
Naoto Sato 2018-09-25 13:57:24 -07:00
parent 9d95755584
commit ff3f48d69f
2 changed files with 24 additions and 7 deletions

View file

@ -802,7 +802,13 @@ public final class DateTimeFormatterBuilder {
return store.getText(value, style);
}
@Override
public Iterator<Entry<String, Long>> getTextIterator(TemporalField field, TextStyle style, Locale locale) {
public Iterator<Entry<String, Long>> getTextIterator(Chronology chrono,
TemporalField field, TextStyle style, Locale locale) {
return store.getTextIterator(style);
}
@Override
public Iterator<Entry<String, Long>> getTextIterator(TemporalField field,
TextStyle style, Locale locale) {
return store.getTextIterator(style);
}
};

View file

@ -74,9 +74,11 @@ import java.time.chrono.ThaiBuddhistChronology;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeFormatterBuilder;
import java.time.format.FormatStyle;
import java.time.format.ResolverStyle;
import java.time.LocalDate;
import java.time.temporal.ChronoField;
import java.time.temporal.Temporal;
import java.time.temporal.TemporalAccessor;
import java.util.HashMap;
import java.util.Locale;
@ -133,13 +135,22 @@ public class TestDateTimeFormatterBuilderWithLocale {
@Test(dataProvider="mapTextLookup")
public void test_appendText_mapTextLookup(ChronoLocalDate date, Locale locale) {
final String new1st = "1st";
Map<Long, String> yearMap = new HashMap<>();
yearMap.put(1L, new1st);
builder.appendText(ChronoField.YEAR_OF_ERA, yearMap);
final String firstYear = "firstYear";
final String firstMonth = "firstMonth";
final String firstYearMonth = firstYear + firstMonth;
final long first = 1L;
String actual = date.format(builder.toFormatter(locale));
assertEquals(actual, new1st);
DateTimeFormatter formatter = builder
.appendText(ChronoField.YEAR_OF_ERA, Map.of(first, firstYear))
.appendText(ChronoField.MONTH_OF_YEAR, Map.of(first, firstMonth))
.toFormatter(locale)
.withResolverStyle(ResolverStyle.STRICT);
assertEquals(date.format(formatter), firstYearMonth);
TemporalAccessor ta = formatter.parse(firstYearMonth);
assertEquals(ta.getLong(ChronoField.YEAR_OF_ERA), first);
assertEquals(ta.getLong(ChronoField.MONTH_OF_YEAR), first);
}