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

org.hamcrest.core.ShortcutCombination Maven / Gradle / Ivy

There is a newer version: 2.12.15
Show newest version
package org.hamcrest.core;

import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;
import org.hamcrest.Matcher;

abstract class ShortcutCombination extends BaseMatcher {

    private final Iterable> matchers;

    public ShortcutCombination(Iterable> matchers) {
        this.matchers = matchers;
    }
    
    @Override
    public abstract boolean matches(Object o);
    
    @Override
    public abstract void describeTo(Description description);
    
    protected boolean matches(Object o, boolean shortcut) {
        for (Matcher matcher : matchers) {
            if (matcher.matches(o) == shortcut) {
                return shortcut;
            }
        }
        return !shortcut;
    }
    
    public void describeTo(Description description, String operator) {
        description.appendList("(", " " + operator + " ", ")", matchers);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy