Skip to content

Commit 360af1e

Browse files
authored
Merge pull request #22 from RUB-NDS/equals-hashcode
Generate equals, hashCode and toString Methods
2 parents 245180e + f1a03f9 commit 360af1e

File tree

15 files changed

+840
-0
lines changed

15 files changed

+840
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ release.properties
77
dependency-reduced-pom.xml
88
buildNumber.properties
99
.mvn/timing.properties
10+
/nbproject/

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,28 @@ public BigInteger getOriginalValue() {
7575
public void setOriginalValue(BigInteger originalValue) {
7676
this.originalValue = originalValue;
7777
}
78+
79+
@Override
80+
public String toString() {
81+
return "ModifiableBigInteger{" + "originalValue=" + originalValue + '}';
82+
}
83+
84+
@Override
85+
public boolean equals(Object o) {
86+
if (this == o)
87+
return true;
88+
if (!(o instanceof ModifiableBigInteger))
89+
return false;
90+
91+
ModifiableBigInteger that = (ModifiableBigInteger) o;
92+
93+
return getValue() != null ? getValue().equals(that.getValue()) : that.getValue() == null;
94+
}
95+
96+
@Override
97+
public int hashCode() {
98+
int result = super.hashCode();
99+
result = 31 * result + (getValue() != null ? getValue().hashCode() : 0);
100+
return result;
101+
}
78102
}

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,28 @@ public boolean validateAssertions() {
6464
}
6565
return true;
6666
}
67+
68+
@Override
69+
public String toString() {
70+
return "ModifiableBoolean{" + "originalValue=" + originalValue + '}';
71+
}
72+
73+
@Override
74+
public boolean equals(Object o) {
75+
if (this == o)
76+
return true;
77+
if (!(o instanceof ModifiableBoolean))
78+
return false;
79+
80+
ModifiableBoolean that = (ModifiableBoolean) o;
81+
82+
return getValue() != null ? getValue().equals(that.getValue()) : that.getValue() == null;
83+
}
84+
85+
@Override
86+
public int hashCode() {
87+
int result = super.hashCode();
88+
result = 31 * result + (getValue() != null ? getValue().hashCode() : 0);
89+
return result;
90+
}
6791
}

src/main/java/de/rub/nds/modifiablevariable/bytearray/ModifiableByteArray.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,22 @@ public String toString() {
9090

9191
}
9292

93+
@Override
94+
public boolean equals(Object o) {
95+
if (this == o)
96+
return true;
97+
if (!(o instanceof ModifiableByteArray))
98+
return false;
99+
100+
ModifiableByteArray that = (ModifiableByteArray) o;
101+
102+
return Arrays.equals(getValue(), that.getValue());
103+
}
104+
105+
@Override
106+
public int hashCode() {
107+
int result = super.hashCode();
108+
result = 31 * result + Arrays.hashCode(getValue());
109+
return result;
110+
}
93111
}

src/main/java/de/rub/nds/modifiablevariable/integer/ModifiableInteger.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,28 @@ public Integer getOriginalValue() {
7171
public void setOriginalValue(Integer originalValue) {
7272
this.originalValue = originalValue;
7373
}
74+
75+
@Override
76+
public String toString() {
77+
return "ModifiableInteger{" + "originalValue=" + originalValue + '}';
78+
}
79+
80+
@Override
81+
public boolean equals(Object o) {
82+
if (this == o)
83+
return true;
84+
if (!(o instanceof ModifiableInteger))
85+
return false;
86+
87+
ModifiableInteger that = (ModifiableInteger) o;
88+
89+
return getValue() != null ? getValue().equals(that.getValue()) : that.getValue() == null;
90+
}
91+
92+
@Override
93+
public int hashCode() {
94+
int result = super.hashCode();
95+
result = 31 * result + (getValue() != null ? getValue().hashCode() : 0);
96+
return result;
97+
}
7498
}

src/main/java/de/rub/nds/modifiablevariable/length/ModifiableLengthField.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,28 @@ public Integer getOriginalValue() {
4343
public void setOriginalValue(Integer originalValue) {
4444
throw new UnsupportedOperationException("Cannot set original Value of ModifiableLengthField");
4545
}
46+
47+
@Override
48+
public String toString() {
49+
return "ModifiableLengthField{" + "ref=" + ref + "} " + super.toString();
50+
}
51+
52+
@Override
53+
public boolean equals(Object o) {
54+
if (this == o)
55+
return true;
56+
if (!(o instanceof ModifiableLengthField))
57+
return false;
58+
59+
ModifiableLengthField that = (ModifiableLengthField) o;
60+
61+
return ref != null ? getValue().equals(that.getValue()) : that.getValue() == null;
62+
}
63+
64+
@Override
65+
public int hashCode() {
66+
int result = super.hashCode();
67+
result = 31 * result + (getValue() != null ? getValue().hashCode() : 0);
68+
return result;
69+
}
4670
}

