aboutsummaryrefslogtreecommitdiff
path: root/usage_examples/DataExample_post.jpage
blob: 27e3db22ff64d0d6a45bc50bcad709f711f7b55a (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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import java.util.Arrays;

public class DataExample {
	private final String name;
	private int age;
	private double score;
	private String[] tags;
	
	public DataExample(String name) {
		this.name = name;
	}
	
	public String getName() {
		return name;
	}
	
	void setAge(int age) {
		this.age = age;
	}
	
	public int getAge() {
		return age;
	}
	
	public void setScore(double score) {
		this.score = score;
	}
	
	public double getScore() {
		return score;
	}
	
	public String[] getTags() {
		return tags;
	}
	
	public void setTags(String[] tags) {
		this.tags = tags;
	}
	
	@Override public String toString() {
		return "DataExample(" + name + ", " + age + ", " + score + ", " + Arrays.deepToString(tags) + ")";
	}
	
	@Override public boolean equals(Object o) {
		if (o == this) return true;
		if (o == null) return false;
		if (o.getClass() != this.getClass()) return false;
		DataExample other = (DataExample) o;
		if (name == null ? other.name != null : !name.equals(other.name)) return false;
		if (age != other.age) return false;
		if (Double.compare(score, other.score) != 0) return false;
		if (!Arrays.deepEquals(tags, other.tags)) return false;
		return true;
	}
	
	@Override public int hashCode() {
		final int PRIME = 31;
		int result = 1;
		final long temp1 = Double.doubleToLongBits(score);
		result = (result*PRIME) + (name == null ? 0 : name.hashCode());
		result = (result*PRIME) + age;
		result = (result*PRIME) + (int)(temp1 ^ (temp1 >>> 32));
		result = (result*PRIME) + Arrays.deepHashCode(tags);
		return result;
	}
	
	public static class Exercise<T> {
		private final String name;
		private final T value;
		
		private Exercise(String name, T value) {
			this.name = name;
			this.value = value;
		}
		
		public static <T> Exercise<T> of(String name, T value) {
			return new Exercise<T>(name, value);
		}
		
		public String getName() {
			return name;
		}
		
		public T getValue() {
			return value;
		}
		
		@Override public String toString() {
			return "Exercise(" + name + ", " + value + ")";
		}
		
		@Override public boolean equals(Object o) {
			if (o == this) return true;
			if (o == null) return false;
			if (o.getClass() != this.getClass()) return false;
			Exercise<?> other = (Exercise<?>) o;
			if (name == null ? other.name != null : !name.equals(other.name)) return false;
			if (value == null ? other.value != null : !value.equals(other.value)) return false;
			return true;
		}
		
		@Override public int hashCode() {
			final int PRIME = 31;
			int result = 1;
			result = (result*PRIME) + (name == null ? 0 : name.hashCode());
			result = (result*PRIME) + (value == null ? 0 : value.hashCode());
			return result;
		}
	}
}