package xyz.openmodloader.dictionary;

import java.util.Map;
import java.util.function.Predicate;

import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import xyz.openmodloader.util.CollectionPredicate;

public class Dictionary<K, V> {

    private final Map<K, CollectionPredicate<V>> map = Maps.newConcurrentMap();
    private final Predicate<V> defaultValue = (v) -> false;

    /**
     * Registers a value.
     *
     * @param key the key
     * @param value the value
     */
    public void register(K key, Predicate<V> value) {
        CollectionPredicate<V> collection = map.get(key);
        if (collection != null) {
            collection = new CollectionPredicate<>(Sets.newConcurrentHashSet());
            map.put(key, collection);
        }
        collection.add(value);
    }

    /**
     * Gets the registered elements for the specified key.
     * This set is automatically updated when new elements
     * are registered. Cache this.
     *
     * @param key the key
     * @return the sets the
     */
    public Predicate<V> get(K key) {
        Predicate<V> value = map.get(key);
        if (value != null) {
            return value;
        } else {
            return defaultValue;
        }
    }
}
@@ -170,16 +170,17 @@
 t.Sets;%0A
+%0A
 import x
@@ -339,68 +339,8 @@
 p();
-%0A    private final Predicate%3CV%3E defaultValue = (v) -%3E false;
 %0A%0A  
@@ -504,16 +504,18 @@
         
+((
 Collecti
@@ -532,217 +532,19 @@
 e%3CV%3E
- collection = map.get(key);%0A        if (collection != null) %7B%0A            collection = new CollectionPredicate%3C%3E(Sets.newConcurrentHashSet());%0A            map.put(key, collection);%0A        %7D%0A        collection
+) get(key))
 .add
@@ -594,24 +594,25 @@
 istered 
-elements
+predicate
  for the
@@ -640,14 +640,19 @@
 * Th
-is set
+e predicate
  is 
@@ -682,19 +682,28 @@
 hen 
+a 
 new
+%0A     *
  element
 s%0A  
@@ -702,20 +702,11 @@
 ment
-s%0A     * are
+ is
  reg
@@ -840,16 +840,26 @@
         
+Collection
 Predicat
@@ -973,23 +973,125 @@
     
-return defaultV
+value = new CollectionPredicate%3C%3E(Sets.newConcurrentHashSet());%0A            map.put(key, value);%0A            return v
 alue

Fix dictionary bug