Class VersionedMap<K,V>

java.lang.Object
com.helixframework.collections.VersionedMap<K,V>
Type Parameters:
K - key type
V - value type
All Implemented Interfaces:
Map<K,V>

public class VersionedMap<K,V> extends Object implements Map<K,V>
Map implementation that allows for the versioning of key value pairs.
  • Field Details

    • FIRST_VERSION

      public static final Long FIRST_VERSION
      First version of the map.
  • Constructor Details

    • VersionedMap

      public VersionedMap()
      Creates a new instance of VersionedMap.
    • VersionedMap

      public VersionedMap(int maxVersions)
      Creates a new instance of VersionedMap with a cap on the maximum number of value versions stored per key. If versions of key exceed the specified amount the versions are removed in FIFO order.
      Parameters:
      maxVersions - maximum number of value versions to keep per key
    • VersionedMap

      public VersionedMap(Map<K,V> m)
      Creates a new instance of VersionedMap and initializes it with the contents of the supplied map.
      Parameters:
      m - the map whose mappings are to be placed in this map
    • VersionedMap

      public VersionedMap(Map<K,V> m, int maxVersions)
      Creates a new instance of VersionedMap with a cap on the maximum number of value versions stored per key and initializes it with the contents of the supplied map. If versions of key exceed the specified amount the versions are removed in FIFO order.
      Parameters:
      m - the map whose mappings are to be placed in this map
      maxVersions - maximum number of value versions to keep per key
  • Method Details

    • size

      public int size()
      Specified by:
      size in interface Map<K,V>
    • isEmpty

      public boolean isEmpty()
      Specified by:
      isEmpty in interface Map<K,V>
    • containsKey

      public boolean containsKey(Object key)
      Specified by:
      containsKey in interface Map<K,V>
    • containsValue

      public boolean containsValue(Object value)
      Specified by:
      containsValue in interface Map<K,V>
    • get

      public V get(Object key)
      Specified by:
      get in interface Map<K,V>
    • get

      public V get(Object key, Long ver)
      Returns the value of the version of the key with the greatest version less than or equal to the given version, or null if the key does not exist.
      Parameters:
      key - key
      ver - version
      Returns:
      value or null if the key does not exist
    • getAll

      public Set<Map.Entry<Long,V>> getAll(Object key)
      Returns all value versions of the key.
      Parameters:
      key - key
      Returns:
      all value versions or null if the key does not exist
    • put

      public V put(K key, V value)
      Specified by:
      put in interface Map<K,V>
    • remove

      public V remove(Object key)
      Specified by:
      remove in interface Map<K,V>
    • putAll

      public void putAll(Map<? extends K,? extends V> m)
      Specified by:
      putAll in interface Map<K,V>
    • clear

      public void clear()
      Specified by:
      clear in interface Map<K,V>
    • keySet

      public Set<K> keySet()
      Specified by:
      keySet in interface Map<K,V>
    • keySet

      public Set<K> keySet(long ver)
      Returns a Set of keys in this map at the specified version.
      Parameters:
      ver - version
      Returns:
      Set of keys in this map
    • values

      public Collection<V> values()
      Specified by:
      values in interface Map<K,V>
    • values

      public Collection<V> values(long ver)
      Returns a Collection of values in this map at the specified version.
      Parameters:
      ver - version
      Returns:
      Collection of values in this map
    • entrySet

      public Set<Map.Entry<K,V>> entrySet()
      Specified by:
      entrySet in interface Map<K,V>
    • entrySet

      public Set<Map.Entry<K,V>> entrySet(long ver)
      Returns a Set view of the mappings in this map at the specified version.
      Parameters:
      ver - version
      Returns:
      Set of mappings in this map
    • version

      public long version()
      Gets the current version of the map.

      Initial version of the map is `-1L`.

      Returns:
      current map version