com.github.romanqed.jutils.util.Pair Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jutils Show documentation
Show all versions of jutils Show documentation
A set of simple utilities for implementing missing functionality in different versions of Java.
package com.github.romanqed.jutils.util;
import java.util.Objects;
public class Pair {
protected final K key;
protected final V value;
public Pair(K key, V value) {
this.key = key;
this.value = value;
}
public K getKey() {
return key;
}
public V getValue() {
return value;
}
@Override
public String toString() {
return key + "=" + value;
}
@Override
public int hashCode() {
return Checks.requireNonNullElse(key.hashCode(), 0) * 13 +
Checks.requireNonNullElse(value.hashCode(), 0);
}
@Override
@SuppressWarnings("unchecked")
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof Pair)) {
return false;
}
Pair pair;
try {
pair = (Pair) o;
} catch (Exception e) {
return false;
}
return Objects.equals(key, pair.key) && Objects.equals(value, pair.value);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy