1 46 package org.mr.api.jms.selector.syntax; 47 48 49 53 final class MantaLong extends MantaNumber { 54 55 58 private long value; 59 60 61 66 public MantaLong(final long value) { 67 this.value = value; 68 } 70 71 77 public MantaNumber add(final MantaNumber number) { 78 MantaNumber result; 79 80 if (number instanceof MantaDouble) { 81 result = promote().add(number); 82 } else { 84 result = new MantaLong(value + number.getLong()); 85 } return result; 87 } 89 90 96 public MantaNumber subtract(final MantaNumber number) { 97 MantaNumber result; 98 if (number instanceof MantaDouble) { 99 result = promote().subtract(number); 100 } else { 102 result = new MantaLong(value - number.getLong()); 103 } return result; 105 } 107 108 114 public MantaNumber multiply(final MantaNumber number) { 115 MantaNumber result; 116 if (number instanceof MantaDouble) { 117 result = promote().multiply(number); 118 } else { 120 result = new MantaLong(value * number.getLong()); 121 } return result; 123 } 125 126 132 public MantaNumber divide(final MantaNumber number) { 133 MantaNumber result = null; 134 try { 135 if (number instanceof MantaDouble) { 136 result = promote().divide(number); 137 } else { 139 result = new MantaLong(value / number.getLong()); 140 } } catch (ArithmeticException ignore) { 143 } return result; 145 } 147 148 153 public long getLong() { 154 return value; 155 } 157 158 163 public double getDouble() { 164 return value; 165 } 167 168 173 public Object getObject() { 174 return new Long (value); 175 } 177 178 184 public MantaBoolean equal(final MantaObject obj) { 185 MantaBoolean result = null; 186 187 if (obj instanceof MantaLong) { 188 long rightHand = ((MantaNumber) obj).getLong(); 189 if (value == rightHand) { 190 result = MantaBoolean.TRUE; 191 } else { 193 result = MantaBoolean.FALSE; 194 } } else if (obj instanceof MantaDouble) { 197 result = promote().equal(obj); 198 } return result; 200 } 202 203 209 public MantaBoolean less(final MantaObject obj) { 210 MantaBoolean result = null; 211 212 if (obj instanceof MantaLong) { 213 long rightHand = ((MantaNumber) obj).getLong(); 214 if (value < rightHand) { 215 result = MantaBoolean.TRUE; 216 } else { 218 result = MantaBoolean.FALSE; 219 } } else if (obj instanceof MantaDouble) { 222 result = promote().less(obj); 223 } return result; 225 } 227 228 234 public MantaBoolean greater(final MantaObject obj) { 235 MantaBoolean result = null; 236 if (obj instanceof MantaLong) { 237 long rightHand = ((MantaNumber) obj).getLong(); 238 if (value > rightHand) { 239 result = MantaBoolean.TRUE; 240 } else { 242 result = MantaBoolean.FALSE; 243 } } else if (obj instanceof MantaDouble) { 246 result = promote().greater(obj); 247 } return result; 249 } 251 252 257 private MantaDouble promote() { 258 return new MantaDouble(value); 259 } 261 } | Popular Tags |