1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
\r
3 * in Industry THTH ry.
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.utils.threads.internal;
\r
15 * A generic Pair (2-tuple) structure for containing two object instances of
\r
18 * @param <T1> type of first element
\r
19 * @param <T2> type of second element
\r
21 public final class Pair<T1, T2> {
\r
22 public final T1 first;
\r
23 public final T2 second;
\r
24 private final int hash;
\r
26 public Pair(T1 first, T2 second) {
\r
27 assert(first != null);
\r
28 assert(second != null);
\r
31 this.second = second;
\r
32 this.hash = makeHash();
\r
36 public boolean equals(Object obj) {
\r
39 if (!(obj.getClass().equals(this.getClass())))
\r
41 Pair<?, ?> other = (Pair<?, ?>) obj;
\r
42 if (other.first != first && !other.first.equals(first))
\r
44 if (other.second != second && !other.second.equals(second))
\r
50 public int hashCode() {
\r
55 public String toString() {
\r
56 return "<"+first+", "+second+">";
\r
59 private int makeHash() {
\r
60 return first.hashCode() ^ second.hashCode()*7;
\r