<commit_before>package de.retest.recheck.ui.diff;

import java.awt.image.BufferedImage;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import de.retest.recheck.image.ImageDifferenceCalculator;
import de.retest.recheck.ui.descriptors.RootElement;
import de.retest.recheck.ui.descriptors.ScreenshotAttributeDifference;
import de.retest.recheck.ui.image.ImageUtils;
import de.retest.recheck.ui.image.Screenshot;

public class RootElementDifference implements Difference {

	private static final Logger logger = LoggerFactory.getLogger( RootElementDifference.class );

	private static final long serialVersionUID = 1L;

	private final String differenceId;

	private final String title;

	private final int checkedUiComponentCount;

	protected final ElementDifference elementDifference;

	private final Screenshot expectedScreenshot;

	private final Screenshot actualScreenshot;

	private RootElement expectedDescriptor;

	private RootElement actualDescriptor;

	@SuppressWarnings( "unused" )
	private RootElementDifference() {
		// for JAXB
		super();
		differenceId = null;
		title = null;
		elementDifference = null;
		expectedScreenshot = null;
		actualScreenshot = null;
		checkedUiComponentCount = 0;
	}

	public RootElementDifference( final ElementDifference elementDifference, final RootElement expectedDescriptor,
			final RootElement actualDescriptor ) {
		final RootElement instance = expectedDescriptor != null ? expectedDescriptor : actualDescriptor;
		this.expectedDescriptor = expectedDescriptor;
		this.actualDescriptor = actualDescriptor;
		title = instance.getTitle();
		differenceId = elementDifference.getIdentifier();
		this.elementDifference = elementDifference;
		expectedScreenshot = elementDifference.getExpectedScreenshot();
		actualScreenshot = elementDifference.getActualScreenshot();
		checkedUiComponentCount = instance.countAllContainedElements();
	}

	@Override
	public String toString() {
		String result = title;
		if ( elementDifference.identifyingAttributesDifference != null ) {
			return result + IdentifyingAttributesDifference.class.getSimpleName() + " "
					+ elementDifference.identifyingAttributesDifference;
		}
		if ( elementDifference.attributesDifference != null ) {
			result += AttributesDifference.class.getSimpleName() + " " + elementDifference.attributesDifference;
		}
		if ( !elementDifference.childDifferences.isEmpty() ) {
			result += elementDifference.childDifferences.toString();
		}
		return result;
	}

	public RootElement getExpectedDescriptor() {
		return expectedDescriptor;
	}

	public RootElement getActualDescriptor() {
		return actualDescriptor;
	}

	@Override
	public int size() {
		return elementDifference.size();
	}

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

	public ElementDifference getElementDifference() {
		return elementDifference;
	}

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

	public List<ElementDifference> getElementDifferencesGrouped() {
		//TODO Implement accordingly
		// three or more differences with the same parent element
		// that is not the rootlayer
		// should be grouped as such
		return elementDifference.getElementDifferences();
	}

	public String getIdentifier() {
		return differenceId;
	}

	public Screenshot getExpectedScreenshot() {
		final ScreenshotAttributeDifference screenshotDiff = getScreenshotDifference();
		if ( screenshotDiff != null ) {
			try {
				// Try to instantiate difference image.
				final Class<?> clazz = Class.forName( screenshotDiff.getStrategyName() );
				final ImageDifferenceCalculator imgDiffCalc = (ImageDifferenceCalculator) clazz.newInstance();
				final BufferedImage differenceImage =
						imgDiffCalc.compare( expectedScreenshot, actualScreenshot ).getDifferenceImage();
				return ImageUtils.image2Screenshot( expectedScreenshot.getPersistenceId(), differenceImage );
			} catch ( final Exception e ) {
				logger.error( "Exception creating difference image.", e );
			}
		}
		return expectedScreenshot;
	}

	ScreenshotAttributeDifference getScreenshotDifference() {
		final AttributesDifference attributesDifference = elementDifference.getAttributesDifference();
		if ( attributesDifference != null ) {
			final List<AttributeDifference> diffs = attributesDifference.getDifferences();
			for ( final AttributeDifference attrDiff : diffs ) {
				if ( attrDiff instanceof ScreenshotAttributeDifference ) {
					return (ScreenshotAttributeDifference) attrDiff;
				}
			}
		}
		return null;
	}

	public Screenshot getActualScreenshot() {
		return actualScreenshot;
	}

	public int getCheckedUiComponentCount() {
		return checkedUiComponentCount;
	}

	public String getTitle() {
		return title;
	}
}
<commit_msg>This method is a needed refactoring downstream<commit_after>package de.retest.recheck.ui.diff;

