1 43 44 package org.exolab.jms.selector; 45 46 47 54 final class SLong extends SNumber { 55 56 59 private long _value; 60 61 66 public SLong(final long value) { 67 _value = value; 68 } 69 70 76 public SNumber add(final SNumber number) { 77 SNumber result; 78 if (number instanceof SDouble) { 79 result = promote().add(number); 80 } else { 81 result = new SLong(_value + number.getLong()); 82 } 83 return result; 84 } 85 86 92 public SNumber subtract(final SNumber number) { 93 SNumber result; 94 if (number instanceof SDouble) { 95 result = promote().subtract(number); 96 } else { 97 result = new SLong(_value - number.getLong()); 98 } 99 return result; 100 } 101 102 108 public SNumber multiply(final SNumber number) { 109 SNumber result; 110 if (number instanceof SDouble) { 111 result = promote().multiply(number); 112 } else { 113 result = new SLong(_value * number.getLong()); 114 } 115 return result; 116 } 117 118 124 public SNumber divide(final SNumber number) { 125 SNumber result = null; 126 try { 127 if (number instanceof SDouble) { 128 result = promote().divide(number); 129 } else { 130 result = new SLong(_value / number.getLong()); 131 } 132 } catch (ArithmeticException ignore) { 133 } 134 return result; 135 } 136 137 142 public long getLong() { 143 return _value; 144 } 145 146 151 public double getDouble() { 152 return _value; 153 } 154 155 160 public Object getObject() { 161 return new Long (_value); 162 } 163 164 171 public SBool equal(final SObject obj) { 172 SBool result = null; 173 if (obj instanceof SLong) { 174 long rhs = ((SNumber) obj).getLong(); 175 if (_value == rhs) { 176 result = SBool.TRUE; 177 } else { 178 result = SBool.FALSE; 179 } 180 } else if (obj instanceof SDouble) { 181 result = promote().equal(obj); 182 } 183 return result; 184 } 185 186 193 public SBool less(final SObject obj) { 194 SBool result = null; 195 if (obj instanceof SLong) { 196 long rhs = ((SNumber) obj).getLong(); 197 if (_value < rhs) { 198 result = SBool.TRUE; 199 } else { 200 result = SBool.FALSE; 201 } 202 } else if (obj instanceof SDouble) { 203 result = promote().less(obj); 204 } 205 return result; 206 } 207 208 215 public SBool greater(final SObject obj) { 216 SBool result = null; 217 if (obj instanceof SLong) { 218 long rhs = ((SNumber) obj).getLong(); 219 if (_value > rhs) { 220 result = SBool.TRUE; 221 } else { 222 result = SBool.FALSE; 223 } 224 } else if (obj instanceof SDouble) { 225 result = promote().greater(obj); 226 } 227 return result; 228 } 229 230 235 private SDouble promote() { 236 return new SDouble(_value); 237 } 238 239 } | Popular Tags |