1 package com.sharkysoft.printf;
2
3 import java.math.BigInteger;
4 import com.sharkysoft.printf.engine.IntegerFormatter;
5
6 abstract class Formatter_Integer extends Formatter_Number
7 {
8
9 Formatter_Integer(final FormatSpecifier ipPfs)
10 {
11 super(ipPfs, new IntegerFormatter());
12 final IntegerFormatter vpFormatter = (IntegerFormatter) mpFormatter;
13 if (ipPfs.mnPrecision == FormatSpecifier.PRECISION_UNSPECIFIED)
14 vpFormatter.setMinDigits(1);
15 else
16 vpFormatter.setMinDigits(ipPfs.mnPrecision);
17 }
18
19 void adjustWidthAndPrecision(final PrintfState ipPs)
20 {
21 adjustWidth(ipPs);
22 if (mzVariablePrecision)
23 ( (IntegerFormatter) mpFormatter
24 ).setMinDigits
25 ( ((Number) ipPs.mapArgs[ipPs.mnArgIndex++]).intValue()
26 );
27 }
28
29 void formatSignedInt(final PrintfState ipPs)
30 {
31 adjustWidthAndPrecision(ipPs);
32 ipPs.mpOutput.append
33 ( ( (IntegerFormatter) mpFormatter
34 ).format
35 ( ((Number) ipPs.mapArgs[ipPs.mnArgIndex++]).intValue()
36 )
37 );
38 }
39
40 void formatSignedLong(final PrintfState ipPs)
41 {
42 adjustWidthAndPrecision(ipPs);
43 ipPs.mpOutput.append
44 ( ( (IntegerFormatter) mpFormatter
45 ).format
46 ( ((Number) ipPs.mapArgs[ipPs.mnArgIndex++]).longValue()
47 )
48 );
49 }
50
51 void formatSignedShort(final PrintfState ipPs)
52 {
53 adjustWidthAndPrecision(ipPs);
54 ipPs.mpOutput.append
55 ( ( (IntegerFormatter) mpFormatter
56 ).format
57 ( ((Number) ipPs.mapArgs[ipPs.mnArgIndex++]).shortValue()
58 )
59 );
60 }
61
62 void formatSignedByte(final PrintfState ipPs)
63 {
64 adjustWidthAndPrecision(ipPs);
65 ipPs.mpOutput.append
66 ( ( (IntegerFormatter) mpFormatter
67 ).format
68 ( ((Number) ipPs.mapArgs[ipPs.mnArgIndex++]).byteValue()
69 )
70 );
71 }
72
73 void formatSignedBigInteger(final PrintfState ipPs)
74 {
75 adjustWidthAndPrecision(ipPs);
76 ipPs.mpOutput.append
77 ( ( (IntegerFormatter) mpFormatter
78 ).format
79 ( (BigInteger) ipPs.mapArgs[ipPs.mnArgIndex++]
80 )
81 );
82 }
83
84 void formatUnsignedInt(final PrintfState ipPs)
85 {
86 adjustWidthAndPrecision(ipPs);
87 ipPs.mpOutput.append
88 ( ( (IntegerFormatter) mpFormatter
89 ).formatUnsigned
90 ( ((Number) ipPs.mapArgs[ipPs.mnArgIndex++]).intValue()
91 )
92 );
93 }
94
95 void formatUnsignedLong(final PrintfState ipPs)
96 {
97 adjustWidthAndPrecision(ipPs);
98 ipPs.mpOutput.append
99 ( ( (IntegerFormatter) mpFormatter
100 ).formatUnsigned
101 ( ((Number) ipPs.mapArgs[ipPs.mnArgIndex++]).longValue()
102 )
103 );
104 }
105
106 void formatUnsignedShort(final PrintfState ipPs)
107 {
108 adjustWidthAndPrecision(ipPs);
109 ipPs.mpOutput.append
110 ( ( (IntegerFormatter) mpFormatter
111 ).formatUnsigned
112 ( ((Number) ipPs.mapArgs[ipPs.mnArgIndex++]).shortValue()
113 )
114 );
115 }
116
117 void formatUnsignedByte(final PrintfState ipPs)
118 {
119 adjustWidthAndPrecision(ipPs);
120 ipPs.mpOutput.append
121 ( ( (IntegerFormatter) mpFormatter
122 ).formatUnsigned
123 ( ((Number) ipPs.mapArgs[ipPs.mnArgIndex++]).byteValue()
124 )
125 );
126 }
127
128 void formatUnsignedBigInteger(final PrintfState ipPs)
129 {
130 adjustWidthAndPrecision(ipPs);
131 final BigInteger vpBi = (BigInteger) ipPs.mapArgs[ipPs.mnArgIndex++];
132 ipPs.mpOutput.append(((IntegerFormatter) mpFormatter).format(vpBi));
133 }
134 }
135