1 4 package gnu.lists; 5 6 11 12 public class Convert 13 { 14 public static Convert instance = new Convert(); 15 16 public static Convert getInstance() { return instance; } 17 18 public static void setInstance(Convert value) { instance = value; }; 19 20 public Object booleanToObject(boolean value) 21 { 22 return value ? Boolean.TRUE : Boolean.FALSE; 23 } 24 25 public boolean objectToBoolean(Object obj) 26 { 27 return ! (obj instanceof Boolean ) || ((Boolean ) obj).booleanValue(); 28 } 29 30 public static Object toObject(boolean value) 31 { 32 return instance.booleanToObject(value); 33 } 34 35 public static boolean toBoolean(Object obj) 36 { 37 return instance.objectToBoolean(obj); 38 } 39 40 public Object charToObject(char ch) 41 { 42 return new Character (ch); 43 } 44 45 public char objectToChar(Object obj) 46 { 47 return ((Character ) obj).charValue(); 48 } 49 50 public static Object toObject(char ch) 51 { 52 return instance.charToObject(ch); 53 } 54 55 public static char toChar(Object obj) 56 { 57 return instance.objectToChar(obj); 58 } 59 60 public Object byteToObject(byte value) 61 { 62 return new Byte (value); 63 } 64 65 public byte objectToByte(Object obj) 66 { 67 return ((Number ) obj).byteValue(); 68 } 69 70 public static Object toObject(byte value) 71 { 72 return instance.byteToObject(value); 73 } 74 75 public static byte toByte(Object obj) 76 { 77 return instance.objectToByte(obj); 78 } 79 80 public Object byteToObjectUnsigned(byte value) 81 { 82 return new Integer (value & 0xFF); 83 } 84 85 public byte objectToByteUnsigned(Object obj) 86 { 87 return ((Number ) obj).byteValue(); 88 } 89 90 public static Object toObjectUnsigned(byte value) 91 { 92 return instance.byteToObjectUnsigned(value); 93 } 94 95 public static byte toByteUnsigned(Object obj) 96 { 97 return instance.objectToByteUnsigned(obj); 98 } 99 100 public Object shortToObject(short value) 101 { 102 return new Short (value); 103 } 104 105 public short objectToShort(Object obj) 106 { 107 return ((Number ) obj).shortValue(); 108 } 109 110 public static Object toObject(short value) 111 { 112 return instance.shortToObject(value); 113 } 114 115 public static short toShort(Object obj) 116 { 117 return instance.objectToShort(obj); 118 } 119 120 public Object shortToObjectUnsigned(short value) 121 { 122 return new Integer (value & 0xFFFF); 123 } 124 125 public short objectToShortUnsigned(Object obj) 126 { 127 return ((Number ) obj).shortValue(); 128 } 129 130 public static Object toObjectUnsigned(short value) 131 { 132 return instance.shortToObjectUnsigned(value); 133 } 134 135 public static short toShortUnsigned(Object obj) 136 { 137 return instance.objectToShortUnsigned(obj); 138 } 139 140 public Object intToObject(int value) 141 { 142 return new Integer (value); 143 } 144 145 public int objectToInt(Object obj) 146 { 147 return ((Number ) obj).intValue(); 148 } 149 150 public static Object toObject(int value) 151 { 152 return instance.intToObject(value); 153 } 154 155 public static int toInt(Object obj) 156 { 157 return instance.objectToInt(obj); 158 } 159 160 public Object intToObjectUnsigned(int value) 161 { 162 if (value >= 0) 163 return new Integer (value); 164 else 165 return new Long ((long) value & 0xffffffffL); 166 } 167 168 public int objectToIntUnsigned(Object obj) 169 { 170 return ((Number ) obj).intValue(); 171 } 172 173 public static Object toObjectUnsigned(int value) 174 { 175 return instance.intToObjectUnsigned(value); 176 } 177 178 public static int toIntUnsigned(Object obj) 179 { 180 return instance.objectToIntUnsigned(obj); 181 } 182 183 public Object longToObject(long value) 184 { 185 return new Long (value); 186 } 187 188 public long objectToLong(Object obj) 189 { 190 return ((Number ) obj).longValue(); 191 } 192 193 public static Object toObject(long value) 194 { 195 return instance.longToObject(value); 196 } 197 198 public static long toLong(Object obj) 199 { 200 return instance.objectToLong(obj); 201 } 202 203 public Object longToObjectUnsigned(long value) 204 { 205 return new Long (value); } 207 208 public long objectToLongUnsigned(Object obj) 209 { 210 return ((Number ) obj).longValue(); 211 } 212 213 public static Object toObjectUnsigned(long value) 214 { 215 return instance.longToObjectUnsigned(value); 216 } 217 218 public static long toLongUnsigned(Object obj) 219 { 220 return instance.objectToLongUnsigned(obj); 221 } 222 223 public Object floatToObject(float value) 224 { 225 return new Float (value); 226 } 227 228 public float objectToFloat(Object obj) 229 { 230 return ((Number ) obj).floatValue(); 231 } 232 233 public static Object toObject(float value) 234 { 235 return instance.floatToObject(value); 236 } 237 238 public static float toFloat(Object obj) 239 { 240 return instance.objectToFloat(obj); 241 } 242 243 public Object doubleToObject(double value) 244 { 245 return new Double (value); 246 } 247 248 public double objectToDouble(Object obj) 249 { 250 return ((Number ) obj).doubleValue(); 251 } 252 253 public static Object toObject(double value) 254 { 255 return instance.doubleToObject(value); 256 } 257 258 public static double toDouble(Object obj) 259 { 260 return instance.objectToDouble(obj); 261 } 262 263 public static double parseDouble(String str) 264 { 265 268 return Double.parseDouble(str); 269 270 271 273 } 274 } 275 | Popular Tags |