package org.hamcrest.core; import org.hamcrest.BaseMatcher; import org.hamcrest.Matcher; import org.hamcrest.Description; import org.hamcrest.Factory; import java.util.Arrays; /** * Calculates the logical disjunction of two matchers. Evaluation is * shortcut, so that the second matcher is not called if the first * matcher returns true. */ public class AnyOf extends BaseMatcher { private final Iterable> matchers; public AnyOf(Iterable> matchers) { this.matchers = matchers; } public boolean matches(Object o) { for (Matcher matcher : matchers) { if (matcher.matches(o)) { return true; } } return false; } public void describeTo(Description description) { description.appendList("(", " or ", ")", matchers); } /** * Evaluates to true if ANY of the passed in matchers evaluate to true. */ @Factory public static Matcher anyOf(Matcher... matchers) { return anyOf(Arrays.asList(matchers)); } /** * Evaluates to true if ANY of the passed in matchers evaluate to true. */ @Factory public static Matcher anyOf(Iterable> matchers) { return new AnyOf(matchers); } }