import java.awt.image.BufferedImage;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import de.retest.recheck.image.ImageDifferenceCalculator;
import de.retest.recheck.ui.descriptors.RootElement;
import de.retest.recheck.ui.descriptors.ScreenshotAttributeDifference;
import de.retest.recheck.ui.image.ImageUtils;
import de.retest.recheck.ui.image.Screenshot;

public class RootElementDifference implements Difference {

	private static final Logger logger = LoggerFactory.getLogger( RootElementDifference.class );

	private static final long serialVersionUID = 1L;

	private final String differenceId;

	private final String title;

	private final int checkedUiComponentCount;

	protected final ElementDifference elementDifference;

	private final Screenshot expectedScreenshot;

	private final Screenshot actualScreenshot;

	private RootElement expectedDescriptor;

	private RootElement actualDescriptor;

	@SuppressWarnings( "unused" )
	private RootElementDifference() {
		// for JAXB
		super();
		differenceId = null;
		title = null;
		elementDifference = null;
		expectedScreenshot = null;
		actualScreenshot = null;
		checkedUiComponentCount = 0;
	}

	public RootElementDifference( final ElementDifference elementDifference, final RootElement expectedDescriptor,
			final RootElement actualDescriptor ) {
		final RootElement instance = expectedDescriptor != null ? expectedDescriptor : actualDescriptor;
		this.expectedDescriptor = expectedDescriptor;
		this.actualDescriptor = actualDescriptor;
		title = instance.getTitle();
		differenceId = elementDifference.getIdentifier();
		this.elementDifference = elementDifference;
		expectedScreenshot = elementDifference.getExpectedScreenshot();
		actualScreenshot = elementDifference.getActualScreenshot();
		checkedUiComponentCount = instance.countAllContainedElements();
	}

	@Override
	public String toString() {
		String result = title;
		if ( elementDifference.identifyingAttributesDifference != null ) {
			return result + IdentifyingAttributesDifference.class.getSimpleName() + " "
					+ elementDifference.identifyingAttributesDifference;
		}
		if ( elementDifference.attributesDifference != null ) {
			result += AttributesDifference.class.getSimpleName() + " " + elementDifference.attributesDifference;
		}
		if ( !elementDifference.childDifferences.isEmpty() ) {
			result += elementDifference.childDifferences.toString();
		}
		return result;
	}

	public RootElement getExpectedDescriptor() {
		return expectedDescriptor;
	}

	public RootElement getActualDescriptor() {
		return actualDescriptor;
	}

	@Override
	public int size() {
		return elementDifference.size();
	}

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

	public ElementDifference getElementDifference() {
		return elementDifference;
	}

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

	public List<ElementDifference> getElementDifferencesGrouped() {
		//TODO Implement accordingly
		// three or more differences with the same parent element
		// that is not the rootlayer
		// should be grouped as such
		return elementDifference.getElementDifferences();
	}

	public String getIdentifier() {
		return differenceId;
	}

	public Screenshot getExpectedScreenshot() {
		final ScreenshotAttributeDifference screenshotDiff = getScreenshotDifference();
		if ( screenshotDiff != null ) {
			try {
				// Try to instantiate difference image.
				final Class<?> clazz = Class.forName( screenshotDiff.getStrategyName() );
				final ImageDifferenceCalculator imgDiffCalc = (ImageDifferenceCalculator) clazz.newInstance();
				final BufferedImage differenceImage =
						imgDiffCalc.compare( expectedScreenshot, actualScreenshot ).getDifferenceImage();
				return ImageUtils.image2Screenshot( expectedScreenshot.getPersistenceId(), differenceImage );
			} catch ( final Exception e ) {
				logger.error( "Exception creating difference image.", e );
			}
		}
		return expectedScreenshot;
	}

	ScreenshotAttributeDifference getScreenshotDifference() {
		final AttributesDifference attributesDifference = elementDifference.getAttributesDifference();
		if ( attributesDifference != null ) {
			final List<AttributeDifference> diffs = attributesDifference.getDifferences();
			for ( final AttributeDifference attrDiff : diffs ) {
				if ( attrDiff instanceof ScreenshotAttributeDifference ) {
					return (ScreenshotAttributeDifference) attrDiff;
				}
			}
		}
		return null;
	}

	public Screenshot getActualScreenshot() {
		return actualScreenshot;
	}

	public int getCheckedUiComponentCount() {
		return checkedUiComponentCount;
	}

	public String getTitle() {
		return title;
	}

	public RootElement getElement() {
		return getExpectedDescriptor() != null ? getExpectedDescriptor() : getActualDescriptor();
	}
}

{'fraction_non_alphanumeric': 0.08000405597241939, 'fraction_numerical': 0.001013993104846887, 'mean_word_length': 5.359123146357189, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7250014', 'n_tokens_mistral': 3010, 'n_tokens_neox': 2674, 'n_words': 620}