1b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato/* 2b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato * ProGuard -- shrinking, optimization, obfuscation, and preverification 3b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato * of Java bytecode. 4b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato * 5b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang * Copyright (c) 2002-2013 Eric Lafortune (eric@graphics.cornell.edu) 6b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato * 7b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato * This program is free software; you can redistribute it and/or modify it 8b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato * under the terms of the GNU General Public License as published by the Free 9b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato * Software Foundation; either version 2 of the License, or (at your option) 10b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato * any later version. 11b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato * 12b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato * This program is distributed in the hope that it will be useful, but WITHOUT 13b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 14b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 15b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato * more details. 16b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato * 17b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato * You should have received a copy of the GNU General Public License along 18b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato * with this program; if not, write to the Free Software Foundation, Inc., 19b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato */ 21b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratopackage proguard.evaluation.value; 22b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 23b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato/** 24b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato * This IntegerValue represents a particular integer value. 25b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato * 26b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato * @author Eric Lafortune 27b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato */ 28b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratofinal class ParticularIntegerValue extends SpecificIntegerValue 29b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato{ 30b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato private final int value; 31b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 32b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 33b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato /** 34b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato * Creates a new particular integer value. 35b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato */ 36b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato public ParticularIntegerValue(int value) 37b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato { 38b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato this.value = value; 39b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato } 40b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 41b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 42b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato // Implementations for IntegerValue. 43b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 44b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato public int value() 45b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato { 46b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato return value; 47b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato } 48b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 49b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 50b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato // Implementations of unary methods of IntegerValue. 51b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 52b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato public IntegerValue negate() 53b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato { 54b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato return new ParticularIntegerValue(-value); 55b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato } 56b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 57b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato public IntegerValue convertToByte() 58b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato { 59b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato int byteValue = (byte)value; 60b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 61b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato return byteValue == value ? 62b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato this : 63b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato new ParticularIntegerValue(byteValue); 64b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato } 65b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 66b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato public IntegerValue convertToCharacter() 67b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato { 68b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato int charValue = (char)value; 69b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 70b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato return charValue == value ? 71b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato this : 72b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato new ParticularIntegerValue(charValue); 73b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato } 74b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 75b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato public IntegerValue convertToShort() 76b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato { 77b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato int shortValue = (short)value; 78b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 79b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato return shortValue == value ? 80b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato this : 81b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato new ParticularIntegerValue(shortValue); 82b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato } 83b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 84b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato public LongValue convertToLong() 85b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato { 86b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato return new ParticularLongValue((long)value); 87b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato } 88b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 89b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato public FloatValue convertToFloat() 90b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato { 91b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato return new ParticularFloatValue((float)value); 92b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato } 93b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 94b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato public DoubleValue convertToDouble() 95b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato { 96b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato return new ParticularDoubleValue((double)value); 97b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato } 98b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 99b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 100b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato // Implementations of binary methods of IntegerValue. 101b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 102b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato public IntegerValue generalize(IntegerValue other) 103b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato { 104b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato return other.generalize(this); 105b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato } 106b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 107b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato public IntegerValue add(IntegerValue other) 108b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato { 109b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato return other.add(this); 110b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato } 111b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 112b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato public IntegerValue subtract(IntegerValue other) 113b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato { 114b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato return other.subtractFrom(this); 115b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato } 116b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 117b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato public IntegerValue subtractFrom(IntegerValue other) 118b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato { 119b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato return other.subtract(this); 120b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato } 121b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 122b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato public IntegerValue multiply(IntegerValue other) 123b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato { 124b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato return other.multiply(this); 125b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato } 126b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 127b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato public IntegerValue divide(IntegerValue other) 128b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato throws ArithmeticException 129b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato { 130b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato return other.divideOf(this); 131b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato } 132b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 133b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato public IntegerValue divideOf(IntegerValue other) 134b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato throws ArithmeticException 135b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato { 136b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato return other.divide(this); 137b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato } 138b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 139b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato public IntegerValue remainder(IntegerValue other) 140b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato throws ArithmeticException 141b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato { 142b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato return other.remainderOf(this); 143b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato } 144b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 145b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato public IntegerValue remainderOf(IntegerValue other) 146b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato throws ArithmeticException 147b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato { 148b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato return other.remainder(this); 149b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato } 150b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 151b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato public IntegerValue shiftLeft(IntegerValue other) 152b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato { 153b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato return other.shiftLeftOf(this); 154b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato } 155b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 156b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato public IntegerValue shiftLeftOf(IntegerValue other) 157b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato { 158b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato return other.shiftLeft(this); 159b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato } 160b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 161b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato public IntegerValue shiftRight(IntegerValue other) 162b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato { 163b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato return other.shiftRightOf(this); 164b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato } 165b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 166b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato public IntegerValue shiftRightOf(IntegerValue other) 167b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato { 168b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato return other.shiftRight(this); 169b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato } 170b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 171b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato public IntegerValue unsignedShiftRight(IntegerValue other) 172b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato { 173b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato return other.unsignedShiftRightOf(this); 174b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato } 175b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 176b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato public IntegerValue unsignedShiftRightOf(IntegerValue other) 177b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato { 178b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato return other.unsignedShiftRight(this); 179b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato } 180b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 181b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato public LongValue shiftLeftOf(LongValue other) 182b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato { 183b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato return other.shiftLeft(this); 184b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato } 185b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 186b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato public LongValue shiftRightOf(LongValue other) 187b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato { 188b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato return other.shiftRight(this); 189b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato } 190b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 191b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato public LongValue unsignedShiftRightOf(LongValue other) 192b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato { 193b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato return other.unsignedShiftRight(this); 194b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato } 195b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 196b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato public IntegerValue and(IntegerValue other) 197b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato { 198b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato return other.and(this); 199b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato } 200b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 201b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato public IntegerValue or(IntegerValue other) 202b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato { 203b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato return other.or(this); 204b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato } 205b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 206b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato public IntegerValue xor(IntegerValue other) 207b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato { 208b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato return other.xor(this); 209b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato } 210b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 211b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato public int equal(IntegerValue other) 212b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato { 213b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato return other.equal(this); 214b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato } 215b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 216b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato public int lessThan(IntegerValue other) 217b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato { 218b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato return other.greaterThan(this); 219b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato } 220b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 221b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato public int lessThanOrEqual(IntegerValue other) 222b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato { 223b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato return other.greaterThanOrEqual(this); 224b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato } 225b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 226b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 227b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato // Implementations of binary IntegerValue methods with ParticularIntegerValue 228b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato // arguments. 229b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 230b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato public IntegerValue generalize(ParticularIntegerValue other) 231b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato { 232b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato return generalize((SpecificIntegerValue)other); 233b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato } 234b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 235b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato public IntegerValue add(ParticularIntegerValue other) 236b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato { 237b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato return new ParticularIntegerValue(this.value + other.value); 238b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato } 239b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 240b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato public IntegerValue subtract(ParticularIntegerValue other) 241b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato { 242b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato return new ParticularIntegerValue(this.value - other.value); 243b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato } 244b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 245b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato public IntegerValue subtractFrom(ParticularIntegerValue other) 246b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato { 247b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato return new ParticularIntegerValue(other.value - this.value); 248b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato } 249b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 250b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato public IntegerValue multiply(ParticularIntegerValue other) 251b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato { 252b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato return new ParticularIntegerValue(this.value * other.value); 253b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato } 254b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 255b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato public IntegerValue divide(ParticularIntegerValue other) 256b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato throws ArithmeticException 257b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato { 258b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato return new ParticularIntegerValue(this.value / other.value); 259b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato } 260b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 261b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato public IntegerValue divideOf(ParticularIntegerValue other) 262b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato throws ArithmeticException 263b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato { 264b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato return new ParticularIntegerValue(other.value / this.value); 265b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato } 266b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 267b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato public IntegerValue remainder(ParticularIntegerValue other) 268b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato throws ArithmeticException 269b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato { 270b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato return new ParticularIntegerValue(this.value % other.value); 271b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato } 272b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 273b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato public IntegerValue remainderOf(ParticularIntegerValue other) 274b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato throws ArithmeticException 275b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato { 276b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato return new ParticularIntegerValue(other.value % this.value); 277b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato } 278b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 279b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato public IntegerValue shiftLeft(ParticularIntegerValue other) 280b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato { 281b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato return new ParticularIntegerValue(this.value << other.value); 282b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato } 283b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 284b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato public IntegerValue shiftRight(ParticularIntegerValue other) 285b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato { 286b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato return new ParticularIntegerValue(this.value >> other.value); 287b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato } 288b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 289b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato public IntegerValue unsignedShiftRight(ParticularIntegerValue other) 290b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato { 291b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato return new ParticularIntegerValue(this.value >>> other.value); 292b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato } 293b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 294b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato public IntegerValue shiftLeftOf(ParticularIntegerValue other) 295b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato { 296b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato return new ParticularIntegerValue(other.value << this.value); 297b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato } 298b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 299b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato public IntegerValue shiftRightOf(ParticularIntegerValue other) 300b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato { 301b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato return new ParticularIntegerValue(other.value >> this.value); 302b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato } 303b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 304b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato public IntegerValue unsignedShiftRightOf(ParticularIntegerValue other) 305b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato { 306b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato return new ParticularIntegerValue(other.value >>> this.value); 307b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato } 308b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 309b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato public LongValue shiftLeftOf(ParticularLongValue other) 310b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato { 311b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato return new ParticularLongValue(other.value() << this.value); 312b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato } 313b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 314b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato public LongValue shiftRightOf(ParticularLongValue other) 315b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato { 316b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato return new ParticularLongValue(other.value() >> this.value); 317b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato } 318b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 319b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato public LongValue unsignedShiftRightOf(ParticularLongValue other) 320b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato { 321b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato return new ParticularLongValue(other.value() >>> this.value); 322b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato } 323b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 324b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato public IntegerValue and(ParticularIntegerValue other) 325b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato { 326b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato return new ParticularIntegerValue(this.value & other.value); 327b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato } 328b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 329b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato public IntegerValue or(ParticularIntegerValue other) 330b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato { 331b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato return new ParticularIntegerValue(this.value | other.value); 332b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato } 333b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 334b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato public IntegerValue xor(ParticularIntegerValue other) 335b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato { 336b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato return new ParticularIntegerValue(this.value ^ other.value); 337b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato } 338b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 339b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato public int equal(ParticularIntegerValue other) 340b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato { 341b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato return this.value == other.value ? ALWAYS : NEVER; 342b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato } 343b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 344b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato public int lessThan(ParticularIntegerValue other) 345b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato { 346b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato return this.value < other.value ? ALWAYS : NEVER; 347b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato } 348b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 349b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato public int lessThanOrEqual(ParticularIntegerValue other) 350b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato { 351b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato return this.value <= other.value ? ALWAYS : NEVER; 352b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato } 353b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 354b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 355b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato // Implementations for Value. 356b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 357b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato public boolean isParticular() 358b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato { 359b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato return true; 360b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato } 361b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 362b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 363b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato // Implementations for Object. 364b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 365b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato public boolean equals(Object object) 366b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato { 367b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato return super.equals(object) && 368b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato this.value == ((ParticularIntegerValue)object).value; 369b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato } 370b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 371b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 372b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato public int hashCode() 373b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato { 374b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato return this.getClass().hashCode() ^ 375b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato value; 376b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato } 377b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 378b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 379b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato public String toString() 380b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato { 381b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato return Integer.toString(value); 382b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato } 383b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato}