Class IndirectEquiMap<K,V>

java.lang.Object
org.aksw.commons.collections.cluster.IndirectEquiMap<K,V>
Type Parameters:
K -
V -

public class IndirectEquiMap<K,V> extends Object
A map-like key-value data structure where keys can be stated as equivalent, and thus become aliases of each other. Keys can be stated as equivalent using stateEqual (raises exception on conflict) or tryStateEqual (returns the conflict). Clusters can be obtained using getEquivalences() and their associated values can be set using setValue(id, value). Note, that there is no distinction between null and undef values. In fact, a null value is interpreted as the absence of a value, and such a cluster token will be removed from the tokenToValue map.
Author:
raven
  • Field Details

    • keyToToken

      protected Map<K,Integer> keyToToken
    • tokenToKeys

      protected com.google.common.collect.Multimap<Integer,K> tokenToKeys
    • tokenToValue

      protected Map<Integer,V> tokenToValue
    • tokenToKeysView

      protected com.google.common.collect.Multimap<Integer,K> tokenToKeysView
    • gen

      protected GeneratorLending<Integer> gen
  • Constructor Details

    • IndirectEquiMap

      public IndirectEquiMap()
  • Method Details

    • dump

      public Map<Set<K>,V> dump()
      Export the state as a map of the sets of equivalent keys and their associated values. Mostly intended for unit testing.
      Returns:
    • keySet

      public Set<K> keySet()
    • getEquivalences

      public com.google.common.collect.Multimap<Integer,K> getEquivalences()
    • getValue

      public V getValue(Integer token)
    • setValue

      public V setValue(Integer token, V value)
      Method to set a cluster's value. Checks whether the validity of the token, i.e. whether a cluster with that id exists.
      Parameters:
      token -
      value -
      Returns:
    • getEquivalences

      public Collection<K> getEquivalences(K key)
    • putKeyToken

      protected void putKeyToken(K key, int token)
    • tryStateEqual

      public Map.Entry<V,V> tryStateEqual(K a, K b)
      Try to make keys equal. The response determines whether there ary any conflicts.
      Parameters:
      a -
      b -
      Returns:
      null on success, otherwise an entry of the key's conflicting values.
    • stateEqual

      public void stateEqual(K a, K b)
      State keys to be equal - raises an exception on conflicting values.
      Parameters:
      a -
      b -
    • stateEqual

      public void stateEqual(K a, K b, V value)
      State keys to be equal and sets their values. Any conflicts are resolved by setting the cluster values to the provided value.
      Parameters:
      a -
      b -
      value -
    • stateEqual

      public void stateEqual(Collection<K> keys, V value)
      State keys to be equal and sets their values. Any conflicts are resolved by setting the cluster values to the provided value.
      Parameters:
      keys -
      value -
    • tryStateEqual

      protected Map.Entry<V,V> tryStateEqual(K a, K b, V value, boolean overwrite)
      States an equality between keys. if overwrite is true, conflicts can not occur as they are overwritten with value. Return value is always null. if overwrite is false, in case of conflict the pair of conflicting values is returned Conflicts can be resolved using stateEqual(a, b, value)
      Parameters:
      a -
      b -
    • putWithoutNull

      public static <K,V> void putWithoutNull(Map<K,V> map, K key, V value)
    • add

      public void add(K key)
      Adds a key. If it already exists, its associated value is left untouched. Note, that this behavior is different from put(key, null) - which overwrites the value with the absence of a value for that key.
      Parameters:
      key -
    • put

      public void put(K key, V value)
      Puts a new value, overwrites any prior value associated with the key's cluster.
      Parameters:
      key -
      value -
    • addKey

      protected Integer addKey(K key)
    • get

      public V get(K key)
    • isEqual

      public boolean isEqual(K a, K b)
    • toString

      public String toString()
      Overrides:
      toString in class Object