Skip to content

Commit 38f943f

Browse files
authored
Merge pull request #33 from RUB-NDS/2.5equalsHashcode
Implemented Equals and Hashcode Methods
2 parents 242572f + 1a5c549 commit 38f943f

File tree

41 files changed

+1423
-11
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1423
-11
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>de.rub.nds</groupId>
55
<artifactId>ModifiableVariable</artifactId>
6-
<version>2.4</version>
6+
<version>2.5</version>
77
<packaging>jar</packaging>
88

99
<name>ModifiableVariable</name>

src/main/java/de/rub/nds/modifiablevariable/VariableModification.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import de.rub.nds.modifiablevariable.biginteger.BigIntegerSubtractModification;
1717
import de.rub.nds.modifiablevariable.biginteger.BigIntegerXorModification;
1818
import de.rub.nds.modifiablevariable.bool.BooleanExplicitValueModification;
19-
import de.rub.nds.modifiablevariable.bool.BooleanToogleModification;
19+
import de.rub.nds.modifiablevariable.bool.BooleanToggleModification;
2020
import de.rub.nds.modifiablevariable.bytearray.*;
2121
import de.rub.nds.modifiablevariable.filter.AccessModificationFilter;
2222
import de.rub.nds.modifiablevariable.integer.IntegerAddModification;
@@ -42,7 +42,7 @@
4242
@XmlTransient
4343
@XmlSeeAlso({ AccessModificationFilter.class, BigIntegerAddModification.class, BigIntegerInteractiveModification.class,
4444
BigIntegerExplicitValueModification.class, BigIntegerSubtractModification.class,
45-
BooleanExplicitValueModification.class, BooleanToogleModification.class, BigIntegerXorModification.class,
45+
BooleanExplicitValueModification.class, BooleanToggleModification.class, BigIntegerXorModification.class,
4646
BigIntegerShiftLeftModification.class, BigIntegerShiftRightModification.class, IntegerAddModification.class,
4747
IntegerExplicitValueModification.class, IntegerSubtractModification.class, IntegerXorModification.class,
4848
IntegerShiftLeftModification.class, IntegerShiftRightModification.class, ByteArrayDeleteModification.class,

src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerAddModification.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
import de.rub.nds.modifiablevariable.VariableModification;
1212
import java.math.BigInteger;
13+
import java.util.Objects;
1314
import java.util.Random;
1415
import javax.xml.bind.annotation.XmlRootElement;
1516
import javax.xml.bind.annotation.XmlType;
@@ -47,4 +48,30 @@ public void setSummand(BigInteger summand) {
4748
public VariableModification<BigInteger> getModifiedCopy() {
4849
return new BigIntegerAddModification(summand.add(new BigInteger(MAX_ADD_LENGTH, new Random())));
4950
}
51+
52+
@Override
53+
public int hashCode() {
54+
int hash = 7;
55+
hash = 41 * hash + Objects.hashCode(this.summand);
56+
return hash;
57+
}
58+
59+
@Override
60+
public boolean equals(Object obj) {
61+
if (this == obj) {
62+
return true;
63+
}
64+
if (obj == null) {
65+
return false;
66+
}
67+
if (getClass() != obj.getClass()) {
68+
return false;
69+
}
70+
final BigIntegerAddModification other = (BigIntegerAddModification) obj;
71+
if (!Objects.equals(this.summand, other.summand)) {
72+
return false;
73+
}
74+
return true;
75+
}
76+
5077
}

src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerExplicitValueModification.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
import de.rub.nds.modifiablevariable.VariableModification;
1212
import java.math.BigInteger;
13+
import java.util.Objects;
1314
import java.util.Random;
1415
import javax.xml.bind.annotation.XmlRootElement;
1516
import javax.xml.bind.annotation.XmlType;
@@ -52,4 +53,29 @@ public VariableModification<BigInteger> getModifiedCopy() {
5253
explicitValue.subtract(new BigInteger(MAX_EXPLICIT_LENGTH, r)));
5354
}
5455
}
56+
57+
@Override
58+
public int hashCode() {
59+
int hash = 3;
60+
hash = 41 * hash + Objects.hashCode(this.explicitValue);
61+
return hash;
62+
}
63+
64+
@Override
65+
public boolean equals(Object obj) {
66+
if (this == obj) {
67+
return true;
68+
}
69+
if (obj == null) {
70+
return false;
71+
}
72+
if (getClass() != obj.getClass()) {
73+
return false;
74+
}
75+
final BigIntegerExplicitValueModification other = (BigIntegerExplicitValueModification) obj;
76+
if (!Objects.equals(this.explicitValue, other.explicitValue)) {
77+
return false;
78+
}
79+
return true;
80+
}
5581
}

src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerShiftLeftModification.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,29 @@ public void setShift(int shift) {
5050
public VariableModification<BigInteger> getModifiedCopy() {
5151
return new BigIntegerShiftLeftModification(shift + new Random().nextInt(MAX_SHIFT_LENGTH));
5252
}
53+
54+
@Override
55+
public int hashCode() {
56+
int hash = 7;
57+
hash = 97 * hash + this.shift;
58+
return hash;
59+
}
60+
61+
@Override
62+
public boolean equals(Object obj) {
63+
if (this == obj) {
64+
return true;
65+
}
66+
if (obj == null) {
67+
return false;
68+
}
69+
if (getClass() != obj.getClass()) {
70+
return false;
71+
}
72+
final BigIntegerShiftLeftModification other = (BigIntegerShiftLeftModification) obj;
73+
if (this.shift != other.shift) {
74+
return false;
75+
}
76+
return true;
77+
}
5378
}

