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