1 3 package jodd.mutable; 4 5 8 public final class MutableInteger extends Number implements Comparable { 9 10 11 public MutableInteger() { 12 super(); 13 } 14 15 public MutableInteger(int value) { 16 super(); 17 this.value = value; 18 } 19 20 public MutableInteger(String value) { 21 this(Integer.parseInt(value)); 22 } 23 24 26 29 public int value; 30 31 34 public int getValue() { 35 return value; 36 } 37 38 41 public void setValue(int value) { 42 this.value = value; 43 } 44 45 48 public void setValue(Number value) { 49 this.value = value.intValue(); 50 } 51 52 54 57 public String toString() { 58 return Integer.toString(value); 59 } 60 61 64 public int hashCode() { 65 return value; 66 } 67 68 75 public boolean equals(Object obj) { 76 if (obj != null) { 77 if (obj instanceof Integer ) { 78 return value == ((Integer ) obj).intValue(); 79 } 80 if (obj instanceof MutableInteger) { 81 return value == ((MutableInteger) obj).value; 82 } 83 } 84 return false; 85 } 86 87 89 92 public int intValue() { 93 return value; 94 } 95 96 99 public long longValue() { 100 return value; 101 } 102 103 106 public float floatValue() { 107 return value; 108 } 109 110 113 public double doubleValue() { 114 return value; 115 } 116 117 119 122 public int compareTo(Object obj) { 123 MutableInteger other = (MutableInteger) obj; 124 return value < other.value ? -1 : (value == other.value ? 0 : 1); 125 } 126 } | Popular Tags |