static AttributeSet createDefaults(Chronology<?> chronology, Locale locale) { Attributes.Builder builder = new Attributes.Builder(chronology); builder.set(Attributes.LENIENCY, Leniency.SMART); builder.set(Attributes.TEXT_WIDTH, TextWidth.WIDE); builder.set(Attributes.OUTPUT_CONTEXT, OutputContext.FORMAT); builder.set(Attributes.PAD_CHAR, ' '); AttributeSet as = new AttributeSet(builder.build(), locale); return as.withLocale(locale); }
/** * Setzt die Sprach- und Ländereinstellung. * * <p>Die Attribute {@link Attributes#ZERO_DIGIT}, {@link Attributes#DECIMAL_SEPARATOR} und {@link * Attributes#LANGUAGE} werden automatisch mit angepasst. * * @param locale new language and country setting * @return this instance for method chaining */ AttributeSet withLocale(Locale locale) { Attributes.Builder builder = new Attributes.Builder(); builder.setAll(this.attributes); if (locale.getLanguage().isEmpty() && locale.getCountry().isEmpty()) { locale = Locale.ROOT; builder.set(Attributes.ZERO_DIGIT, '0'); builder.set(Attributes.DECIMAL_SEPARATOR, ISO_DECIMAL_SEPARATOR); } else { NumericalSymbols symbols = NUMBER_SYMBOL_CACHE.get(locale); if (symbols == null) { symbols = DEFAULT_NUMERICAL_SYMBOLS; for (Locale test : NUMBER_SYMBOLS.getAvailableLocales()) { if (locale.equals(test)) { symbols = new NumericalSymbols( NUMBER_SYMBOLS.getZeroDigit(locale), NUMBER_SYMBOLS.getDecimalSeparator(locale)); break; } } NumericalSymbols old = NUMBER_SYMBOL_CACHE.putIfAbsent(locale, symbols); if (old != null) { symbols = old; } } builder.set(Attributes.ZERO_DIGIT, symbols.zeroDigit); builder.set(Attributes.DECIMAL_SEPARATOR, symbols.decimalSeparator); } builder.setLanguage(locale); return new AttributeSet( builder.build(), locale, this.level, this.section, this.printCondition, this.cutover); }