diff options
Diffstat (limited to 'hamcrest-core/src/main/java/org/hamcrest/core/ShortcutCombination.java')
-rw-r--r-- | hamcrest-core/src/main/java/org/hamcrest/core/ShortcutCombination.java | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/hamcrest-core/src/main/java/org/hamcrest/core/ShortcutCombination.java b/hamcrest-core/src/main/java/org/hamcrest/core/ShortcutCombination.java new file mode 100644 index 0000000..30b33af --- /dev/null +++ b/hamcrest-core/src/main/java/org/hamcrest/core/ShortcutCombination.java @@ -0,0 +1,33 @@ +package org.hamcrest.core; + +import org.hamcrest.BaseMatcher; +import org.hamcrest.Description; +import org.hamcrest.Matcher; + +abstract class ShortcutCombination<T> extends BaseMatcher<T> { + + private final Iterable<Matcher<? super T>> matchers; + + public ShortcutCombination(Iterable<Matcher<? super T>> 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<? super T> matcher : matchers) { + if (matcher.matches(o) == shortcut) { + return shortcut; + } + } + return !shortcut; + } + + public void describeTo(Description description, String operator) { + description.appendList("(", " " + operator + " ", ")", matchers); + } +} |