public TypeSpec createCurrencyUtil ( String className , Map < String , CurrencyData > currencies ) { TypeSpec . Builder type = TypeSpec . classBuilder ( className ) . addModifiers ( Modifier . PUBLIC ) ; CurrencyData defaultData = currencies . get ( "DEFAULT" ) ; currencies . remove ( "DEFAULT" ) ; MethodSpec . Builder code = MethodSpec . methodBuilder ( "getCurrencyDigits" ) . addModifiers ( PUBLIC , STATIC ) . addParameter ( Types . CLDR_CURRENCY_ENUM , "code" ) . returns ( int . class ) ; code . beginControlFlow ( "switch (code)" ) ; for ( Map . Entry < String , CurrencyData > entry : currencies . entrySet ( ) ) { CurrencyData data = entry . getValue ( ) ; code . addStatement ( "case $L: return $L" , entry . getKey ( ) , data . digits ) ; } code . addStatement ( "default: return $L" , defaultData . digits ) ; code . endControlFlow ( ) ; type . addMethod ( code . build ( ) ) ; return type . build ( ) ; }
Create class to hold global currency information .