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 java.lang.Object
  • Constructor Summary

    Constructors
    Constructor Description
    Pair()
    creates an empty pair (key and value are null)
    Pair​(K key, V value)  
    Pair​(Pair<K,​V> pair)  
  • Method Summary

    Modifier and Type Method Description
    void clear()
    sets key and value to null
    void clearKey()
    sets key null
    void clearValue()
    sets value null
    boolean equals​(java.lang.Object obj)
    if the given object is a Pair instance, equals comparison will be used on key and value
    K getKey()  
    V getValue()  
    int hashCode()  
    boolean hasKey()  
    boolean hasValue()  
    boolean isEmpty()  
    boolean isFull()  
    Pair<K,​V> set​(K key, V value)  
    Pair<K,​V> set​(Pair<K,​V> pair)  
    void setKey​(K key)  
    void setValue​(V value)  
    void swap()
    swaps key and value
    java.lang.String toString()  

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • 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 java.lang.IllegalStateException
      swaps key and value
      Throws:
      java.lang.IllegalStateException - if the classes of key and value are not assignable from each other
    • hashCode

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

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

      public java.lang.String toString()
      Overrides:
      toString in class java.lang.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