package de.retest.recheck.review.workers;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.stream.Collectors;

import de.retest.recheck.ignore.JSShouldIgnoreImpl;
import de.retest.recheck.ignore.RecheckIgnoreUtil;
import de.retest.recheck.ignore.ShouldIgnore;
import de.retest.recheck.review.GlobalIgnoreApplier;
import de.retest.recheck.review.GlobalIgnoreApplier.PersistableGlobalIgnoreApplier;
import de.retest.recheck.review.counter.Counter;
import de.retest.recheck.review.ignore.io.Loaders;

public class LoadShouldIgnoreWorker {

	private final Counter counter;
	private final Consumer<GlobalIgnoreApplier> applier;

	public LoadShouldIgnoreWorker( final Counter counter, final Consumer<GlobalIgnoreApplier> applier ) {
		this.counter = counter;
		this.applier = applier;
	}

	public GlobalIgnoreApplier load() throws IOException {
		final Optional<Path> path = RecheckIgnoreUtil.getIgnoreFile();
		final PersistableGlobalIgnoreApplier ignoreApplier = Loaders
				.load( Files.lines(
						path.orElseThrow( () -> new IllegalArgumentException( "No reliable argument found." ) ) ) ) //
				.filter( ShouldIgnore.class::isInstance ) //
				.map( ShouldIgnore.class::cast ) //
				.collect( Collectors.collectingAndThen( Collectors.toList(), PersistableGlobalIgnoreApplier::new ) );
		final GlobalIgnoreApplier result = GlobalIgnoreApplier.create( counter, ignoreApplier );

		final Optional<Path> ignoreRuleFile = RecheckIgnoreUtil.getIgnoreRuleFile();
		if ( ignoreRuleFile.isPresent() ) {
			result.add( new JSShouldIgnoreImpl( ignoreRuleFile.get() ) );
		}

		return result;
	}

	public Counter getCounter() {
		return counter;
	}

	public Consumer<GlobalIgnoreApplier> getApplier() {
		return applier;
	}
}

@@ -150,44 +150,8 @@
 al;%0A
-import java.util.function.Consumer;%0A
 impo
@@ -644,62 +644,8 @@
 ter;
-%0A%09private final Consumer%3CGlobalIgnoreApplier%3E applier;
 %0A%0A%09p
@@ -699,53 +699,8 @@
 nter
-, final Consumer%3CGlobalIgnoreApplier%3E applier
  ) %7B
@@ -730,34 +730,8 @@
 er;%0A
-%09%09this.applier = applier;%0A
 %09%7D%0A%0A
@@ -1589,82 +1589,7 @@
 ;%0A%09%7D
-%0A%0A%09public Consumer%3CGlobalIgnoreApplier%3E getApplier() %7B%0A%09%09return applier;%0A%09%7D
 %0A%7D%0A

Remove obsolete field