package de.retest.recheck.ui.diff;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAnyElement;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;

import de.retest.recheck.util.ChecksumCalculator;

@XmlRootElement
@XmlAccessorType( XmlAccessType.FIELD )
public class StateDifference implements Difference {

	private static final long serialVersionUID = 1L;

	@XmlAttribute
	private final String differenceId;

	@XmlAnyElement( lax = true )
	private final List<RootElementDifference> differences;

	@SuppressWarnings( "unused" )
	private StateDifference() {
		// for JAXB
		differenceId = null;
		differences = new ArrayList<>();
	}

	public StateDifference( final List<RootElementDifference> differences ) {
		differenceId = getSumIdentifier( differences );
		this.differences = Collections.unmodifiableList( differences );
	}

	public List<RootElementDifference> getStateDifference() {
		return differences;
	}

	@Override
	public String toString() {
		return differences.toString();
	}

	@Override
	public int size() {
		int size = 0;
		for ( final Difference difference : differences ) {
			size += difference.size();
		}
		return size;
	}

	@Override
	public List<ElementDifference> getNonEmptyDifferences() {
		return ElementDifferenceFinder.getNonEmptyDifferences( differences );
	}

	@Override
	public List<ElementDifference> getElementDifferences() {
		return ElementDifferenceFinder.getElementDifferences( differences );
	}

	public String getIdentifier() {
		return differenceId;
	}

	public List<RootElementDifference> getRootElementDifferences() {
		return differences;
	}

	private static String getSumIdentifier( final List<RootElementDifference> differences ) {
		String result = "";
		for ( final RootElementDifference rootElementDifference : differences ) {
			result += " # " + rootElementDifference.getIdentifier();
		}
		return ChecksumCalculator.getInstance().sha256( result );
	}
}

@@ -350,24 +350,70 @@
 otElement;%0A%0A
+import de.retest.recheck.ui.image.Screenshot;%0A
 import de.re
@@ -1840,16 +1840,552 @@
 es;%0A%09%7D%0A%0A
+%09public List%3CScreenshot%3E getExpectedScreenshots() %7B%0A%09%09final List%3CScreenshot%3E result = new ArrayList%3C%3E();%0A%09%09for ( final RootElementDifference rootElementDifference : differences ) %7B%0A%09%09%09result.add( rootElementDifference.getExpectedScreenshot() );%0A%09%09%7D%0A%09%09return result;%0A%09%7D%0A%0A%09public List%3CScreenshot%3E getActualScreenshots() %7B%0A%09%09final List%3CScreenshot%3E result = new ArrayList%3C%3E();%0A%09%09for ( final RootElementDifference rootElementDifference : differences ) %7B%0A%09%09%09result.add( rootElementDifference.getActualScreenshot() );%0A%09%09%7D%0A%09%09return result;%0A%09%7D%0A%0A
 %09private

Revert past delete of "unused" method