755 * <p>
756 * Other uses might be to output the value with a suffix, such as "1st", "2nd", "3rd",
757 * or as Roman numerals "I", "II", "III", "IV".
758 * <p>
759 * During formatting, the value is obtained and checked that it is in the valid range.
760 * If text is not available for the value then it is output as a number.
761 * During parsing, the parser will match against the map of text and numeric values.
762 *
763 * @param field the field to append, not null
764 * @param textLookup the map from the value to the text
765 * @return this, for chaining, not null
766 */
767 public DateTimeFormatterBuilder appendText(TemporalField field, Map<Long, String> textLookup) {
768 Objects.requireNonNull(field, "field");
769 Objects.requireNonNull(textLookup, "textLookup");
770 Map<Long, String> copy = new LinkedHashMap<>(textLookup);
771 Map<TextStyle, Map<Long, String>> map = Collections.singletonMap(TextStyle.FULL, copy);
772 final LocaleStore store = new LocaleStore(map);
773 DateTimeTextProvider provider = new DateTimeTextProvider() {
774 @Override
775 public String getText(TemporalField field, long value, TextStyle style, Locale locale) {
776 return store.getText(value, style);
777 }
778 @Override
779 public Iterator<Entry<String, Long>> getTextIterator(TemporalField field, TextStyle style, Locale locale) {
780 return store.getTextIterator(style);
781 }
782 };
783 appendInternal(new TextPrinterParser(field, TextStyle.FULL, provider));
784 return this;
785 }
786
787 //-----------------------------------------------------------------------
788 /**
789 * Appends an instant using ISO-8601 to the formatter, formatting fractional
790 * digits in groups of three.
791 * <p>
792 * Instants have a fixed output format.
793 * They are converted to a date-time with a zone-offset of UTC and formatted
794 * using the standard ISO-8601 format.
795 * With this method, formatting nano-of-second outputs zero, three, six
796 * or nine digits digits as necessary.
797 * The localized decimal style is not used.
798 * <p>
799 * The instant is obtained using {@link ChronoField#INSTANT_SECONDS INSTANT_SECONDS}
|
755 * <p>
756 * Other uses might be to output the value with a suffix, such as "1st", "2nd", "3rd",
757 * or as Roman numerals "I", "II", "III", "IV".
758 * <p>
759 * During formatting, the value is obtained and checked that it is in the valid range.
760 * If text is not available for the value then it is output as a number.
761 * During parsing, the parser will match against the map of text and numeric values.
762 *
763 * @param field the field to append, not null
764 * @param textLookup the map from the value to the text
765 * @return this, for chaining, not null
766 */
767 public DateTimeFormatterBuilder appendText(TemporalField field, Map<Long, String> textLookup) {
768 Objects.requireNonNull(field, "field");
769 Objects.requireNonNull(textLookup, "textLookup");
770 Map<Long, String> copy = new LinkedHashMap<>(textLookup);
771 Map<TextStyle, Map<Long, String>> map = Collections.singletonMap(TextStyle.FULL, copy);
772 final LocaleStore store = new LocaleStore(map);
773 DateTimeTextProvider provider = new DateTimeTextProvider() {
774 @Override
775 public String getText(Chronology chrono, TemporalField field,
776 long value, TextStyle style, Locale locale) {
777 return store.getText(value, style);
778 }
779 @Override
780 public String getText(TemporalField field, long value, TextStyle style, Locale locale) {
781 return store.getText(value, style);
782 }
783 @Override
784 public Iterator<Entry<String, Long>> getTextIterator(Chronology chrono,
785 TemporalField field, TextStyle style, Locale locale) {
786 return store.getTextIterator(style);
787 }
788 @Override
789 public Iterator<Entry<String, Long>> getTextIterator(TemporalField field,
790 TextStyle style, Locale locale) {
791 return store.getTextIterator(style);
792 }
793 };
794 appendInternal(new TextPrinterParser(field, TextStyle.FULL, provider));
795 return this;
796 }
797
798 //-----------------------------------------------------------------------
799 /**
800 * Appends an instant using ISO-8601 to the formatter, formatting fractional
801 * digits in groups of three.
802 * <p>
803 * Instants have a fixed output format.
804 * They are converted to a date-time with a zone-offset of UTC and formatted
805 * using the standard ISO-8601 format.
806 * With this method, formatting nano-of-second outputs zero, three, six
807 * or nine digits digits as necessary.
808 * The localized decimal style is not used.
809 * <p>
810 * The instant is obtained using {@link ChronoField#INSTANT_SECONDS INSTANT_SECONDS}
|