private PluralCategory getCategory(long amount) { return this.rules.getCategory(Math.abs(amount)); }
/** * <p>Registers given plural rules for a language, possibly overriding * CLDR-default setting. </p> * * @param locale language or country which the rules shall be assigned to * @param rules localized plural rules * @since 1.2 */ /*[deutsch] * <p>Registriert die angegebenen Pluralregeln für eine Sprache, * wobei die CLDR-Vorgabe überschrieben werden kann. </p> * * @param locale language or country which the rules shall be assigned to * @param rules localized plural rules * @since 1.2 */ public static void register( Locale locale, PluralRules rules ) { Map<String, PluralRules> map = getRuleMap(rules.getNumberType()); String key = locale.getLanguage(); String region = FormatUtils.getRegion(locale); if (!region.isEmpty()) { key = toKey(key, region); } map.put(key, rules); }
private PrettyTime( Locale loc, TimeSource<?> refClock, char zeroDigit, String minusSign, IsoUnit emptyUnit, boolean weekToDays, boolean shortStyle ) { super(); if (emptyUnit == null) { throw new NullPointerException("Missing zero time unit."); } else if (refClock == null) { throw new NullPointerException("Missing reference clock."); } // throws NPE if language == null this.rules = PluralRules.of(loc, NumberType.CARDINALS); this.locale = loc; this.refClock = refClock; this.zeroDigit = zeroDigit; this.emptyUnit = emptyUnit; this.minusSign = minusSign; this.weekToDays = weekToDays; this.shortStyle = shortStyle; }
) { Map<String, PluralRules> map = getRuleMap(numType); PluralRules rules = null; String region = FormatUtils.getRegion(locale); if (!region.isEmpty()) { rules = map.get(toKey(locale.getLanguage(), region));
@Override void print( TimeSpan<? super U> duration, Appendable buffer ) throws IOException { this.numItem.print(duration, buffer); this.sepItem.print(duration, buffer); PluralCategory category = this.rules.getCategory(this.numItem.getAmount(duration)); buffer.append(this.pluralForms.get(category)); }
PluralRules rules = PluralRules.of(loc, NumberType.CARDINALS);
@Override int parse( Map<Object, Long> unitsToValues, CharSequence text, int pos ) { int start = pos; pos = this.numItem.parse(unitsToValues, text, pos); if (pos < 0) { return pos; } pos = this.sepItem.parse(unitsToValues, text, pos); if (pos < 0) { return pos; } long value = unitsToValues.get(this.numItem.getUnit()).longValue(); String s = this.pluralForms.get(this.rules.getCategory(value)); int n = s.length(); if (pos + n > text.length() - this.getReserved()) { return ~start; } for (int i = 0; i < n; i++) { if (s.charAt(i) != text.charAt(pos + i)) { return ~start; } } return pos + n; }