package de.retest.recheck.printer.leaf;

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

import de.retest.recheck.printer.PrinterValueProvider;
import de.retest.recheck.printer.Printer;
import de.retest.ui.diff.DurationDifference;
import de.retest.ui.diff.IdentifyingAttributesDifference;
import de.retest.ui.diff.InsertedDeletedElementDifference;
import de.retest.ui.diff.LeafDifference;

public class MultiLeafDifferencePrinter implements Printer<LeafDifference> {

	private final Map<Class<? extends LeafDifference>, Printer<? extends LeafDifference>> printers;

	public MultiLeafDifferencePrinter( final PrinterValueProvider defaultValueFinder ) {
		printers = createPrinterMap( defaultValueFinder );
	}

	private Map<Class<? extends LeafDifference>, Printer<? extends LeafDifference>>
			createPrinterMap( final PrinterValueProvider finder ) {
		final Map<Class<? extends LeafDifference>, Printer<? extends LeafDifference>> map = new HashMap<>();

		map.put( DurationDifference.class, new DurationDifferencePrinter() );
		map.put( IdentifyingAttributesDifference.class, new IdentifyingAttributesDifferencePrinter( finder ) );
		map.put( InsertedDeletedElementDifference.class, new InsertedDeletedElementDifferencePrinter() );

		return map;
	}

	@Override
	public String toString( final LeafDifference difference, final String indent ) {
		final Printer<LeafDifference> printer = findPrinter( difference );
		return printer.toString( difference, indent );
	}

	@SuppressWarnings( "unchecked" )
	private Printer<LeafDifference> findPrinter( final LeafDifference difference ) {
		return printers.entrySet().stream() //
				.filter( entry -> entry.getKey().isInstance( difference ) ) //
				.map( entry -> (Printer<LeafDifference>) entry.getValue() ) // cast here due to generic incompatibility
				.findAny() //
				.orElse( DefaultPrinter.INSTANCE );
	}

	private enum DefaultPrinter implements Printer<LeafDifference> {
		INSTANCE;

		@Override
		public String toString( final LeafDifference difference, final String indent ) {
			return indent + String.format( "expected=%s, actual=%s", difference.getExpected(), difference.getActual() );
		}
	}
}

@@ -123,29 +123,16 @@
 .Printer
-ValueProvider
 ;%0Aimport
@@ -157,32 +157,45 @@
 .printer.Printer
+ValueProvider
 ;%0Aimport de.rete
@@ -1588,245 +1588,79 @@
 urn 
-printers.entrySet().stream() //%0A%09%09%09%09.filter( entry -%3E entry.getKey().isInstance( difference ) ) //%0A%09%09%09%09.map( entry -%3E (Printer%3CLeafDifference%3E) entry.getValue() ) // cast here due to generic incompatibility%0A%09%09%09%09.findAny() //%0A%09%09%09%09.orElse(
+(Printer%3CLeafDifference%3E) printers.getOrDefault( difference.getClass(),
  Def

Simplify implementation