View Javadoc

1   /*
2    * Copyright (C) 2004-2006 Christian Siefkes <christian@siefkes.net>.
3    * Development of this software is supported by the German Research Society,
4    * Berlin-Brandenburg Graduate School in Distributed Information Systems
5    * (DFG grant no. GRK 316).
6    *
7    * This program is free software; you can redistribute it and/or modify
8    * it under the terms of the GNU General Public License as published by
9    * the Free Software Foundation; either version 2 of the License, or
10   * (at your option) any later version.
11   *
12   * This program is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   * GNU General Public License for more details.
16   *
17   * You should have received a copy of the GNU General Public License
18   * along with this program; if not, visit
19   * http://www.gnu.org/licenses/gpl.html or write to the Free Software
20   * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
21   */
22  package de.fu_berlin.ties.util;
23  
24  /***
25   * Small wrapper class for an <code>int</code> whose value can be changed.
26   * Can be used whenever a mutable object is required, e.g. for adjustable
27   * status codes ({@link java.lang.Integer} is immutable, <code>int</code> is a
28   * primitive).
29   *
30   * @author Christian Siefkes
31   * @version $Revision: 1.4 $, $Date: 2006/10/21 16:04:27 $, $Author: siefkes $
32   */
33  public class MutableInt {
34  
35      /***
36       * The wrapped <code>int</code> value.
37       */
38      private int value;
39  
40      /***
41       * Creates a new instance, setting the initial value to 0.
42       */
43      public MutableInt() {
44          this(0);
45      }
46  
47      /***
48       * Creates a new instance.
49       *
50       * @param initialValue the initial value to wrap
51       */
52      public MutableInt(final int initialValue) {
53          super();
54          value = initialValue;
55      }
56  
57      /***
58       * Returns the wrapped <code>int</code> value.
59       * @return the current value
60       */
61      public int getValue() {
62          return value;
63      }
64  
65      /***
66       * Modifies the wrapped <code>int</code> value.
67       * @param i the new value
68       */
69      public void setValue(final int i) {
70          value = i;
71      }
72  
73      /***
74       * Returns a string representation of this object.
75       *
76       * @return a textual representation
77       */
78      public String toString() {
79          return Integer.toString(value);
80      }
81  
82  }