|
| 1 | +/** |
| 2 | + * ModifiableVariable - A Variable Concept for Runtime Modifications |
| 3 | + * |
| 4 | + * Copyright 2014-2017 Ruhr University Bochum / Hackmanit GmbH |
| 5 | + * |
| 6 | + * Licensed under Apache License 2.0 |
| 7 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | + */ |
| 9 | +package de.rub.nds.modifiablevariable.biginteger; |
| 10 | + |
| 11 | +import de.rub.nds.modifiablevariable.VariableModification; |
| 12 | +import java.math.BigInteger; |
| 13 | +import java.util.Objects; |
| 14 | +import java.util.Random; |
| 15 | +import javax.xml.bind.annotation.XmlAccessType; |
| 16 | +import javax.xml.bind.annotation.XmlAccessorType; |
| 17 | +import javax.xml.bind.annotation.XmlRootElement; |
| 18 | +import javax.xml.bind.annotation.XmlType; |
| 19 | + |
| 20 | +@XmlRootElement |
| 21 | +@XmlType(propOrder = { "factor", "modificationFilter" }) |
| 22 | +@XmlAccessorType(XmlAccessType.FIELD) |
| 23 | +public class BigIntegerMultiplyModification extends VariableModification<BigInteger> { |
| 24 | + |
| 25 | + private final static int MAX_FACTOR_LENGTH = 8; |
| 26 | + |
| 27 | + private BigInteger factor; |
| 28 | + |
| 29 | + public BigIntegerMultiplyModification() { |
| 30 | + |
| 31 | + } |
| 32 | + |
| 33 | + public BigIntegerMultiplyModification(BigInteger bi) { |
| 34 | + this.factor = bi; |
| 35 | + } |
| 36 | + |
| 37 | + @Override |
| 38 | + protected BigInteger modifyImplementationHook(BigInteger input) { |
| 39 | + if (input == null) { |
| 40 | + input = BigInteger.ZERO; |
| 41 | + } |
| 42 | + return input.multiply(factor); |
| 43 | + } |
| 44 | + |
| 45 | + public BigInteger getFactor() { |
| 46 | + return factor; |
| 47 | + } |
| 48 | + |
| 49 | + public void setFactor(BigInteger factor) { |
| 50 | + this.factor = factor; |
| 51 | + } |
| 52 | + |
| 53 | + @Override |
| 54 | + public VariableModification<BigInteger> getModifiedCopy() { |
| 55 | + return new BigIntegerMultiplyModification(factor.add(new BigInteger(MAX_FACTOR_LENGTH, new Random()))); |
| 56 | + } |
| 57 | + |
| 58 | + @Override |
| 59 | + public int hashCode() { |
| 60 | + int hash = 5; |
| 61 | + hash = 61 * hash + Objects.hashCode(this.factor); |
| 62 | + return hash; |
| 63 | + } |
| 64 | + |
| 65 | + @Override |
| 66 | + public boolean equals(Object obj) { |
| 67 | + if (this == obj) { |
| 68 | + return true; |
| 69 | + } |
| 70 | + if (obj == null) { |
| 71 | + return false; |
| 72 | + } |
| 73 | + if (getClass() != obj.getClass()) { |
| 74 | + return false; |
| 75 | + } |
| 76 | + final BigIntegerMultiplyModification other = (BigIntegerMultiplyModification) obj; |
| 77 | + if (!Objects.equals(this.factor, other.factor)) { |
| 78 | + return false; |
| 79 | + } |
| 80 | + return true; |
| 81 | + } |
| 82 | +} |
0 commit comments