package com.speedment.codegen.base;

import java.util.AbstractMap.SimpleImmutableEntry;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Stream;

/**
 *
 * @author Emil Forslund
 */
public class DefaultInstaller implements Installer {
	private final Map<Class<?>, Class<? extends CodeView>> modelToView;
	
	public DefaultInstaller() {
		modelToView = new HashMap<>();
	}

	@Override
	public <M, V extends CodeView<M>> void install(Class<M> model, Class<V> view) {
		modelToView.put(model, view);
	}

	@Override
	public Optional<CodeView> withOne(Class<?> model) {
		for (final Map.Entry<Class<?>, Class<? extends CodeView>> e : modelToView.entrySet()) {
			if (e.getKey().isAssignableFrom(model)) {
				return Optional.of(Installer.create(e.getValue()));
			}
		}
		return Optional.empty();
	}
	
	@Override
	public Stream<CodeView> withAll(Class<?> model) {
		final Stream.Builder<CodeView> stream = Stream.builder();
		modelToView.entrySet().stream()
			.filter(e -> e.getKey().isAssignableFrom(model))
			.forEach((e) -> {
				stream.add(Installer.create(e.getValue()));
			}
		);
		return stream.build();
	}
}
@@ -102,19 +102,19 @@
 til.Hash
-Map
+Set
 ;%0Aimport
@@ -156,16 +156,38 @@
 tional;%0A
+import java.util.Set;%0A
 import j
@@ -315,19 +315,29 @@
 e final 
-Map
+Set%3CMap.Entry
 %3CClass%3C?
@@ -365,16 +365,17 @@
 deView%3E%3E
+%3E
  modelTo
@@ -435,19 +435,19 @@
 new Hash
-Map
+Set
 %3C%3E();%0A%09%7D
@@ -558,11 +558,38 @@
 iew.
-put
+add(new SimpleImmutableEntry%3C%3E
 (mod
@@ -597,16 +597,17 @@
 l, view)
+)
 ;%0A%09%7D%0A%0A%09@
@@ -743,27 +743,16 @@
 elToView
-.entrySet()
 ) %7B%0A%09%09%09i
@@ -1029,19 +1029,8 @@
 iew.
-entrySet().
 stre

Revert "Changd implementation of DefaultInstaller"