1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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 }