All Downloads are FREE. Search and download functionalities are using the official Maven repository.

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 checker) {
        skipCircularReferenceCheck.add(checker);
        return this;
    }


    public MatcherConfiguration addSkipCircularReferenceChecker(Function[] checkers) {
        for (Function actual : checkers) {
            skipCircularReferenceCheck.add(actual);
        }
        return this;
    }

    public MatcherConfiguration addPatternToSort(Matcher fieldNamePattern) {
        patternsToSort.add(fieldNamePattern);
        return this;
    }

    public MatcherConfiguration addPatternToSort(Matcher[] fieldNamePatterns) {
        for (Matcher matcher : fieldNamePatterns) {
            patternsToSort.add(matcher);
        }
        return this;
    }

    public MatcherConfiguration addPatternToSort(Collection> fieldNamePattern) {
        patternsToSort.addAll(fieldNamePattern);
        return this;
    }

    public MatcherConfiguration addPathToSort(String path) {
        pathsToSort.add(path);
        return this;
    }

    public MatcherConfiguration addPathToSort(String[] fieldPaths) {
        for (String fieldPath : fieldPaths) {
            pathsToSort.add(fieldPath);
        }
        return this;
    }

    public MatcherConfiguration addPathToSort(Collection fieldPaths) {
        pathsToSort.addAll(fieldPaths);
        return this;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy