1 34 35 36 package com.micronova.util.codec; 37 38 import com.micronova.util.*; 39 40 41 42 public class CodecNumber extends Codec 43 { 44 public static Object toBinaryString(Object object, Object filler) 45 { 46 if (object != null) 47 { 48 Long longNumber = TypeUtil.isLong(object); 49 50 if (longNumber != null) 51 { 52 object = NumberUtil.toBinaryString(longNumber.longValue(), (String )filler); 53 } 54 else 55 { 56 object = null; 57 } 58 } 59 60 return object; 61 } 62 63 public static Object toBinaryString(Object object) 64 { 65 return toBinaryString(object, null); 66 } 67 68 public static Object toHexString(Object object, Object filler) 69 { 70 if (object != null) 71 { 72 Long longNumber = TypeUtil.isLong(object); 73 74 if (longNumber != null) 75 { 76 object = NumberUtil.toHexString(longNumber.longValue(), (String )filler); 77 } 78 else 79 { 80 object = null; 81 } 82 } 83 84 return object; 85 } 86 87 public static Object toHexString(Object object) 88 { 89 return toHexString(object, null); 90 } 91 92 public static Object toOctalString(Object object, Object filler) 93 { 94 if (object != null) 95 { 96 Long longNumber = TypeUtil.isLong(object); 97 98 if (longNumber != null) 99 { 100 object = NumberUtil.toOctalString(longNumber.longValue(), (String )filler); 101 } 102 else 103 { 104 object = null; 105 } 106 } 107 108 return object; 109 } 110 111 public static Object toOctalString(Object object) 112 { 113 return toOctalString(object, null); 114 } 115 116 public static Object fromBinaryString(Object object) 117 { 118 if (object != null) 119 { 120 object = new Long (NumberUtil.fromBinaryString(object.toString())); 121 } 122 123 return object; 124 } 125 126 public static Object fromHexString(Object object) 127 { 128 if (object != null) 129 { 130 object = new Long (NumberUtil.fromHexString(object.toString())); 131 } 132 133 return object; 134 } 135 136 public static Object fromOctalString(Object object) 137 { 138 if (object != null) 139 { 140 object = new Long (NumberUtil.fromOctalString(object.toString())); 141 } 142 143 return object; 144 } 145 146 private static Object asDouble(double d) 147 { 148 return new Double (d); 149 } 150 151 private static Object asLong(double d) 152 { 153 return new Long ((long)d); 154 } 155 156 public static Object e() 157 { 158 return asDouble(Math.E); 159 } 160 161 public static Object pi() 162 { 163 return asDouble(Math.PI); 164 } 165 166 public static Object abs(Object object) 167 { 168 Double d = TypeUtil.isDouble(object); 169 170 if (d != null) 171 { 172 return asDouble(Math.abs(d.doubleValue())); 173 } 174 175 return null; 176 } 177 178 179 public static Object max(Object object1, Object object2 ) 180 { 181 Double d1 = TypeUtil.isDouble(object1); 182 Double d2 = TypeUtil.isDouble(object2); 183 184 if ((d1 != null) && (d2 != null)) 185 { 186 return asDouble(Math.max(d1.doubleValue(), d2.doubleValue())); 187 } 188 189 return null; 190 } 191 192 public static Object min(Object object1, Object object2 ) 193 { 194 Double d1 = TypeUtil.isDouble(object1); 195 Double d2 = TypeUtil.isDouble(object2); 196 197 if ((d1 != null) && (d2 != null)) 198 { 199 return asDouble(Math.min(d1.doubleValue(), d2.doubleValue())); 200 } 201 202 return null; 203 } 204 205 public static Object ceil(Object object) 206 { 207 Double d = TypeUtil.isDouble(object); 208 209 if (d != null) 210 { 211 return asLong(Math.ceil(d.doubleValue())); 212 } 213 214 return null; 215 } 216 217 public static Object floor(Object object) 218 { 219 Double d = TypeUtil.isDouble(object); 220 221 if (d != null) 222 { 223 return asLong(Math.floor(d.doubleValue())); 224 } 225 226 return null; 227 } 228 229 public static Object round(Object object) 230 { 231 Double d = TypeUtil.isDouble(object); 232 233 if (d != null) 234 { 235 return asLong(Math.round(d.doubleValue())); 236 } 237 238 return null; 239 } 240 241 public static Object exp(Object object) 242 { 243 Double d = TypeUtil.isDouble(object); 244 245 if (d != null) 246 { 247 return asDouble(Math.exp(d.doubleValue())); 248 } 249 250 return null; 251 } 252 253 public static Object log(Object object) 254 { 255 Double d = TypeUtil.isDouble(object); 256 257 if (d != null) 258 { 259 return asDouble(Math.log(d.doubleValue())); 260 } 261 262 return null; 263 } 264 265 public static Object sqrt(Object object) 266 { 267 Double d = TypeUtil.isDouble(object); 268 269 if (d != null) 270 { 271 return asDouble(Math.sqrt(d.doubleValue())); 272 } 273 274 return null; 275 } 276 277 public static Object pow(Object object1, Object object2 ) 278 { 279 Double d1 = TypeUtil.isDouble(object1); 280 Double d2 = TypeUtil.isDouble(object2); 281 282 if ((d1 != null) && (d2 != null)) 283 { 284 return asDouble(Math.pow(d1.doubleValue(), d2.doubleValue())); 285 } 286 287 return null; 288 } 289 290 public static Object sin(Object object) 291 { 292 Double d = TypeUtil.isDouble(object); 293 294 if (d != null) 295 { 296 return asDouble(Math.sin(d.doubleValue())); 297 } 298 299 return null; 300 } 301 302 public static Object cos(Object object) 303 { 304 Double d = TypeUtil.isDouble(object); 305 306 if (d != null) 307 { 308 return asDouble(Math.cos(d.doubleValue())); 309 } 310 311 return null; 312 } 313 314 public static Object tan(Object object) 315 { 316 Double d = TypeUtil.isDouble(object); 317 318 if (d != null) 319 { 320 return asDouble(Math.tan(d.doubleValue())); 321 } 322 323 return null; 324 } 325 326 327 public static Object asin(Object object) 328 { 329 Double d = TypeUtil.isDouble(object); 330 331 if (d != null) 332 { 333 return asDouble(Math.asin(d.doubleValue())); 334 } 335 336 return null; 337 } 338 339 public static Object acos(Object object) 340 { 341 Double d = TypeUtil.isDouble(object); 342 343 if (d != null) 344 { 345 return asDouble(Math.acos(d.doubleValue())); 346 } 347 348 return null; 349 } 350 351 public static Object atan(Object object) 352 { 353 Double d = TypeUtil.isDouble(object); 354 355 if (d != null) 356 { 357 return asDouble(Math.atan(d.doubleValue())); 358 } 359 360 return null; 361 } 362 363 public static Object toDegrees(Object object) 364 { 365 Double d = TypeUtil.isDouble(object); 366 367 if (d != null) 368 { 369 return asDouble(Math.toDegrees(d.doubleValue())); 370 } 371 372 return null; 373 } 374 375 public static Object toRadians(Object object) 376 { 377 Double d = TypeUtil.isDouble(object); 378 379 if (d != null) 380 { 381 return asDouble(Math.toRadians(d.doubleValue())); 382 } 383 384 return null; 385 } 386 } 387 388 | Popular Tags |