1   /**
2    * Distribution License:
3    * This is free software; you can redistribute it and/or modify it under
4    * the terms of the GNU Lesser General Public License, version 2.1 as published
5    * by the Free Software Foundation. This program is distributed in the hope
6    * that it will be useful, but WITHOUT ANY WARRANTY; without even the
7    * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
8    * See the GNU Lesser General Public License for more details.
9    *
10   * The License is available on the internet at:
11   *       http://www.gnu.org/copyleft/llgpl.html
12   * or by writing to:
13   *      Free Software Foundation, Inc.
14   *      59 Temple Place - Suite 330
15   *      Boston, MA 02111-1307, USA
16   *
17   * Copyright: 2005
18   *     The copyright to this program is held by it's authors.
19   *
20   * ID: $Id: NumberChoice.java 2050 2010-12-09 15:31:45Z dmsmith $
21   */
22  package org.crosswire.common.config;
23  
24  import org.crosswire.common.util.Convert;
25  
26  /**
27   * A class to convert between strings and objects of a type.
28   * 
29   * @see gnu.lgpl.License for license details.<br>
30   *      The copyright to this program is held by it's authors.
31   * @author Joe Walker [joe at eireneh dot com]
32   */
33  public class NumberChoice extends AbstractReflectedChoice {
34      /*
35       * (non-Javadoc)
36       * 
37       * @see org.crosswire.common.config.Choice#getConvertionClass()
38       */
39      public Class<Integer> getConversionClass() {
40          return Integer.TYPE;
41      }
42  
43      /*
44       * (non-Javadoc)
45       * 
46       * @see
47       * org.crosswire.common.config.AbstractReflectedChoice#convertToString(java
48       * .lang.Object)
49       */
50      @Override
51      public String convertToString(Object orig) {
52          return Convert.int2String(((Integer) orig).intValue());
53      }
54  
55      /*
56       * (non-Javadoc)
57       * 
58       * @see
59       * org.crosswire.common.config.AbstractReflectedChoice#convertToObject(java
60       * .lang.String)
61       */
62      @Override
63      public Object convertToObject(String orig) {
64          return Integer.valueOf(Convert.string2Int(orig));
65      }
66  }
67