Skip to main content
summaryrefslogtreecommitdiffstats
blob: be97ba2bdeb418fadd102db84ef33b50d1384998 (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
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
/*******************************************************************************
 * Copyright (c) 2005, 2007 committers of openArchitectureWare and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     committers of openArchitectureWare - initial API and implementation
 *******************************************************************************/
package org.eclipse.internal.xtend.util;

import java.io.Serializable;

/**
 * This class provides combines three objects into one, giving them appropriate
 * equals and hashCode methods.
 * 
 * @author Arno Haase
 */
public class Triplet<T1, T2, T3> implements Serializable, Cloneable {
	private static final long serialVersionUID = -3721045730655830208L;

	private T1 _first;

	private T2 _second;

	private T3 _third;

	public Triplet(T1 first, T2 second, T3 third) {
		_first = first;
		_second = second;
		_third = third;
	}

	public T1 getFirst() {
		return _first;
	}

	public T2 getSecond() {
		return _second;
	}

	public T3 getThird() {
		return _third;
	}

	public void setFirst(T1 first) {
		_first = first;
	}

	public void setSecond(T2 second) {
		_second = second;
	}

	public void setThird(T3 third) {
		_third = third;
	}

	public String toString() {
		return "Triplet [" + _first + ", " + _second + ", " + _third + "]";
	}

	public boolean equals(Object o) {
		if (this == o)
			return true;
		if (!(o instanceof Triplet))
			return false;

		final Triplet<?, ?, ?> triplet = (Triplet<?, ?, ?>) o;

		if (_first != null ? !_first.equals(triplet._first) : triplet._first != null)
			return false;
		if (_second != null ? !_second.equals(triplet._second) : triplet._second != null)
			return false;
		if (_third != null ? !_third.equals(triplet._third) : triplet._third != null)
			return false;

		return true;
	}

	public int hashCode() {
		int result;
		result = (_first != null ? _first.hashCode() : 0);
		result = 29 * result + (_second != null ? _second.hashCode() : 0);
		result = 29 * result + (_third != null ? _third.hashCode() : 0);
		return result;
	}

	public Object clone() {
		try {
			return super.clone();
		} catch (CloneNotSupportedException e) {
			throw new InternalError("Should not be thrown: " + e);
		}
	}
}

Back to the top