1 2 5 14 package org.jacorb.trading.constraint; 15 16 17 public class FloatValue implements Value 18 { 19 private Float m_value; 20 21 22 public FloatValue() 23 { 24 this((float)0.0); 25 } 26 27 28 public FloatValue(float value) 29 { 30 m_value = new Float (value); 31 } 32 33 34 public FloatValue(Object value) 35 { 36 m_value = (Float )value; 37 } 38 39 40 public void setValue(Object value) 41 { 42 m_value = (Float )value; 43 } 44 45 46 public int getTypeId() 47 { 48 return ValueType.FLOAT; 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.FLOAT) 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.FLOAT) { 76 Float f = (Float )nv.getValue(); 77 result = (m_value.floatValue() < f.floatValue()); 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.FLOAT) { 109 Float f = (Float )nv.getValue(); 110 result = new FloatValue(m_value.floatValue() + f.floatValue()); 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.FLOAT) { 124 Float f = (Float )nv.getValue(); 125 result = new FloatValue(m_value.floatValue() - f.floatValue()); 126 } 127 else 128 throw new IllegalArgumentException (); 129 130 return result; 131 } 132 133 134 public Value multiply(Value nv) 135 { 136 Value result = null; 137 138 if (nv.getTypeId() == ValueType.FLOAT) { 139 Float f = (Float )nv.getValue(); 140 result = new FloatValue(m_value.floatValue() * f.floatValue()); 141 } 142 else 143 throw new IllegalArgumentException (); 144 145 return result; 146 } 147 148 149 public Value divide(Value nv) 150 { 151 Value result = null; 152 153 if (nv.getTypeId() == ValueType.FLOAT) { 154 Float f = (Float )nv.getValue(); 155 result = new FloatValue(m_value.floatValue() / f.floatValue()); 156 } 157 else 158 throw new IllegalArgumentException (); 159 160 return result; 161 } 162 163 164 public Value negate() 165 { 166 Value result = null; 167 168 result = new FloatValue(-1 * m_value.floatValue()); 169 170 return result; 171 } 172 173 174 public Value convert(int typeId) 175 { 176 Value result = null; 177 178 switch (typeId) { 179 case ValueType.FLOAT: 180 result = new FloatValue(m_value); 181 break; 182 183 case ValueType.DOUBLE: 184 result = ValueFactory.createDouble(m_value.doubleValue()); 185 break; 186 187 default: 188 throw new IllegalArgumentException (); 189 } 190 191 return result; 192 } 193 194 195 public String toString() 196 { 197 return m_value.toString(); 198 } 199 } 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 | Popular Tags |