Class Pair<K,V>

java.lang.Object
net.dermetfan.utils.Pair<K,V>
Type Parameters:
K - the type of the key
V - the type of the value

public class Pair<K,V> extends Object
  • Constructor Details

    • Pair

      public Pair()
      creates an empty pair (key and value are null)
    • Pair

      public Pair(K key, V value)
      Parameters:
      key - the key
      value - the value
    • Pair

      public Pair(Pair<K,V> pair)
      Parameters:
      pair - the Pair to copy
  • Method Details

    • set

      public Pair<K,V> set(Pair<K,V> pair)
      Parameters:
      pair - the Pair which key and value to use
      Returns:
      this Pair for chaining
    • set

      public Pair<K,V> set(K key, V value)
      Parameters:
      key - the key to set
      value - the value to set
      Returns:
      this Pair for chaining
    • clear

      public void clear()
      sets key and value to null
    • clearKey

      public void clearKey()
      sets key null
    • clearValue

      public void clearValue()
      sets value null
    • isEmpty

      public boolean isEmpty()
      Returns:
      if key or value is not null
    • isFull

      public boolean isFull()
      Returns:
      if key and value are both not null
    • hasKey

      public boolean hasKey()
      Returns:
      if key is not null
    • hasValue

      public boolean hasValue()
      Returns:
      if value is not null
    • swap

      public void swap() throws IllegalStateException
      swaps key and value
      Throws:
      IllegalStateException - if the classes of key and value are not assignable from each other
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      if the given object is a Pair instance, equals comparison will be used on key and value
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
      Returns:
      [key & value]
    • getKey

      public K getKey()
      Returns:
      the key
    • setKey

      public void setKey(K key)
      Parameters:
      key - the key to set
    • getValue

      public V getValue()
      Returns:
      the value
    • setValue

      public void setValue(V value)
      Parameters:
      value - the value to set