1 16 17 package org.apache.commons.lang.mutable; 18 19 26 public class MutableShort extends Number implements Comparable , Mutable { 27 28 29 private static final long serialVersionUID = -2135791679L; 30 31 32 private short value; 33 34 37 public MutableShort() { 38 super(); 39 } 40 41 47 public MutableShort(short value) { 48 super(); 49 this.value = value; 50 } 51 52 60 public MutableShort(Number value) { 61 super(); 62 this.value = value.shortValue(); 63 } 64 65 71 public Object getValue() { 72 return new Short (this.value); 73 } 74 75 81 public void setValue(short value) { 82 this.value = value; 83 } 84 85 95 public void setValue(Object value) { 96 setValue(((Number ) value).shortValue()); 97 } 98 99 106 public short shortValue() { 107 return value; 108 } 109 110 115 public int intValue() { 116 return value; 117 } 118 119 124 public long longValue() { 125 return value; 126 } 127 128 133 public float floatValue() { 134 return value; 135 } 136 137 142 public double doubleValue() { 143 return value; 144 } 145 146 156 public boolean equals(Object obj) { 157 if (obj instanceof MutableShort) { 158 return value == ((MutableShort) obj).shortValue(); 159 } 160 return false; 161 } 162 163 168 public int hashCode() { 169 return value; 170 } 171 172 180 public int compareTo(Object obj) { 181 MutableShort other = (MutableShort) obj; 182 short anotherVal = other.value; 183 return value < anotherVal ? -1 : (value == anotherVal ? 0 : 1); 184 } 185 186 191 public String toString() { 192 return String.valueOf(value); 193 } 194 195 } 196 | Popular Tags |