package protocolsupport.utils;

import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;

public class CachedInstanceOfChain<T> {

	private final Map<Class<?>, T> knownPaths = new LinkedHashMap<>();
	private final Map<Class<?>, T> cachedPaths = new HashMap<>();

	public void setKnownPath(Class<?> clazz, T path) {
		knownPaths.put(clazz, path);
		cachedPaths.put(clazz, path);
	}

	public T selectPath(Class<?> clazz) {
		return cachedPaths.computeIfAbsent(clazz, k ->
			knownPaths.entrySet().stream()
			.filter(entry -> entry.getKey().isAssignableFrom(k))
			.map(Map.Entry::getValue)
			.findFirst().orElse(null)
		);
	}

}

@@ -29,34 +29,8 @@
 s;%0A%0A
-import java.util.HashMap;%0A
 impo
@@ -78,16 +78,63 @@
 til.Map;
+%0Aimport java.util.concurrent.ConcurrentHashMap;
 %0A%0Apublic
@@ -286,16 +286,26 @@
 s = new 
+Concurrent
 HashMap%3C

Make CachedInstanceOfMap concurrent capable.