org.hamcrest.core.AnyOf Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of virtdata-lib-realer Show documentation
Show all versions of virtdata-lib-realer Show documentation
With inspiration from other libraries
package org.hamcrest.core;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.hamcrest.Description;
import org.hamcrest.Factory;
import org.hamcrest.Matcher;
/**
* Calculates the logical disjunction of multiple matchers. Evaluation is shortcut, so
* subsequent matchers are not called if an earlier matcher returns true
.
*/
public class AnyOf extends ShortcutCombination {
public AnyOf(Iterable> matchers) {
super(matchers);
}
@Override
public boolean matches(Object o) {
return matches(o, true);
}
@Override
public void describeTo(Description description) {
describeTo(description, "or");
}
/**
* Creates a matcher that matches if the examined object matches ANY of the specified matchers.
*
* For example:
* assertThat("myValue", anyOf(startsWith("foo"), containsString("Val")))
*/
@Factory
public static AnyOf anyOf(Iterable> matchers) {
return new AnyOf(matchers);
}
/**
* Creates a matcher that matches if the examined object matches ANY of the specified matchers.
*
* For example:
* assertThat("myValue", anyOf(startsWith("foo"), containsString("Val")))
*/
@Factory
public static AnyOf anyOf(Matcher super T>... matchers) {
return anyOf(Arrays.asList(matchers));
}
/**
* Creates a matcher that matches if the examined object matches ANY of the specified matchers.
*
* For example:
* assertThat("myValue", anyOf(startsWith("foo"), containsString("Val")))
*/
@Factory
public static AnyOf anyOf(Matcher first, Matcher super T> second) {
List> matchers = new ArrayList>();
matchers.add(first);
matchers.add(second);
return anyOf(matchers);
}
/**
* Creates a matcher that matches if the examined object matches ANY of the specified matchers.
*
* For example:
* assertThat("myValue", anyOf(startsWith("foo"), containsString("Val")))
*/
@Factory
public static AnyOf anyOf(Matcher first, Matcher super T> second, Matcher super T> third) {
List> matchers = new ArrayList>();
matchers.add(first);
matchers.add(second);
matchers.add(third);
return anyOf(matchers);
}
/**
* Creates a matcher that matches if the examined object matches ANY of the specified matchers.
*
* For example:
* assertThat("myValue", anyOf(startsWith("foo"), containsString("Val")))
*/
@Factory
public static AnyOf anyOf(Matcher first, Matcher super T> second, Matcher super T> third, Matcher super T> fourth) {
List> matchers = new ArrayList>();
matchers.add(first);
matchers.add(second);
matchers.add(third);
matchers.add(fourth);
return anyOf(matchers);
}
/**
* Creates a matcher that matches if the examined object matches ANY of the specified matchers.
*
* For example:
* assertThat("myValue", anyOf(startsWith("foo"), containsString("Val")))
*/
@Factory
public static AnyOf anyOf(Matcher first, Matcher super T> second, Matcher super T> third, Matcher super T> fourth, Matcher super T> fifth) {
List> matchers = new ArrayList>();
matchers.add(first);
matchers.add(second);
matchers.add(third);
matchers.add(fourth);
matchers.add(fifth);
return anyOf(matchers);
}
/**
* Creates a matcher that matches if the examined object matches ANY of the specified matchers.
*
* For example:
* assertThat("myValue", anyOf(startsWith("foo"), containsString("Val")))
*/
@Factory
public static AnyOf anyOf(Matcher first, Matcher super T> second, Matcher super T> third, Matcher super T> fourth, Matcher super T> fifth, Matcher super T> sixth) {
List> matchers = new ArrayList>();
matchers.add(first);
matchers.add(second);
matchers.add(third);
matchers.add(fourth);
matchers.add(fifth);
matchers.add(sixth);
return anyOf(matchers);
}
}