001 /*BEGIN_COPYRIGHT_BLOCK
002 *
003 * Copyright (c) 2001-2010, JavaPLT group at Rice University (drjava@rice.edu). All rights reserved.
004 *
005 * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
006 * following conditions are met:
007 * * Redistributions of source code must retain the above copyright notice, this list of conditions and the
008 * following disclaimer.
009 * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
010 * following disclaimer in the documentation and/or other materials provided with the distribution.
011 * * Neither the names of DrJava, the JavaPLT group, Rice University, nor the names of its contributors may be used
012 * to endorse or promote products derived from this software without specific prior written permission.
013 *
014 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
015 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
016 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
017 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
018 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
019 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
020 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
021 *
022 * This software is Open Source Initiative approved Open Source Software. Open Source Initative Approved is a trademark
023 * of the Open Source Initiative.
024 *
025 * This file is part of DrJava. Download the current version of this project from http://www.drjava.org/ or
026 * http://sourceforge.net/projects/drjava/
027 *
028 * END_COPYRIGHT_BLOCK*/
029
030 package edu.rice.cs.javalanglevels;
031
032 /** Utility class, allows us to store two things as a single object. */
033 public class Pair<T,U> {
034 T _first;
035 U _second;
036
037 public Pair(T first, U second) {
038 _first = first;
039 _second = second;
040 }
041
042 public T getFirst() { return _first; }
043
044 public U getSecond() { return _second; }
045
046 public boolean equals(Object o) {
047 return (o != null) && (o.getClass() == this.getClass()) &&
048 getFirst().equals(((Pair) o).getFirst()) && getSecond().equals(((Pair) o).getSecond());
049 }
050
051 /** Define a hash code based on the first and second's hash code */
052 public int hashCode() { return _first.hashCode() ^ _second.hashCode(); }
053
054 public String toString() { return "Pair(" + _first + ", " + _second + ")"; }
055 }