private TypeSpec create ( NumberData data , UnitData unitData , String className ) { LocaleID id = data . id ( ) ; // TODO: add descriptive javadoc to type TypeSpec . Builder type = TypeSpec . classBuilder ( className ) . superclass ( NUMBER_FORMATTER_BASE ) . addModifiers ( Modifier . PUBLIC ) ; // Build the constructor's code block String fmt = "super(\n" ; List < Object > args = new ArrayList <> ( ) ; fmt += "$T.$L,\n" ; args . add ( CLDR_LOCALE_IF ) ; args . add ( id . safe ) ; fmt += "new _Params(),\n" ; fmt += "// decimal standard\n" ; fmt += "patterns($S, $S),\n" ; args . addAll ( getPatterns ( data . decimalFormatStandard ) ) ; fmt += "// percent standard\n" ; fmt += "patterns($S, $S),\n" ; args . addAll ( getPatterns ( data . percentFormatStandard ) ) ; fmt += "// currency standard\n" ; fmt += "patterns($S, $S),\n" ; args . addAll ( getPatterns ( data . currencyFormatStandard ) ) ; fmt += "// currency accounting\n" ; fmt += "patterns($S, $S),\n" ; args . addAll ( getPatterns ( data . currencyFormatAccounting ) ) ; fmt += "// units standard\n" ; fmt += "patterns($S, $S)\n" ; List < NumberPattern > unitPatterns = data . decimalFormatStandard . stream ( ) . map ( p -> { p = NUMBER_PARSER . parse ( p . render ( ) ) ; p . format ( ) . setMaximumFractionDigits ( 1 ) ; p . format ( ) . setMinimumFractionDigits ( 0 ) ; return p ; } ) . collect ( Collectors . toList ( ) ) ; args . addAll ( getPatterns ( unitPatterns ) ) ; fmt += ")" ; // Build the constructor. MethodSpec . Builder code = MethodSpec . constructorBuilder ( ) . addModifiers ( PUBLIC ) . addStatement ( fmt , args . toArray ( ) ) ; type . addMethod ( code . build ( ) ) ; // Create a private instance of the NumberFormatterParams type addParams ( type , id , data ) ; addCompactPattern ( type , "DECIMAL_SHORT" , data . decimalFormatShort , false , data ) ; addCompactPattern ( type , "DECIMAL_LONG" , data . decimalFormatLong , false , data ) ; addCompactPattern ( type , "CURRENCY_SHORT" , data . currencyFormatShort , true , data ) ; addUnitPattern ( type , "UNITS_LONG" , unitData . long_ ) ; addUnitPattern ( type , "UNITS_NARROW" , unitData . narrow ) ; addUnitPattern ( type , "UNITS_SHORT" , unitData . short_ ) ; addCurrencyInfo ( type , data ) ; addUnitWrappers ( type , data ) ; return type . build ( ) ; }
Creates a number formatter class .