001
002 /*****************************************************************************
003
004 jBudget.
005 Copyright (C) 2006 Dmitri Petrov
006
007 This program is free software: you can redistribute it and/or modify
008 it under the terms of the GNU General Public License as published by
009 the Free Software Foundation, either version 3 of the License, or
010 (at your option) any later version.
011
012 This program is distributed in the hope that it will be useful,
013 but WITHOUT ANY WARRANTY; without even the implied warranty of
014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
015 GNU General Public License for more details.
016
017 You should have received a copy of the GNU General Public License
018 along with this program. If not, see <http://www.gnu.org/licenses/>.
019
020 /*****************************************************************************
021
022 /*
023 * Pair.java
024 *
025 * Created on May 12, 2006, 6:12 PM
026 */
027
028 package org.jbudget.util;
029
030 /**
031 * A generic class that contains references to two objects of different
032 * types.
033 * @author petrov
034 */
035
036 public class Pair<T,U>
037 {
038 private final T firstElement;
039 private final U secondElement;
040
041 /** Creates a new instance of Pair */
042 public Pair(T first, U second){
043 firstElement = first;
044 secondElement = second;
045 }
046
047 public T first(){return firstElement;}
048 public U second(){return secondElement;}
049
050 public boolean equals (Object o){
051 if (!(o instanceof Pair))
052 return false;
053
054 Pair otherPair = (Pair)o;
055 return firstElement.equals(otherPair.firstElement) &&
056 secondElement.equals(otherPair.secondElement);
057 }
058
059 public String toString(){
060 return firstElement.toString() + ":" + secondElement.toString();
061 }
062
063 public int hashCode()
064 {
065 return firstElement.hashCode();
066 }
067
068 }