public synchronized void registerIfAbsent(ParameterizedTypeHandlerMap<T> other) { if (!modifiable) { throw new IllegalStateException("Attempted to modify an unmodifiable map."); } for (Map.Entry<Type, T> entry : other.userMap.entrySet()) { if (!userMap.containsKey(entry.getKey())) { register(entry.getKey(), entry.getValue(), false); } } for (Map.Entry<Type, T> entry : other.systemMap.entrySet()) { if (!systemMap.containsKey(entry.getKey())) { register(entry.getKey(), entry.getValue(), true); } } // Quite important to traverse the typeHierarchyList from stack bottom first since // we want to register the handlers in the same order to preserve priority order for (int i = other.userTypeHierarchyList.size() - 1; i >= 0; --i) { Pair<Class<?>, T> entry = other.userTypeHierarchyList.get(i); int index = getIndexOfSpecificHandlerForTypeHierarchy(entry.first, userTypeHierarchyList); if (index < 0) { registerForTypeHierarchy(entry, false); } } for (int i = other.systemTypeHierarchyList.size() - 1; i >= 0; --i) { Pair<Class<?>, T> entry = other.systemTypeHierarchyList.get(i); int index = getIndexOfSpecificHandlerForTypeHierarchy(entry.first, systemTypeHierarchyList); if (index < 0) { registerForTypeHierarchy(entry, true); } } }
public synchronized void registerForTypeHierarchy(Class<?> typeOfT, T value, boolean isSystem) { Pair<Class<?>, T> pair = new Pair<Class<?>, T>(typeOfT, value); registerForTypeHierarchy(pair, isSystem); }