+/**
+ * Set one of the non-numerical rules.
+ * @param rule The rule to set.
+ */
+void NFRuleSet::setNonNumericalRule(NFRule *rule) {
+ int64_t baseValue = rule->getBaseValue();
+ if (baseValue == NFRule::kNegativeNumberRule) {
+ delete nonNumericalRules[NEGATIVE_RULE_INDEX];
+ nonNumericalRules[NEGATIVE_RULE_INDEX] = rule;
+ }
+ else if (baseValue == NFRule::kImproperFractionRule) {
+ setBestFractionRule(IMPROPER_FRACTION_RULE_INDEX, rule, TRUE);
+ }
+ else if (baseValue == NFRule::kProperFractionRule) {
+ setBestFractionRule(PROPER_FRACTION_RULE_INDEX, rule, TRUE);
+ }
+ else if (baseValue == NFRule::kMasterRule) {
+ setBestFractionRule(MASTER_RULE_INDEX, rule, TRUE);
+ }
+ else if (baseValue == NFRule::kInfinityRule) {
+ delete nonNumericalRules[INFINITY_RULE_INDEX];
+ nonNumericalRules[INFINITY_RULE_INDEX] = rule;
+ }
+ else if (baseValue == NFRule::kNaNRule) {
+ delete nonNumericalRules[NAN_RULE_INDEX];
+ nonNumericalRules[NAN_RULE_INDEX] = rule;
+ }
+}
+
+/**
+ * Determine the best fraction rule to use. Rules matching the decimal point from
+ * DecimalFormatSymbols become the main set of rules to use.
+ * @param originalIndex The index into nonNumericalRules
+ * @param newRule The new rule to consider
+ * @param rememberRule Should the new rule be added to fractionRules.
+ */
+void NFRuleSet::setBestFractionRule(int32_t originalIndex, NFRule *newRule, UBool rememberRule) {
+ if (rememberRule) {
+ fractionRules.add(newRule);
+ }
+ NFRule *bestResult = nonNumericalRules[originalIndex];
+ if (bestResult == NULL) {
+ nonNumericalRules[originalIndex] = newRule;
+ }
+ else {
+ // We have more than one. Which one is better?
+ const DecimalFormatSymbols *decimalFormatSymbols = owner->getDecimalFormatSymbols();
+ if (decimalFormatSymbols->getSymbol(DecimalFormatSymbols::kDecimalSeparatorSymbol).charAt(0)
+ == newRule->getDecimalPoint())
+ {
+ nonNumericalRules[originalIndex] = newRule;
+ }
+ // else leave it alone
+ }
+}
+