| /* |
| * Copyright (C) 2004-2020 Savoir-faire Linux Inc. |
| * |
| * Author: Alexandre Lision <alexandre.lision@savoirfairelinux.com> |
| * |
| * This program is free software; you can redistribute it and/or modify |
| * it under the terms of the GNU 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, write to the Free Software |
| * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| */ |
| package cx.ring.utils; |
| |
| public class Tuple<X, Y> { |
| public final X first; |
| public final Y second; |
| |
| public Tuple(X first, Y second) { |
| this.first = first; |
| this.second = second; |
| } |
| |
| @Override |
| public String toString() { |
| return "(" + first + "," + second + ")"; |
| } |
| |
| @Override |
| public boolean equals(Object other) { |
| if (other == this) { |
| return true; |
| } |
| |
| if (!(other instanceof Tuple)) { |
| return false; |
| } |
| |
| Tuple<X, Y> other_ = (Tuple<X, Y>) other; |
| |
| // this may cause NPE if nulls are valid values for first or second. |
| // The logic may be improved to handle nulls properly, if needed. |
| return other_.first.equals(this.first) && other_.second.equals(this.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; |
| } |
| } |