View Javadoc

1   /**
2    * Logback: the reliable, generic, fast and flexible logging framework.
3    * Copyright (C) 1999-2009, QOS.ch. All rights reserved.
4    *
5    * This program and the accompanying materials are dual-licensed under
6    * either the terms of the Eclipse Public License v1.0 as published by
7    * the Eclipse Foundation
8    *
9    *   or (per the licensee's choosing)
10   *
11   * under the terms of the GNU Lesser General Public License version 2.1
12   * as published by the Free Software Foundation.
13   */
14  package ch.qos.logback.core.rolling.helper;
15  
16  import ch.qos.logback.core.pattern.DynamicConverter;
17  
18  /**
19   * When asked to convert an integer, <code>IntegerTokenConverter</code> the
20   * string value of that integer.
21   * 
22   * @author Ceki Gulcu
23   */
24  public class IntegerTokenConverter extends DynamicConverter implements MonoTypedConverter {
25  
26    public final static String CONVERTER_KEY = "i";
27    
28    public IntegerTokenConverter() {
29    }
30  
31    public String convert(int i) {
32      return Integer.toString(i);
33    }
34  
35    public String convert(Object o) {
36      if(o == null) {
37        throw new IllegalArgumentException("Null argument forbidden");
38      }
39      if(o instanceof Integer) {
40        Integer i = (Integer) o;
41        return convert(i.intValue());
42      } 
43      throw new IllegalArgumentException("Cannot convert "+o+" of type"+o.getClass().getName());
44    }
45  
46    public boolean isApplicable(Object o) {
47      return (o instanceof Integer);
48    }
49  }