RegexFilter.java

1
/*-
2
 * #%L
3
 * io.earcam.utilitarian.site.search.offline
4
 * %%
5
 * Copyright (C) 2017 earcam
6
 * %%
7
 * SPDX-License-Identifier: (BSD-3-Clause OR EPL-1.0 OR Apache-2.0 OR MIT)
8
 *
9
 * You <b>must</b> choose to accept, in full - any individual or combination of
10
 * the following licenses:
11
 * <ul>
12
 * 	<li><a href="https://opensource.org/licenses/BSD-3-Clause">BSD-3-Clause</a></li>
13
 * 	<li><a href="https://www.eclipse.org/legal/epl-v10.html">EPL-1.0</a></li>
14
 * 	<li><a href="https://www.apache.org/licenses/LICENSE-2.0">Apache-2.0</a></li>
15
 * 	<li><a href="https://opensource.org/licenses/MIT">MIT</a></li>
16
 * </ul>
17
 * #L%
18
 */
19
package io.earcam.utilitarian.site.search.offline;
20
21
import static io.earcam.utilitarian.site.search.offline.Component.mandatory;
22
import static java.util.regex.Pattern.compile;
23
24
import java.util.Map;
25
import java.util.function.Predicate;
26
27
import org.slf4j.Logger;
28
import org.slf4j.LoggerFactory;
29
30
public class RegexFilter implements Filter {
31
32
	private static final Logger LOG = LoggerFactory.getLogger(RegexFilter.class);
33
34
	public static final String INCLUDE = "include";
35
	public static final String EXCLUDE = "exclude";
36
37
	public final String id = id();
38
	private Predicate<String> predicate;
39
40
41
	@Override
42
	public void configure(Map<String, String> configuration)
43
	{
44
		String include = mandatory(configuration, INCLUDE);
45
		String exclude = mandatory(configuration, EXCLUDE);
46
47
		predicate = compile(include).asPredicate().and(compile(exclude).asPredicate().negate());
48
		LOG.debug("{} include pattern: {}", id, include);
49
		LOG.debug("{} exclude pattern: {}", id, exclude);
50
	}
51
52
53
	@Override
54
	public boolean test(Document document)
55
	{
56
		String path = document.file().toAbsolutePath().toString();
57
		boolean include = predicate.test(path);
58
		LOG.debug("{} {}cluding {}", id, include ? "in" : "ex", path);
59 1 1. test : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED
		return include;
60
	}
61
}

Mutations

59

1.1
Location : test
Killed by : io.earcam.utilitarian.site.search.offline.RegexFilterTest.excludes()
replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED

Active mutators

Tests examined


Report generated by PIT 1.4.3