/* This program is free software: you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public License
as published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
package org.opentripplanner.common.model;
import java.io.Serializable;
/**
* An ordered pair of objects of potentially different types
*
*/
public class T2<E1, E2> implements Serializable {
private static final long serialVersionUID = 1L;
private final E1 _first;
private final E2 _second;
public T2(E1 first, E2 second) {
_first = first;
_second = second;
}
public E1 getFirst() {
return _first;
}
public E2 getSecond() {
return _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;
T2<?, ?> other = (T2<?, ?>) 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;
}
public String toString() {
return "T2(" + _first + ", " + _second + ")";
}
}