com.github.karsaig.approvalcrest.MatcherConfiguration Maven / Gradle / Ivy
The newest version!
package com.github.karsaig.approvalcrest;
import org.hamcrest.Matcher;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Function;
public class MatcherConfiguration {
private final Set pathsToIgnore = new HashSet<>();
private final Map> customMatchers = new HashMap<>();
private final List> typesToIgnore = new ArrayList<>();
private final List> patternsToIgnore = new ArrayList<>();
private final List> skipCircularReferenceCheck = new ArrayList<>();
private final Set pathsToSort = new HashSet<>();
private final List> patternsToSort = new ArrayList<>();
public MatcherConfiguration() {
skipCircularReferenceCheck.add(o -> Path.class.isInstance(o));
}
public Map> getCustomMatchers() {
return customMatchers;
}
public Set getPathsToIgnore() {
return pathsToIgnore;
}
public List> getPatternsToIgnore() {
return patternsToIgnore;
}
public List> getSkipCircularReferenceCheck() {
return skipCircularReferenceCheck;
}
public List> getTypesToIgnore() {
return typesToIgnore;
}
public Set getPathsToSort() {
return pathsToSort;
}
public List> getPatternsToSort() {
return patternsToSort;
}
public MatcherConfiguration addPathToIgnore(String path) {
pathsToIgnore.add(path);
return this;
}
public MatcherConfiguration addPathToIgnore(String[] fieldPaths) {
for (String fieldPath : fieldPaths) {
pathsToIgnore.add(fieldPath);
}
return this;
}
public MatcherConfiguration addPathToIgnore(Collection fieldPaths) {
pathsToIgnore.addAll(fieldPaths);
return this;
}
public MatcherConfiguration addCustomMatcher(String fieldPath, Matcher> matcher) {
customMatchers.put(fieldPath, matcher);
return this;
}
public MatcherConfiguration addTypeToIgnore(Class> clazz) {
typesToIgnore.add(clazz);
return this;
}
public MatcherConfiguration addTypeToIgnore(Class>[] clazzs) {
for (Class> clazz : clazzs) {
typesToIgnore.add(clazz);
}
return this;
}
public MatcherConfiguration addTypeToIgnore(Collection> clazzs) {
typesToIgnore.addAll(clazzs);
return this;
}
public MatcherConfiguration addPatternToIgnore(Matcher fieldNamePattern) {
patternsToIgnore.add(fieldNamePattern);
return this;
}
public MatcherConfiguration addPatternToIgnore(Matcher[] fieldNamePatterns) {
for (Matcher matcher : fieldNamePatterns) {
patternsToIgnore.add(matcher);
}
return this;
}
public MatcherConfiguration addPatternToIgnore(Collection> fieldNamePattern) {
patternsToIgnore.addAll(fieldNamePattern);
return this;
}
public MatcherConfiguration addSkipCircularReferenceChecker(Function