package sherlock.commit;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.Set;
import java.util.function.Predicate;

import static java.util.Arrays.stream;

public class CommitKeywordsFilter implements Predicate<String> {

	private static final Set<String> keywords = new HashSet<>();

	public CommitKeywordsFilter() {
		try {
			try (BufferedReader keywordsReader = new BufferedReader(
				new InputStreamReader(
					this.getClass().getClassLoader().getResourceAsStream("keywords.txt")))) {

				keywordsReader
					.lines()
					.filter(line -> !line.isEmpty() && !line.startsWith("#"))
					.flatMap(line -> stream(line.split("\\s")))
					.forEach(keywords::add);
			}
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}

	@Override
	public boolean test(String word) {
		return !keywords.contains(word);
	}
}

@@ -404,17 +404,8 @@
 ) %7B%0A
-%09%09try %7B%0A%09
 %09%09tr
@@ -462,17 +462,16 @@
 der(%0A%09%09%09
-%09
 new Inpu
@@ -485,17 +485,16 @@
 Reader(%0A
-%09
 %09%09%09%09this
@@ -567,17 +567,16 @@
 ) %7B%0A%0A%09%09%09
-%09
 keywords
@@ -586,17 +586,16 @@
 der%0A%09%09%09%09
-%09
 .lines()
@@ -595,17 +595,16 @@
 lines()%0A
-%09
 %09%09%09%09.fil
@@ -661,17 +661,16 @@
 %22))%0A%09%09%09%09
-%09
 .flatMap
@@ -705,17 +705,16 @@
 %5C%5Cs%22)))%0A
-%09
 %09%09%09%09.for
@@ -738,13 +738,8 @@
 d);%0A
-%09%09%09%7D%0A
 %09%09%7D 

Refactor error handling