1 2 5 14 package org.jacorb.trading.constraint; 15 16 17 public class ULongValue implements Value 18 { 19 private Long m_value; 20 21 22 public ULongValue() 23 { 24 this(0); 25 } 26 27 28 public ULongValue(long value) 29 { 30 m_value = new Long (value); 31 } 32 33 34 public ULongValue(Object value) 35 { 36 m_value = (Long )value; 37 } 38 39 40 public void setValue(Object value) 41 { 42 m_value = (Long )value; 43 } 44 45 46 public int getTypeId() 47 { 48 return ValueType.ULONG; 49 } 50 51 52 public Object getValue() 53 { 54 return m_value; 55 } 56 57 58 public boolean equals(Value nv) 59 { 60 boolean result = false; 61 62 if (nv.getTypeId() == ValueType.ULONG) 63 result = m_value.equals(nv.getValue()); 64 else 65 throw new IllegalArgumentException (); 66 67 return result; 68 } 69 70 71 public boolean lessThan(Value nv) 72 { 73 boolean result = false; 74 75 if (nv.getTypeId() == ValueType.ULONG) { 76 Long l = (Long )nv.getValue(); 77 result = (m_value.longValue() < l.longValue()); 78 } 79 else 80 throw new IllegalArgumentException (); 81 82 return result; 83 } 84 85 86 public boolean lessThanEqual(Value nv) 87 { 88 return (lessThan(nv) || equals(nv)); 89 } 90 91 92 public boolean greaterThan(Value nv) 93 { 94 return (! lessThan(nv) && ! equals(nv)); 95 } 96 97 98 public boolean greaterThanEqual(Value nv) 99 { 100 return (! lessThan(nv)); 101 } 102 103 104 public Value plus(Value nv) 105 { 106 Value result = null; 107 108 if (nv.getTypeId() == ValueType.ULONG) { 109 Long l = (Long )nv.getValue(); 110 result = new ULongValue(m_value.longValue() + l.longValue()); 111 } 112 else 113 throw new IllegalArgumentException (); 114 115 return result; 116 } 117 118 119 public Value minus(Value nv) 120 { 121 Value result = null; 122 123 if (nv.getTypeId() == ValueType.ULONG) { 124 Long l = (Long )nv.getValue(); 125 long val = m_value.longValue() - l.longValue(); 126 if (val < 0) 127 result = ValueFactory.createLong((int)val); 128 else 129 result = new ULongValue(val); 130 } 131 else 132 throw new IllegalArgumentException (); 133 134 return result; 135 } 136 137 138 public Value multiply(Value nv) 139 { 140 Value result = null; 141 142 if (nv.getTypeId() == ValueType.ULONG) { 143 Long l = (Long )nv.getValue(); 144 result = 145 ValueFactory.createULong(m_value.longValue() * l.longValue()); 146 } 147 else 148 throw new IllegalArgumentException (); 149 150 return result; 151 } 152 153 154 public Value divide(Value nv) 155 { 156 Value result = null; 157 158 if (nv.getTypeId() == ValueType.ULONG) { 159 Long l = (Long )nv.getValue(); 160 result = new ULongValue(m_value.longValue() / l.longValue()); 161 } 162 else 163 throw new IllegalArgumentException (); 164 165 return result; 166 } 167 168 169 public Value negate() 170 { 171 return ValueFactory.createLong(-1 * m_value.intValue()); 172 } 173 174 175 public Value convert(int typeId) 176 { 177 Value result = null; 178 179 switch (typeId) { 180 case ValueType.LONG: 181 result = ValueFactory.createLong(m_value.intValue()); 182 break; 183 184 case ValueType.ULONG: 185 result = new ULongValue(m_value); 186 break; 187 188 case ValueType.FLOAT: 189 result = ValueFactory.createFloat(m_value.floatValue()); 190 break; 191 192 case ValueType.DOUBLE: 193 result = ValueFactory.createDouble(m_value.doubleValue()); 194 break; 195 196 default: 197 throw new IllegalArgumentException (); 198 } 199 200 return result; 201 } 202 203 204 public String toString() 205 { 206 return m_value.toString(); 207 } 208 } 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 | Popular Tags |