public static NFSubstitution makeSubstitution ( int pos , NFRule rule , NFRule rulePredecessor , NFRuleSet ruleSet , RuleBasedNumberFormat formatter , String description ) { // if the description is empty, return a NullSubstitution if ( description . length ( ) == 0 ) { return null ; } switch ( description . charAt ( 0 ) ) { case ' ' : if ( rule . getBaseValue ( ) == NFRule . NEGATIVE_NUMBER_RULE ) { // throw an exception if the rule is a negative number rule ///CLOVER:OFF // If you look at the call hierarchy of this method, the rule would // never be directly modified by the user and therefore makes the // following pointless unless the user changes the ruleset. throw new IllegalArgumentException ( "<< not allowed in negative-number rule" ) ; ///CLOVER:ON } else if ( rule . getBaseValue ( ) == NFRule . IMPROPER_FRACTION_RULE || rule . getBaseValue ( ) == NFRule . PROPER_FRACTION_RULE || rule . getBaseValue ( ) == NFRule . MASTER_RULE ) { // if the rule is a fraction rule, return an IntegralPartSubstitution return new IntegralPartSubstitution ( pos , ruleSet , description ) ; } else if ( ruleSet . isFractionSet ( ) ) { // if the rule set containing the rule is a fraction // rule set, return a NumeratorSubstitution return new NumeratorSubstitution ( pos , rule . getBaseValue ( ) , formatter . getDefaultRuleSet ( ) , description ) ; } else { // otherwise, return a MultiplierSubstitution return new MultiplierSubstitution ( pos , rule , ruleSet , description ) ; } case ' ' : if ( rule . getBaseValue ( ) == NFRule . NEGATIVE_NUMBER_RULE ) { // if the rule is a negative-number rule, return // an AbsoluteValueSubstitution return new AbsoluteValueSubstitution ( pos , ruleSet , description ) ; } else if ( rule . getBaseValue ( ) == NFRule . IMPROPER_FRACTION_RULE || rule . getBaseValue ( ) == NFRule . PROPER_FRACTION_RULE || rule . getBaseValue ( ) == NFRule . MASTER_RULE ) { // if the rule is a fraction rule, return a // FractionalPartSubstitution return new FractionalPartSubstitution ( pos , ruleSet , description ) ; } else if ( ruleSet . isFractionSet ( ) ) { // if the rule set owning the rule is a fraction rule set, // throw an exception ///CLOVER:OFF // If you look at the call hierarchy of this method, the rule would // never be directly modified by the user and therefore makes the // following pointless unless the user changes the ruleset. throw new IllegalArgumentException ( ">> not allowed in fraction rule set" ) ; ///CLOVER:ON } else { // otherwise, return a ModulusSubstitution return new ModulusSubstitution ( pos , rule , rulePredecessor , ruleSet , description ) ; } case ' ' : return new SameValueSubstitution ( pos , ruleSet , description ) ; default : // and if it's anything else, throw an exception ///CLOVER:OFF // If you look at the call hierarchy of this method, the rule would // never be directly modified by the user and therefore makes the // following pointless unless the user changes the ruleset. throw new IllegalArgumentException ( "Illegal substitution character" ) ; ///CLOVER:ON } }
Parses the description creates the right kind of substitution and initializes it based on the description .