/*
* Part of the CCNx Java Library.
*
* Copyright (C) 2008, 2009, 2010 Palo Alto Research Center, Inc.
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License version 2.1
* as published by the Free Software Foundation.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details. You should have received
* a copy of the GNU Lesser General Public License along with this library;
* if not, write to the Free Software Foundation, Inc., 51 Franklin Street,
* Fifth Floor, Boston, MA 02110-1301 USA.
*/
package org.ccnx.ccn.impl.support;
/**
* Utility class to represent pairs of objects, most commonly as return
* values from methods.
*/
public class Tuple<A, B> {
A _first;
B _second;
public Tuple(A first, B second) {
_first = first;
_second = second;
}
public A first() { return _first; }
public B second() { return _second; }
public void setFirst(A first) { _first = first; }
public void setSecond(B second) { _second = second; }
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((_first == null) ? 0 : _first.hashCode());
result = prime * result + ((_second == null) ? 0 : _second.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Tuple<?,?> other = (Tuple<?,?>) obj;
if (_first == null) {
if (other._first != null)
return false;
} else if (!_first.equals(other._first))
return false;
if (_second == null) {
if (other._second != null)
return false;
} else if (!_second.equals(other._second))
return false;
return true;
}
}