LEFT | RIGHT |
1 // © 2016 and later: Unicode, Inc. and others. | 1 // © 2016 and later: Unicode, Inc. and others. |
2 // License & terms of use: http://www.unicode.org/copyright.html#License | 2 // License & terms of use: http://www.unicode.org/copyright.html#License |
3 /* | 3 /* |
4 ******************************************************************************* | 4 ******************************************************************************* |
5 * Copyright (C) 2007-2016, International Business Machines Corporation and | 5 * Copyright (C) 2007-2016, International Business Machines Corporation and |
6 * others. All Rights Reserved. | 6 * others. All Rights Reserved. |
7 ******************************************************************************* | 7 ******************************************************************************* |
8 */ | 8 */ |
9 | 9 |
10 package com.ibm.icu.text; | 10 package com.ibm.icu.text; |
11 | 11 |
12 import java.io.IOException; | 12 import java.io.IOException; |
13 import java.io.ObjectInputStream; | 13 import java.io.ObjectInputStream; |
14 import java.text.FieldPosition; | 14 import java.text.FieldPosition; |
15 import java.text.ParsePosition; | 15 import java.text.ParsePosition; |
16 import java.util.Locale; | 16 import java.util.Locale; |
17 import java.util.Map; | 17 import java.util.Map; |
18 | 18 |
19 import com.ibm.icu.impl.Utility; | 19 import com.ibm.icu.impl.Utility; |
20 import com.ibm.icu.text.PluralRules.FixedDecimal; | 20 import com.ibm.icu.text.PluralRules.FixedDecimal; |
21 import com.ibm.icu.text.PluralRules.IFixedDecimal; | 21 import com.ibm.icu.text.PluralRules.IFixedDecimal; |
| 22 import com.ibm.icu.text.PluralRules.Operand; |
22 import com.ibm.icu.text.PluralRules.PluralType; | 23 import com.ibm.icu.text.PluralRules.PluralType; |
23 import com.ibm.icu.util.ULocale; | 24 import com.ibm.icu.util.ULocale; |
24 import com.ibm.icu.util.ULocale.Category; | 25 import com.ibm.icu.util.ULocale.Category; |
25 | 26 |
26 /** | 27 /** |
27 * <code>PluralFormat</code> supports the creation of internationalized | 28 * <code>PluralFormat</code> supports the creation of internationalized |
28 * messages with plural inflection. It is based on <i>plural | 29 * messages with plural inflection. It is based on <i>plural |
29 * selection</i>, i.e. the caller specifies messages for each | 30 * selection</i>, i.e. the caller specifies messages for each |
30 * plural case that can appear in the user's language and the | 31 * plural case that can appear in the user's language and the |
31 * <code>PluralFormat</code> selects the appropriate message based on | 32 * <code>PluralFormat</code> selects the appropriate message based on |
(...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
548 */ | 549 */ |
549 public String select(Object context, double number); | 550 public String select(Object context, double number); |
550 } | 551 } |
551 | 552 |
552 // See PluralSelector: | 553 // See PluralSelector: |
553 // We could avoid this adapter class if we made PluralSelector public | 554 // We could avoid this adapter class if we made PluralSelector public |
554 // (or at least publicly visible) and had PluralRules implement PluralSelect
or. | 555 // (or at least publicly visible) and had PluralRules implement PluralSelect
or. |
555 private final class PluralSelectorAdapter implements PluralSelector { | 556 private final class PluralSelectorAdapter implements PluralSelector { |
556 @Override | 557 @Override |
557 public String select(Object context, double number) { | 558 public String select(Object context, double number) { |
558 FixedDecimal dec = (FixedDecimal) context; | 559 IFixedDecimal dec = (IFixedDecimal) context; |
559 assert dec.source == (dec.isNegative ? -number : number); | 560 assert dec.getPluralOperand(Operand.n) == Math.abs(number); |
560 return pluralRules.select(dec); | 561 return pluralRules.select(dec); |
561 } | 562 } |
562 } | 563 } |
563 transient private PluralSelectorAdapter pluralRulesWrapper = new PluralSelec
torAdapter(); | 564 transient private PluralSelectorAdapter pluralRulesWrapper = new PluralSelec
torAdapter(); |
564 | 565 |
565 /** | 566 /** |
566 * Formats a plural message for a given number. | 567 * Formats a plural message for a given number. |
567 * | 568 * |
568 * @param number a number for which the plural message should be formatted. | 569 * @param number a number for which the plural message should be formatted. |
569 * If no pattern has been applied to this | 570 * If no pattern has been applied to this |
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
865 in.defaultReadObject(); | 866 in.defaultReadObject(); |
866 pluralRulesWrapper = new PluralSelectorAdapter(); | 867 pluralRulesWrapper = new PluralSelectorAdapter(); |
867 // Ignore the parsedValues from an earlier class version (before ICU 4.8
) | 868 // Ignore the parsedValues from an earlier class version (before ICU 4.8
) |
868 // and rebuild the msgPattern. | 869 // and rebuild the msgPattern. |
869 parsedValues = null; | 870 parsedValues = null; |
870 if (pattern != null) { | 871 if (pattern != null) { |
871 applyPattern(pattern); | 872 applyPattern(pattern); |
872 } | 873 } |
873 } | 874 } |
874 } | 875 } |
LEFT | RIGHT |