IntegerTokenConverter.java (logback-1.2.3) | : | IntegerTokenConverter.java (logback-v_1.2.7) | ||
---|---|---|---|---|
skipping to change at line 17 | skipping to change at line 17 | |||
* the Eclipse Foundation | * the Eclipse Foundation | |||
* | * | |||
* or (per the licensee's choosing) | * or (per the licensee's choosing) | |||
* | * | |||
* under the terms of the GNU Lesser General Public License version 2.1 | * under the terms of the GNU Lesser General Public License version 2.1 | |||
* as published by the Free Software Foundation. | * as published by the Free Software Foundation. | |||
*/ | */ | |||
package ch.qos.logback.core.rolling.helper; | package ch.qos.logback.core.rolling.helper; | |||
import ch.qos.logback.core.pattern.DynamicConverter; | import ch.qos.logback.core.pattern.DynamicConverter; | |||
import ch.qos.logback.core.pattern.FormatInfo; | ||||
/** | /** | |||
* When asked to convert an integer, <code>IntegerTokenConverter</code> the | * When asked to convert an integer, <code>IntegerTokenConverter</code> the | |||
* string value of that integer. | * string value of that integer. | |||
* | * | |||
* @author Ceki Gulcu | * @author Ceki Gulcu | |||
*/ | */ | |||
public class IntegerTokenConverter extends DynamicConverter<Object> implements M onoTypedConverter { | public class IntegerTokenConverter extends DynamicConverter<Object> implements M onoTypedConverter { | |||
public final static String CONVERTER_KEY = "i"; | public final static String CONVERTER_KEY = "i"; | |||
public String convert(int i) { | public String convert(int i) { | |||
return Integer.toString(i); | String s = Integer.toString(i); | |||
FormatInfo formattingInfo = getFormattingInfo(); | ||||
if (formattingInfo == null) { | ||||
return s; | ||||
} | ||||
int min = formattingInfo.getMin(); | ||||
StringBuilder sbuf = new StringBuilder(); | ||||
for (int j = s.length(); j < min; ++j) { | ||||
sbuf.append('0'); | ||||
} | ||||
return sbuf.append(s).toString(); | ||||
} | } | |||
public String convert(Object o) { | public String convert(Object o) { | |||
if (o == null) { | if (o == null) { | |||
throw new IllegalArgumentException("Null argument forbidden"); | throw new IllegalArgumentException("Null argument forbidden"); | |||
} | } | |||
if (o instanceof Integer) { | if (o instanceof Integer) { | |||
Integer i = (Integer) o; | Integer i = (Integer) o; | |||
return convert(i.intValue()); | return convert(i.intValue()); | |||
} | } | |||
End of changes. 2 change blocks. | ||||
1 lines changed or deleted | 12 lines changed or added |