package de.retest.recheck.printer;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import java.util.stream.Collectors;

import de.retest.recheck.meta.global.GitMetadataProvider;
import de.retest.recheck.meta.global.MachineMetadataProvider;
import de.retest.recheck.meta.global.OSMetadataProvider;
import de.retest.recheck.meta.global.TimeMetadataProvider;
import de.retest.recheck.ui.diff.meta.MetadataDifference;
import de.retest.recheck.ui.diff.meta.MetadataElementDifference;

public class MetadataDifferencePrinter implements Printer<MetadataDifference> {

	private static final String KEY_EXPECTED_ACTUAL_FORMAT = "%s: expected=\"%s\", actual=\"%s\"";

	// Only print a selected amount of differences that potentially can break a test
	private static final Set<String> differencesToIgnore = new HashSet<>( Arrays.asList( //
			GitMetadataProvider.VCS_NAME, //
			GitMetadataProvider.BRANCH_NAME, //
			GitMetadataProvider.COMMIT_NAME, //
			MachineMetadataProvider.MACHINE_NAME, //
			OSMetadataProvider.OS_ARCH, //
			TimeMetadataProvider.DATE, //
			TimeMetadataProvider.TIME, //
			TimeMetadataProvider.ZONE, //
			TimeMetadataProvider.OFFSET //
	) );

	@Override
	public String toString( final MetadataDifference difference, final String indent ) {
		final String prefix = "Metadata Differences:";
		return indent + prefix + printDifferences( difference, indent + "\t" );
	}

	private String printDifferences( final MetadataDifference difference, final String indent ) {
		return difference.getDifferences().stream() //
				.filter( this::shouldPrint ) //
				.map( this::print ) //
				.collect( Collectors.joining( "\n" + indent, "\n" + indent, "" ) );
	}

	private boolean shouldPrint( final MetadataElementDifference difference ) {
		return !differencesToIgnore.contains( difference.getKey() );
	}

	private String print( final MetadataElementDifference difference ) {
		return String.format( KEY_EXPECTED_ACTUAL_FORMAT, difference.getKey(), difference.getExpected(),
				difference.getActual() );
	}
}

@@ -50,1139 +50,327 @@
 til.
-Arrays;%0Aimport java.util.HashSet;%0Aimport java.util.Set;%0Aimport java.util.stream.Collectors;%0A%0Aimport de.retest.recheck.meta.global.GitMetadataProvider;%0Aimport de.retest.recheck.meta.global.MachineMetadataProvider;%0Aimport de.retest.recheck.meta.global.OSMetadataProvider;%0Aimport de.retest.recheck.meta.global.TimeMetadataProvider;%0Aimport de.retest.recheck.ui.diff.meta.MetadataDifference;%0Aimport de.retest.recheck.ui.diff.meta.MetadataElementDifference;%0A%0Apublic class MetadataDifferencePrinter implements Printer%3CMetadataDifference%3E %7B%0A%0A%09private static final String KEY_EXPECTED_ACTUAL_FORMAT = %22%25s: expected=%5C%22%25s%5C%22, actual=%5C%22%25s%5C%22%22;%0A%0A%09// Only print a selected amount of differences that potentially can break a test%0A%09private static final Set%3CString%3E differencesToIgnore = new HashSet%3C%3E( Arrays.asList( //%0A%09%09%09GitMetadataProvider.VCS_NAME, //%0A%09%09%09GitMetadataProvider.BRANCH_NAME, //%0A%09%09%09GitMetadataProvider.COMMIT_NAME, //%0A%09%09%09MachineMetadataProvider.MACHINE_NAME, //%0A%09%09%09OSMetadataProvider.OS_ARCH, //%0A%09%09%09TimeMetadataProvider.DATE, //%0A%09%09%09TimeMetadataProvider.TIME, //%0A%09%09%09TimeMetadataProvider.ZONE, //%0A%09%09%09TimeMetadataProvider.OFFSET //%0A%09) )
+stream.Collectors;%0A%0Aimport de.retest.recheck.ui.diff.meta.MetadataDifference;%0Aimport de.retest.recheck.ui.diff.meta.MetadataElementDifference;%0A%0Apublic class MetadataDifferencePrinter implements Printer%3CMetadataDifference%3E %7B%0A%0A%09private static final String KEY_EXPECTED_ACTUAL_FORMAT = %22%25s: expected=%5C%22%25s%5C%22, actual=%5C%22%25s%5C%22%22
 ;%0A%0A%09
@@ -740,44 +740,8 @@
  //%0A
-%09%09%09%09.filter( this::shouldPrint ) //%0A
 %09%09%09%09
@@ -843,152 +843,8 @@
 %09%7D%0A%0A
-%09private boolean shouldPrint( final MetadataElementDifference difference ) %7B%0A%09%09return !differencesToIgnore.contains( difference.getKey() );%0A%09%7D%0A%0A
 %09pri

Remove now obsolete checks