summaryrefslogtreecommitdiff
path: root/src/test/java/au/id/zancanaro/javacheck/object/MyObject.java
blob: ac0c3701a2b75ce013cef59733d28779d4d83422 (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package au.id.zancanaro.javacheck.object;

public class MyObject {
    public final String string;
    public final int value;
    public final SubObject<Integer> subObject;

    public MyObject(String string, int value, SubObject<Integer> subObject) {
        this.string = string;
        this.value = value;
        this.subObject = subObject;
    }

    @UseForGeneration
    public MyObject(String string, SubObject<Integer> subObject) {
        this(string, string.length(), subObject);
    }

    public MyObject add(MyObject other) {
        return new MyObject(
                this.string + other.string,
                this.value + other.value,
                this.subObject.add(other.subObject));
    }

    @Override
    public String toString() {
        return "{" + string + ", " + value + ", " + subObject + "}";
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        MyObject myObject = (MyObject) o;

        return value == myObject.value
                && string.equals(myObject.string)
                && subObject.equals(myObject.subObject);
    }

    @Override
    public int hashCode() {
        int result = string.hashCode();
        result = 31 * result + value;
        result = 31 * result + subObject.hashCode();
        return result;
    }
}