Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package common.utils;
- import java.util.Collection;
- import java.util.Set;
- public interface TriMap<K, V1, V2> {
- public TriMap<V1,V2,K> rotateKey();
- public TriMap<V2,K,V1> reverseRotateKey();
- public Set<TriMap.TriEntry<K, V1, V2>> entrySet();
- public Collection<TriMap.TriValue<V1, V2>> values();
- public Set<K> getKeySet();
- public boolean containsKey(K key);
- public boolean containsValue(TriMap.TriValue<V1, V2> value);
- public TriMap.TriValue<V1, V2> getValue(K key);
- public boolean isEmpty();
- public int size();
- public static abstract class TriEntry<K, V1, V2> {
- abstract public K getKey();
- abstract public TriValue<V1, V2> getValue();
- @Override
- public boolean equals(Object obj) {
- if (obj == null)
- return false;
- if (this == obj)
- return true;
- if (!(obj instanceof TriEntry<?, ?, ?>))
- return false;
- TriEntry<?, ?, ?> that = (TriEntry<?, ?, ?>) obj;
- if (this.getKey() == that.getKey() && this.getValue() == that.getValue())
- return true;
- if (this.getKey() != that.getKey())
- if (this.getKey() != null && !this.getKey().equals(that.getKey()))
- return false;
- else if (!this.getKey().equals(that.getKey()))
- return false;
- if (this.getValue() != that.getValue())
- if (this.getValue() != null && !this.getValue().equals(that.getValue()))
- return false;
- else if (!this.getValue().equals(that.getValue()))
- return false;
- return true;
- }
- @Override
- public int hashCode() {
- int result = 31;
- result = 37 * result + (getValue()!=null?getValue().hashCode():0);
- result = 37 * result + (getKey()!=null?getKey().hashCode():0);
- return result;
- }
- }
- public static class TriValue<V1, V2> {
- public TriValue(V1 value1, V2 value2) {
- this.value1 = value1;
- this.value2 = value2;
- }
- final public V1 value1;
- final public V2 value2;
- @Override
- public boolean equals(Object obj){
- if (obj == null)
- return false;
- if (this == obj)
- return true;
- if (!(obj instanceof TriValue<?, ?>))
- return false;
- TriValue<?, ?> that = (TriValue<?, ?>) obj;
- if (this.value1 == that.value1 && this.value2 == that.value2)
- return true;
- if (this.value1 != that.value1)
- if (this.value1 != null && !this.value1.equals(that.value1))
- return false;
- else if (!this.value1.equals(that.value1))
- return false;
- if (this.value2 != that.value2)
- if (this.value2 != null && !this.value2.equals(that.value2))
- return false;
- else if (!this.value2.equals(that.value2))
- return false;
- return true;
- }
- @Override
- public int hashCode() {
- int result = 31;
- result = 37 * result + (value1!=null?value1.hashCode():0);
- result = 37 * result + (value2!=null?value2.hashCode():0);
- return result;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement