1
package org.hamcrest.core;
3
import java.util.ArrayList;
4
import java.util.Arrays;
7
import org.hamcrest.Description;
8
import org.hamcrest.Factory;
9
import org.hamcrest.Matcher;
12
* Calculates the logical disjunction of multiple matchers. Evaluation is shortcut, so
13
* subsequent matchers are not called if an earlier matcher returns <code>true</code>.
15
public class AnyOf<T> extends ShortcutCombination<T> {
17
public AnyOf(Iterable<Matcher<? super T>> matchers) {
22
public boolean matches(Object o) {
23
return matches(o, true);
27
public void describeTo(Description description) {
28
describeTo(description, "or");
32
* Evaluates to true if ANY of the passed in matchers evaluate to true.
35
public static <T> AnyOf<T> anyOf(Iterable<Matcher<? super T>> matchers) {
36
return new AnyOf<T>(matchers);
40
* Evaluates to true if ANY of the passed in matchers evaluate to true.
43
public static <T> AnyOf<T> anyOf(Matcher<? super T>... matchers) {
44
return anyOf(Arrays.asList(matchers));
48
* Evaluates to true if ANY of the passed in matchers evaluate to true.
51
public static <T> AnyOf<T> anyOf(Matcher<T> first, Matcher<? super T> second) {
52
List<Matcher<? super T>> matchers = new ArrayList<Matcher<? super T>>();
55
return anyOf(matchers);
59
* Evaluates to true if ANY of the passed in matchers evaluate to true.
62
public static <T> AnyOf<T> anyOf(Matcher<T> first, Matcher<? super T> second, Matcher<? super T> third) {
63
List<Matcher<? super T>> matchers = new ArrayList<Matcher<? super T>>();
67
return anyOf(matchers);
71
* Evaluates to true if ANY of the passed in matchers evaluate to true.
74
public static <T> AnyOf<T> anyOf(Matcher<T> first, Matcher<? super T> second, Matcher<? super T> third, Matcher<? super T> fourth) {
75
List<Matcher<? super T>> matchers = new ArrayList<Matcher<? super T>>();
80
return anyOf(matchers);
84
* Evaluates to true if ANY of the passed in matchers evaluate to true.
87
public static <T> AnyOf<T> anyOf(Matcher<T> first, Matcher<? super T> second, Matcher<? super T> third, Matcher<? super T> fourth, Matcher<? super T> fifth) {
88
List<Matcher<? super T>> matchers = new ArrayList<Matcher<? super T>>();
94
return anyOf(matchers);
98
* Evaluates to true if ANY of the passed in matchers evaluate to true.
101
public static <T> AnyOf<T> anyOf(Matcher<T> first, Matcher<? super T> second, Matcher<? super T> third, Matcher<? super T> fourth, Matcher<? super T> fifth, Matcher<? super T> sixth) {
102
List<Matcher<? super T>> matchers = new ArrayList<Matcher<? super T>>();
104
matchers.add(second);
106
matchers.add(fourth);
109
return anyOf(matchers);