Created
September 1, 2020 12:36
-
-
Save albertoventurini/353d2060caff2ef8c38372798748290a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Objects; | |
/** | |
* This class represents a pair of values. | |
*/ | |
public class Pair<T1, T2> { | |
public final T1 first; | |
public final T2 second; | |
private Pair(final T1 first, final T2 second) { | |
this.first = first; | |
this.second = second; | |
} | |
public static <U1, U2> Pair<U1, U2> of(final U1 first, final U2 second) { | |
return new Pair<>(first, second); | |
} | |
@Override | |
public boolean equals(final Object o) { | |
if (this == o) return true; | |
if (o == null || getClass() != o.getClass()) return false; | |
final Pair<?, ?> pair = (Pair<?, ?>) o; | |
return Objects.equals(first, pair.first) && | |
Objects.equals(second, pair.second); | |
} | |
@Override | |
public int hashCode() { | |
return Objects.hash(first, second); | |
} | |
@Override | |
public String toString() { | |
return "Pair{" + | |
"first=" + first + | |
", second=" + second + | |
'}'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment