Class KVPair

java.lang.Object
io.permazen.kv.KVPair
All Implemented Interfaces:
Cloneable

public class KVPair extends Object implements Cloneable
A key/value pair.

Note: the internal byte arrays are not copied; therefore, values passed to the constructor or returned from the accessor methods must not be modified if instances are to remain immutable. To ensure safety, use clone().

  • Constructor Details

    • KVPair

      public KVPair(byte[] key, byte[] value)
      Constructor. The given arrays are copied.
      Parameters:
      key - key
      value - value
      Throws:
      IllegalArgumentException - if key or value is null
    • KVPair

      public KVPair(Map.Entry<byte[],byte[]> entry)
      Constructor. The given key and value arrays are copied.
      Parameters:
      entry - map entry
      Throws:
      IllegalArgumentException - if entry or its key or value is null
  • Method Details

    • getKey

      public byte[] getKey()
      Get the key.
      Returns:
      the key
    • getValue

      public byte[] getValue()
      Get the value.
      Returns:
      the value
    • clone

      public KVPair clone()
      Deep-clone this instance. Copys this instance as well as the key and value byte[] arrays.
      Overrides:
      clone in class Object
      Returns:
      cloned instance
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object obj)
      Compare for equality.

      Two KVPair instances are equal if the keys and values both match according to Arrays.equals(byte[], byte[]).

      Overrides:
      equals in class Object
      Returns:
      true if objects are equal
    • hashCode

      public int hashCode()
      Calculate hash code.

      The hash code of a KVPair is the exclusive-OR of the hash codes of the key and the value, each according to Arrays.hashCode(byte[]).

      Overrides:
      hashCode in class Object
      Returns:
      hash value for this instance