Skip to content

Instantly share code, notes, and snippets.

@cyclotimia
Last active March 12, 2016 11:27
Show Gist options
  • Save cyclotimia/04269e7956adc9f98d55 to your computer and use it in GitHub Desktop.
Save cyclotimia/04269e7956adc9f98d55 to your computer and use it in GitHub Desktop.
class Pair<T, M> {
private final T first;
private final M second;
// конструктор
private Pair(T value1, M value2) {
this.first = value1;
this.second = value2;
}
// получить первый эл-т пары
public T getFirst() {
return this.first;
}
// получить второй эл-т пары
public M getSecond() {
return this.second;
}
// equals
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null || getClass() != obj.getClass()) return false;
Pair<?, ?> pair = (Pair<?, ?>) obj;
if (first != null ? !first.equals(pair.first) : pair.first != null) return false;
return !(second != null ? !second.equals(pair.second) : pair.second != null);
}
// hashcode
@Override
public int hashCode() {
int result = first != null ? first.hashCode() : 0;
result = 31 * result + (second != null ? second.hashCode() : 0);
return result;
}
// конструктор
public static <T, M> Pair of(T value1, M value2) {
return new Pair(value1, value2);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment