package de.retest.recheck.ui.diff.meta;

import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.Set;
import java.util.Spliterator;
import java.util.TreeSet;
import java.util.function.Consumer;

import lombok.AccessLevel;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.ToString;

@ToString
@EqualsAndHashCode
@RequiredArgsConstructor( access = AccessLevel.PRIVATE )
public final class MetadataDifference implements Iterable<MetadataElementDifference> {

	@Getter
	private final Set<MetadataElementDifference> differences;

	public static MetadataDifference empty() {
		return new MetadataDifference( Collections.emptySet() );
	}

	public static MetadataDifference of( final Set<MetadataElementDifference> differences ) {
		final Set<MetadataElementDifference> unique =
				new TreeSet<>( Comparator.comparing( MetadataElementDifference::getKey ) );
		unique.addAll( differences );
		return new MetadataDifference( unique );
	}

	public boolean isEmpty() {
		return differences.isEmpty();
	}

	public int size() {
		return differences.size();
	}

	@Override
	public Iterator<MetadataElementDifference> iterator() {
		return differences.iterator();
	}

	@Override
	public Spliterator<MetadataElementDifference> spliterator() {
		return differences.spliterator();
	}

	@Override
	public void forEach( final Consumer<? super MetadataElementDifference> action ) {
		differences.forEach( action );
	}
}

@@ -624,16 +624,99 @@
 ences;%0A%0A
+%09// For JAXB%0A%09private MetadataDifference() %7B%0A%09%09this( Collections.emptySet() );%0A%09%7D%0A%0A
 %09public 

Add default constructor for JAXB