Home | History | Annotate | Download | only in number
      1 //  2017 and later: Unicode, Inc. and others.
      2 // License & terms of use: http://www.unicode.org/copyright.html#License
      3 package com.ibm.icu.impl.number;
      4 
      5 import com.ibm.icu.impl.Utility;
      6 import com.ibm.icu.number.Grouper;
      7 import com.ibm.icu.number.IntegerWidth;
      8 import com.ibm.icu.number.Notation;
      9 import com.ibm.icu.number.NumberFormatter.DecimalSeparatorDisplay;
     10 import com.ibm.icu.number.NumberFormatter.SignDisplay;
     11 import com.ibm.icu.number.NumberFormatter.UnitWidth;
     12 import com.ibm.icu.number.Rounder;
     13 import com.ibm.icu.text.PluralRules;
     14 import com.ibm.icu.util.MeasureUnit;
     15 import com.ibm.icu.util.ULocale;
     16 
     17 public class MacroProps implements Cloneable {
     18   public Notation notation;
     19   public MeasureUnit unit;
     20   public Rounder rounder;
     21   public Grouper grouper;
     22   public Padder padder;
     23   public IntegerWidth integerWidth;
     24   public Object symbols;
     25   public UnitWidth unitWidth;
     26   public SignDisplay sign;
     27   public DecimalSeparatorDisplay decimal;
     28   public AffixPatternProvider affixProvider; // not in API; for JDK compatibility mode only
     29   public MultiplierImpl multiplier; // not in API; for JDK compatibility mode only
     30   public PluralRules rules; // not in API; could be made public in the future
     31   public Long threshold; // not in API; controls internal self-regulation threshold
     32   public ULocale loc;
     33 
     34   /**
     35    * Copies values from fallback into this instance if they are null in this instance.
     36    *
     37    * @param fallback The instance to copy from; not modified by this operation.
     38    */
     39   public void fallback(MacroProps fallback) {
     40     if (notation == null) notation = fallback.notation;
     41     if (unit == null) unit = fallback.unit;
     42     if (rounder == null) rounder = fallback.rounder;
     43     if (grouper == null) grouper = fallback.grouper;
     44     if (padder == null) padder = fallback.padder;
     45     if (integerWidth == null) integerWidth = fallback.integerWidth;
     46     if (symbols == null) symbols = fallback.symbols;
     47     if (unitWidth == null) unitWidth = fallback.unitWidth;
     48     if (sign == null) sign = fallback.sign;
     49     if (decimal == null) decimal = fallback.decimal;
     50     if (affixProvider == null) affixProvider = fallback.affixProvider;
     51     if (multiplier == null) multiplier = fallback.multiplier;
     52     if (rules == null) rules = fallback.rules;
     53     if (loc == null) loc = fallback.loc;
     54   }
     55 
     56   @Override
     57   public int hashCode() {
     58     return Utility.hash(
     59         notation,
     60         unit,
     61         rounder,
     62         grouper,
     63         padder,
     64         integerWidth,
     65         symbols,
     66         unitWidth,
     67         sign,
     68         decimal,
     69         affixProvider,
     70         multiplier,
     71         rules,
     72         loc);
     73   }
     74 
     75   @Override
     76   public boolean equals(Object _other) {
     77     if (_other == null) return false;
     78     if (this == _other) return true;
     79     if (!(_other instanceof MacroProps)) return false;
     80     MacroProps other = (MacroProps) _other;
     81     return Utility.equals(notation, other.notation)
     82         && Utility.equals(unit, other.unit)
     83         && Utility.equals(rounder, other.rounder)
     84         && Utility.equals(grouper, other.grouper)
     85         && Utility.equals(padder, other.padder)
     86         && Utility.equals(integerWidth, other.integerWidth)
     87         && Utility.equals(symbols, other.symbols)
     88         && Utility.equals(unitWidth, other.unitWidth)
     89         && Utility.equals(sign, other.sign)
     90         && Utility.equals(decimal, other.decimal)
     91         && Utility.equals(affixProvider, other.affixProvider)
     92         && Utility.equals(multiplier, other.multiplier)
     93         && Utility.equals(rules, other.rules)
     94         && Utility.equals(loc, other.loc);
     95   }
     96 
     97   @Override
     98   public Object clone() {
     99     // TODO: Remove this method?
    100     try {
    101       return super.clone();
    102     } catch (CloneNotSupportedException e) {
    103       throw new AssertionError(e);
    104     }
    105   }
    106 }
    107