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

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

Go to download

Statistical sampling library for use in virtualdataset libraries, based on apache commons math 4

There is a newer version: 2.12.15
Show newest version
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... 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 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 second, Matcher 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 second, Matcher third, Matcher 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 second, Matcher third, Matcher fourth, Matcher 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 second, Matcher third, Matcher fourth, Matcher fifth, Matcher 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); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy