1 16 17 package org.apache.commons.lang.mutable; 18 19 26 public class MutableInt extends Number implements Comparable , Mutable { 27 28 29 private static final long serialVersionUID = 512176391864L; 30 31 32 private int value; 33 34 37 public MutableInt() { 38 super(); 39 } 40 41 47 public MutableInt(int value) { 48 super(); 49 this.value = value; 50 } 51 52 60 public MutableInt(Number value) { 61 super(); 62 this.value = value.intValue(); 63 } 64 65 71 public Object getValue() { 72 return new Integer (this.value); 73 } 74 75 81 public void setValue(int value) { 82 this.value = value; 83 } 84 85 95 public void setValue(Object value) { 96 setValue(((Number ) value).intValue()); 97 } 98 99 106 public int intValue() { 107 return value; 108 } 109 110 115 public long longValue() { 116 return value; 117 } 118 119 124 public float floatValue() { 125 return value; 126 } 127 128 133 public double doubleValue() { 134 return value; 135 } 136 137 147 public boolean equals(Object obj) { 148 if (obj instanceof MutableInt) { 149 return value == ((MutableInt) obj).intValue(); 150 } 151 return false; 152 } 153 154 159 public int hashCode() { 160 return value; 161 } 162 163 171 public int compareTo(Object obj) { 172 MutableInt other = (MutableInt) obj; 173 int anotherVal = other.value; 174 return value < anotherVal ? -1 : (value == anotherVal ? 0 : 1); 175 } 176 177 182 public String toString() { 183 return String.valueOf(value); 184 } 185 186 } 187 | Popular Tags |