src/main/java/de/rub/nds/modifiablevariable/mlong/ModifiableLong.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,28 @@ public Long getOriginalValue() {
7171
public void setOriginalValue(Long originalValue) {
7272
this.originalValue = originalValue;
7373
}
74+
75+
@Override
76+
public String toString() {
77+
return "ModifiableLong{" + "originalValue=" + originalValue + '}';
78+
}
79+
80+
@Override
81+
public boolean equals(Object o) {
82+
if (this == o)
83+
return true;
84+
if (!(o instanceof ModifiableLong))
85+
return false;
86+
87+
ModifiableLong that = (ModifiableLong) o;
88+
89+
return getValue() != null ? getValue().equals(that.getValue()) : that.getValue() == null;
90+
}
91+
92+
@Override
93+
public int hashCode() {
94+
int result = super.hashCode();
95+
result = 31 * result + (getValue() != null ? getValue().hashCode() : 0);
96+
return result;
97+
}
7498
}

src/main/java/de/rub/nds/modifiablevariable/singlebyte/ModifiableByte.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,28 @@ public Byte getOriginalValue() {
6666
public void setOriginalValue(Byte originalValue) {
6767
this.originalValue = originalValue;
6868
}
69+
70+
@Override
71+
public String toString() {
72+
return "ModifiableByte{" + "originalValue=" + originalValue + '}';
73+
}
74+
75+
@Override
76+
public boolean equals(Object o) {
77+
if (this == o)
78+
return true;
79+
if (!(o instanceof ModifiableByte))
80+
return false;
81+
82+
ModifiableByte that = (ModifiableByte) o;
83+
84+
return getValue() != null ? getValue().equals(that.getValue()) : that.getValue() == null;
85+
}
86+
87+
@Override
88+
public int hashCode() {
89+
int result = super.hashCode();
90+
result = 31 * result + (getValue() != null ? getValue().hashCode() : 0);
91+
return result;
92+
}
6993
}
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
/*
2+
* Copyright 2017 Robert Merget <robert.merget@rub.de>.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package de.rub.nds.modifiablevariable.biginteger;
17+
18+
import java.math.BigInteger;
19+
import org.junit.Before;
20+
import org.junit.Test;
21+
import static org.junit.Assert.*;
22+
23+
/**
24+
*
25+
* @author Robert Merget <robert.merget@rub.de>
26+
*/
27+
public class ModifiableBigIntegerTest {
28+
29+
private ModifiableBigInteger integer1;
30+
31+
private ModifiableBigInteger integer2;
32+
33+
@Before
34+
public void setUp() {
35+
integer1 = new ModifiableBigInteger();
36+
integer1.setOriginalValue(BigInteger.ONE);
37+
integer2 = new ModifiableBigInteger();
38+
integer2.setOriginalValue(BigInteger.TEN);
39+
}
40+
41+
/**
42+
* Test of createRandomModification method, of class ModifiableBigInteger.
43+
*/
44+
@Test
45+
public void testCreateRandomModification() {
46+
}
47+
48+
/**
49+
* Test of getAssertEquals method, of class ModifiableBigInteger.
50+
*/
51+
@Test
52+
public void testGetAssertEquals() {
53+
}
54+
55+
/**
56+
* Test of setAssertEquals method, of class ModifiableBigInteger.
57+
*/
58+
@Test
59+
public void testSetAssertEquals() {
60+
}
61+
62+
/**
63+
* Test of isOriginalValueModified method, of class ModifiableBigInteger.
64+
*/
65+
@Test
66+
public void testIsOriginalValueModified() {
67+
}
68+
69+
/**
70+
* Test of getByteArray method, of class ModifiableBigInteger.
71+
*/
72+
@Test
73+
public void testGetByteArray_0args() {
74+
}
75+
76+
/**
77+
* Test of getByteArray method, of class ModifiableBigInteger.
78+
*/
79+
@Test
80+
public void testGetByteArray_int() {
81+
}
82+
83+
/**
84+
* Test of validateAssertions method, of class ModifiableBigInteger.
85+
*/
86+
@Test
87+
public void testValidateAssertions() {
88+
}
89+
90+
/**
91+
* Test of getOriginalValue method, of class ModifiableBigInteger.
92+
*/
93+
@Test
94+
public void testGetOriginalValue() {
95+
}
96+
97+
/**
98+
* Test of setOriginalValue method, of class ModifiableBigInteger.
99+
*/
100+
@Test
101+
public void testSetOriginalValue() {
102+
}
103+
104+
/**
105+
* Test of toString method, of class ModifiableBigInteger.
106+
*/
107+
@Test
108+
public void testToString() {
109+
}
110+
111+
/**
112+
* Test of equals method, of class ModifiableBigInteger.
113+
*/
114+
@Test
115+
public void testEquals() {
116+
assertFalse(integer1.equals(integer2));
117+
integer2.setOriginalValue(BigInteger.ONE);
118+
assertTrue(integer1.equals(integer2));
119+
}
120+
121+
/**
122+
* Test of hashCode method, of class ModifiableBigInteger.
123+
*/
124+
@Test
125+
public void testHashCode() {
126+
}
127+
128+
}

0 commit comments

Comments
 (0)