001package org.jadira.reflection.core.identity; 002 003import java.util.Objects; 004 005public final class Tuple<L, R> { 006 007 // TODO Add toString and Comparable 008 009 public final L left; 010 public final R right; 011 012 public static <L, R> Tuple<L, R> of(L left, R right) { 013 return new Tuple<L, R>(left, right); 014 } 015 016 public Tuple(L left, R right) { 017 this.left = left; 018 this.right = right; 019 } 020 021 public L getLeft() { 022 return left; 023 } 024 025 public R getRight() { 026 return right; 027 } 028 029 @Override 030 public boolean equals(Object obj) { 031 if (obj == this) { 032 return true; 033 } 034 if (obj instanceof Tuple<?, ?>) { 035 Tuple<?, ?> other = (Tuple<?, ?>) obj; 036 return Objects.equals(getLeft(), other.getLeft()) 037 && Objects.equals(getRight(), other.getRight()); 038 } 039 return false; 040 } 041 042 @Override 043 public int hashCode() { 044 return (getLeft() == null ? 0 : getLeft().hashCode()) 045 ^ (getRight() == null ? 0 : getRight().hashCode()); 046 } 047}