Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: cd474dc7e9855ddcd7eb8f1653e6e214a6f024a3 (plain) (blame)
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
package org.eclipse.emf.teneo.samples.emf.hibernate.usertype;

/**
 * Trivial example implementation of a specific type.
 */
public class UsaPhoneNumber {

	private int num1;
	private int num2;
	private int num3;

	public UsaPhoneNumber(int num1, int num2, int num3) {
		this.num1 = num1;
		this.num2 = num2;
		this.num3 = num3;
	}

	public UsaPhoneNumber(String numbers) {
		String[] nums = numbers.split("_");
		num1 = Integer.parseInt(nums[0]);
		num2 = Integer.parseInt(nums[1]);
		num3 = Integer.parseInt(nums[2]);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	public boolean equals(Object obj) {
		if (!(obj instanceof UsaPhoneNumber)) {
			return false;
		}
		UsaPhoneNumber up = (UsaPhoneNumber) obj;
		return up.num1 == num1 && up.num2 == num2 && up.num3 == num3;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#hashCode()
	 */
	public int hashCode() {
		return num1 + num2 + num3;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#toString()
	 */
	public String toString() {
		return num1 + "_" + num2 + "_" + num3;
	}
}

Back to the top