1
2
3
4
5
6
7
8
9
10
11
12
13
14 package ch.qos.logback.core.rolling.helper;
15
16 import ch.qos.logback.core.pattern.DynamicConverter;
17 import ch.qos.logback.core.pattern.FormatInfo;
18
19
20
21
22
23
24
25 public class IntegerTokenConverter extends DynamicConverter<Object> implements MonoTypedConverter {
26
27 public final static String CONVERTER_KEY = "i";
28
29 public String convert(int i) {
30 String s = Integer.toString(i);
31 FormatInfo formattingInfo = getFormattingInfo();
32 if (formattingInfo == null) {
33 return s;
34 }
35 int min = formattingInfo.getMin();
36 StringBuilder sbuf = new StringBuilder();
37 for (int j = s.length(); j < min; ++j) {
38 sbuf.append('0');
39 }
40 return sbuf.append(s).toString();
41 }
42
43 public String convert(Object o) {
44 if (o == null) {
45 throw new IllegalArgumentException("Null argument forbidden");
46 }
47 if (o instanceof Integer) {
48 Integer i = (Integer) o;
49 return convert(i.intValue());
50 }
51 throw new IllegalArgumentException("Cannot convert " + o + " of type" + o.getClass().getName());
52 }
53
54 public boolean isApplicable(Object o) {
55 return (o instanceof Integer);
56 }
57 }