01: /* MutableInteger.java
02:
03: {{IS_NOTE
04: Purpose:
05:
06: Description:
07:
08: History:
09: Fri Feb 16 13:39:47 2007, Created by tomyeh
10: }}IS_NOTE
11:
12: Copyright (C) 2007 Potix Corporation. All Rights Reserved.
13:
14: {{IS_RIGHT
15: This program is distributed under GPL Version 2.0 in the hope that
16: it will be useful, but WITHOUT ANY WARRANTY.
17: }}IS_RIGHT
18: */
19: package org.zkoss.lang;
20:
21: /**
22: * Represents an interger that can be modified.
23: *
24: * <p>It is useful if you want to pass an integer to a method
25: * and like to keep the result of how the method modifies the value.
26: *
27: * @author tomyeh
28: */
29: public class MutableInteger implements Comparable {
30: /** The value of ths mutable integer. */
31: public int value;
32:
33: public MutableInteger(int value) {
34: this .value = value;
35: }
36:
37: /** Returns the value of this {@link MutableInteger} as an int.
38: */
39: public int intValue() {
40: return this .value;
41: }
42:
43: /** Sets the value of this {@link MutableInteger}.
44: */
45: public void setValue(int value) {
46: this .value = value;
47: }
48:
49: /** Compares two {@link MutableInteger} objects numerically.
50: *
51: * @return the value 0 if the argument is numerically equal to this;
52: * a value less than 0 if the argument is numerically greater than this;
53: * and a value greater than 0 if the argument is numerically less than this.
54: */
55: public int compareTo(MutableInteger o) {
56: if (this .value > o.value)
57: return 1;
58: else if (this .value == o.value)
59: return 0;
60: else
61: return -1;
62: }
63:
64: //Comparable//
65: /** Compares two {@link MutableInteger} objects numerically.
66: *
67: * @return the value 0 if the argument is numerically equal to this;
68: * a value less than 0 if the argument is numerically greater than this;
69: * and a value greater than 0 if the argument is numerically less than this.
70: */
71: public int compareTo(Object o) {
72: return compareTo((MutableInteger) o);
73: }
74:
75: //Object//
76: public String toString() {
77: return "" + this .value;
78: }
79:
80: public int hashCode() {
81: return this .value;
82: }
83:
84: public boolean equals(Object o) {
85: return (o instanceof MutableInteger)
86: && ((MutableInteger) o).value == this.value;
87: }
88: }
|