1 16 package org.apache.axis.types; 17 18 import org.apache.axis.utils.Messages; 19 20 import java.math.BigInteger ; 21 22 28 public class UnsignedLong extends java.lang.Number 29 implements java.lang.Comparable { 30 31 protected BigInteger lValue = BigInteger.ZERO; 32 private static BigInteger MAX = new BigInteger ("18446744073709551615"); 34 public UnsignedLong() { 35 } 36 37 public UnsignedLong(double value) throws NumberFormatException { 38 setValue(new BigInteger (Double.toString(value))); 39 } 40 41 public UnsignedLong(BigInteger value) throws NumberFormatException { 42 setValue(value); 43 } 44 45 public UnsignedLong(long lValue) throws NumberFormatException { 46 setValue(BigInteger.valueOf(lValue)); 47 } 48 49 public UnsignedLong(String stValue) throws NumberFormatException { 50 setValue(new BigInteger (stValue)); 51 } 52 53 private void setValue(BigInteger val) { 54 if (!UnsignedLong.isValid(val)) { 55 throw new NumberFormatException (Messages.getMessage( 56 "badUnsignedLong00") + 57 String.valueOf(val) + "]"); 58 } 59 this.lValue = val; 60 } 61 62 public static boolean isValid(BigInteger value) { 63 if (value.compareTo(BigInteger.ZERO) == -1 || value.compareTo(MAX) == 1) { 65 return false; 66 } 67 return true; 68 } 69 70 public String toString() { 71 return lValue.toString(); 72 } 73 74 public int hashCode() { 75 if (lValue != null) 76 return lValue.hashCode(); 77 else 78 return 0; 79 } 80 81 private Object __equalsCalc = null; 82 83 public synchronized boolean equals(Object obj) { 84 if (!(obj instanceof UnsignedLong)) return false; 85 UnsignedLong other = (UnsignedLong) obj; 86 if (obj == null) return false; 87 if (this == obj) return true; 88 if (__equalsCalc != null) { 89 return (__equalsCalc == obj); 90 } 91 __equalsCalc = obj; 92 boolean _equals; 93 _equals = true && 94 ((lValue == null && other.lValue == null) || 95 (lValue != null && 96 lValue.equals(other.lValue))); 97 __equalsCalc = null; 98 return _equals; 99 } 100 101 public int compareTo(Object obj) { 103 if (lValue != null) 104 return lValue.compareTo(obj); 105 else if (equals(obj) == true) 106 return 0; else 108 return 1; } 110 111 public byte byteValue() { 113 return lValue.byteValue(); 114 } 115 116 public short shortValue() { 117 return lValue.shortValue(); 118 } 119 120 public int intValue() { 121 return lValue.intValue(); 122 } 123 124 public long longValue() { 125 return lValue.longValue(); 126 } 127 128 public double doubleValue() { 129 return lValue.doubleValue(); 130 } 131 132 public float floatValue() { 133 return lValue.floatValue(); 134 } 135 136 } 137 | Popular Tags |