View Javadoc

1   /*
2    * Copyright (C) 2004 TiongHiang Lee
3    *
4    * This library is free software; you can redistribute it and/or
5    * modify it under the terms of the GNU Lesser General Public
6    * License as published by the Free Software Foundation; either
7    * version 2.1 of the License, or (at your option) any later version.
8    *
9    * This library is distributed in the hope that it will be useful,
10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12   * Lesser General Public License for more details.
13   *
14   * You should have received a copy of the GNU Lesser General Public
15   * License along with this library; if not,  write to the Free Software
16   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17   *
18   * Email: thlee@onemindsoft.org
19   */
20  package org.onemind.commons.java.lang;
21  
22  /***
23   * An mutable integer
24   * @author TiongHiang Lee (thlee@onemindsoft.org)
25   * @version $Id: MutableInteger.java,v 1.3 2004/09/03 13:24:14 thlee Exp $ $Name:  $
26   */
27  public class MutableInteger extends Number
28  {
29  
30      /*** the integer value * */
31      private int _value;
32  
33      /***
34       * {@inheritDoc}
35       * @param l the int value
36       */
37      public MutableInteger(int l)
38      {
39          _value = l;
40      }
41  
42      /***
43       * Set the value
44       * @param l the int value
45       */
46      public final void set(int l)
47      {
48          _value = l;
49      }
50  
51      /***
52       * {@inheritDoc}
53       */
54      public final byte byteValue()
55      {
56          return (byte) _value;
57      }
58  
59      /***
60       * {@inheritDoc}
61       */
62      public final double doubleValue()
63      {
64          return (double) _value;
65      }
66  
67      /***
68       * {@inheritDoc}
69       */
70      public final float floatValue()
71      {
72          return (float) _value;
73      }
74  
75      /***
76       * {@inheritDoc}
77       */
78      public final int intValue()
79      {
80          return _value;
81      }
82  
83      /***
84       * {@inheritDoc}
85       */
86      public final long longValue()
87      {
88          return (long) _value;
89      }
90  
91      /***
92       * {@inheritDoc}
93       */
94      public final short shortValue()
95      {
96          return (short) _value;
97      }
98      
99      /***
100      * increase by i
101      * @param i the value to increase
102      */
103     public void inc(int i)
104     {
105         _value += i;
106     }
107     
108     /***
109      * decrease by i
110      * @param i the value to decrease
111      */
112     public void dec(int i)
113     {
114         _value -= i;
115     }
116     
117     /*** 
118      * {@inheritDoc}
119      */
120     public String toString()
121     {
122         return String.valueOf(_value);
123     }
124 }