1 32 package net.sf.retrotranslator.runtime.format; 33 34 import java.math.BigInteger ; 35 import java.text.DecimalFormatSymbols ; 36 37 40 class DecimalIntegralConversion extends NumericConversion { 41 42 public void format(FormatContext context) { 43 context.assertNoPrecision(); 44 context.assertNoFlag('#'); 45 context.checkWidth(); 46 context.checkFlags(); 47 Object argument = context.getArgument(); 48 if (argument instanceof Byte ) { 49 printf(context, (Byte ) argument); 50 } else if (argument instanceof Short ) { 51 printf(context, (Short ) argument); 52 } else if (argument instanceof Integer ) { 53 printf(context, (Integer ) argument); 54 } else if (argument instanceof Long ) { 55 printf(context, (Long ) argument); 56 } else if (argument instanceof BigInteger ) { 57 printf(context, (BigInteger ) argument); 58 } else if (argument == null) { 59 context.writePadded(String.valueOf(argument)); 60 } else { 61 throw context.getConversionException(); 62 } 63 } 64 65 private void printf(FormatContext context, long argument) { 66 printf(context, BigInteger.valueOf(argument)); 67 } 68 69 private void printf(FormatContext context, BigInteger argument) { 70 DecimalFormatSymbols symbols = context.getSymbols(true); 71 StringBuilder builder = new StringBuilder (); 72 appendNumber(builder, argument.abs().toString(), context.isFlag(','), symbols); 73 printNumber(context, argument.signum() < 0, null, builder, symbols); 74 } 75 76 } 77 | Popular Tags |