View Javadoc

1   /**
2    * LOGBack: the reliable, fast and flexible logging library for Java.
3    * 
4    * Copyright (C) 1999-2006, QOS.ch
5    * 
6    * This library is free software, you can redistribute it and/or modify it under
7    * the terms of the GNU Lesser General Public License as published by the Free
8    * Software Foundation.
9    */
10  package ch.qos.logback.core.rolling.helper;
11  
12  import ch.qos.logback.core.pattern.DynamicConverter;
13  
14  /**
15   * When asked to convert an integer, <code>IntegerTokenConverter</code> the
16   * string value of that integer.
17   * 
18   * @author Ceki Gulcu
19   */
20  public class IntegerTokenConverter extends DynamicConverter {
21  
22    public IntegerTokenConverter() {
23    }
24  
25    public String convert(int i) {
26      return Integer.toString(i);
27    }
28  
29    public String convert(Object o) {
30      if(o == null) {
31        throw new IllegalArgumentException("Null argument forbidden");
32      }
33      if(o instanceof Integer) {
34        Integer i = (Integer) o;
35        return convert(i.intValue());
36      }
37      throw new IllegalArgumentException("Cannot convert "+o+" of type"+o.getClass().getName());
38    }
39  }