src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerShiftRightModification.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,29 @@ public void setShift(int shift) {
5050
public VariableModification<BigInteger> getModifiedCopy() {
5151
return new BigIntegerShiftRightModification(shift + new Random().nextInt(MAX_SHIFT_LENGTH));
5252
}
53+
54+
@Override
55+
public int hashCode() {
56+
int hash = 7;
57+
hash = 97 * hash + this.shift;
58+
return hash;
59+
}
60+
61+
@Override
62+
public boolean equals(Object obj) {
63+
if (this == obj) {
64+
return true;
65+
}
66+
if (obj == null) {
67+
return false;
68+
}
69+
if (getClass() != obj.getClass()) {
70+
return false;
71+
}
72+
final BigIntegerShiftRightModification other = (BigIntegerShiftRightModification) obj;
73+
if (this.shift != other.shift) {
74+
return false;
75+
}
76+
return true;
77+
}
5378
}

src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerSubtractModification.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
import de.rub.nds.modifiablevariable.VariableModification;
1212
import java.math.BigInteger;
13+
import java.util.Objects;
1314
import java.util.Random;
1415
import javax.xml.bind.annotation.XmlRootElement;
1516
import javax.xml.bind.annotation.XmlType;
@@ -50,4 +51,29 @@ public void setSubtrahend(BigInteger subtrahend) {
5051
public VariableModification<BigInteger> getModifiedCopy() {
5152
return new BigIntegerSubtractModification(subtrahend.add(new BigInteger(MAX_SUBTRACT_LENGTH, new Random())));
5253
}
54+
55+
@Override
56+
public int hashCode() {
57+
int hash = 5;
58+
hash = 61 * hash + Objects.hashCode(this.subtrahend);
59+
return hash;
60+
}
61+
62+
@Override
63+
public boolean equals(Object obj) {
64+
if (this == obj) {
65+
return true;
66+
}
67+
if (obj == null) {
68+
return false;
69+
}
70+
if (getClass() != obj.getClass()) {
71+
return false;
72+
}
73+
final BigIntegerSubtractModification other = (BigIntegerSubtractModification) obj;
74+
if (!Objects.equals(this.subtrahend, other.subtrahend)) {
75+
return false;
76+
}
77+
return true;
78+
}
5379
}

src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerXorModification.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
import de.rub.nds.modifiablevariable.VariableModification;
1212
import java.math.BigInteger;
13+
import java.util.Objects;
1314
import java.util.Random;
1415
import javax.xml.bind.annotation.XmlRootElement;
1516
import javax.xml.bind.annotation.XmlType;
@@ -50,4 +51,29 @@ public void setXor(BigInteger xor) {
5051
public VariableModification<BigInteger> getModifiedCopy() {
5152
return new BigIntegerXorModification(xor.add(new BigInteger(MAX_XOR_LENGTH, new Random())));
5253
}
54+
55+
@Override
56+
public int hashCode() {
57+
int hash = 7;
58+
hash = 97 * hash + Objects.hashCode(this.xor);
59+
return hash;
60+
}
61+
62+
@Override
63+
public boolean equals(Object obj) {
64+
if (this == obj) {
65+
return true;
66+
}
67+
if (obj == null) {
68+
return false;
69+
}
70+
if (getClass() != obj.getClass()) {
71+
return false;
72+
}
73+
final BigIntegerXorModification other = (BigIntegerXorModification) obj;
74+
if (!Objects.equals(this.xor, other.xor)) {
75+
return false;
76+
}
77+
return true;
78+
}
5379
}

src/main/java/de/rub/nds/modifiablevariable/bool/BooleanExplicitValueModification.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,35 @@ public void setExplicitValue(boolean explicitValue) {
4242
public VariableModification<Boolean> getModifiedCopy() {
4343
return new BooleanExplicitValueModification(!explicitValue);
4444
}
45+
46+
@Override
47+
public int hashCode() {
48+
int hash = 7;
49+
hash = 29 * hash + (this.explicitValue ? 1 : 0);
50+
return hash;
51+
}
52+
53+
@Override
54+
public boolean equals(Object obj) {
55+
if (this == obj) {
56+
return true;
57+
}
58+
if (obj == null) {
59+
return false;
60+
}
61+
if (getClass() != obj.getClass()) {
62+
return false;
63+
}
64+
final BooleanExplicitValueModification other = (BooleanExplicitValueModification) obj;
65+
if (this.explicitValue != other.explicitValue) {
66+
return false;
67+
}
68+
return true;
69+
}
70+
71+
@Override
72+
public String toString() {
73+
return "BooleanExplicitValueModification{" + "explicitValue=" + explicitValue + '}';
74+
}
75+
4576
}

src/main/java/de/rub/nds/modifiablevariable/bool/BooleanModificationFactory.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ public static VariableModification<Boolean> createRandomModification() {
2424
case 1:
2525
return new BooleanExplicitValueModification(false);
2626
case 2:
27-
return new BooleanToogleModification();
27+
return new BooleanToggleModification();
2828
}
2929
return null;
3030
}
3131

3232
public static VariableModification<Boolean> toogle() {
33-
return new BooleanToogleModification();
33+
return new BooleanToggleModification();
3434
}
3535

3636
public static VariableModification<Boolean> explicitValue(final boolean explicitValue) {

0 commit comments

Comments
 (0)