diff options
author | Paul Duffin <paulduffin@google.com> | 2017-01-20 13:50:23 +0000 |
---|---|---|
committer | Paul Duffin <paulduffin@google.com> | 2017-01-20 13:50:23 +0000 |
commit | 74299c53a59140905e0259cb0a1130cb719733d8 (patch) | |
tree | aa4a6a53609f47d386dfa114be0abfc01e0e5dff /library/src/org/hamcrest/collection/IsCollectionContaining.java | |
parent | f1015b50e715aefc3070d83d95340cbc29811329 (diff) | |
download | hamcrest-74299c53a59140905e0259cb0a1130cb719733d8.tar.gz |
Match upstream file structure
Bug: 30946317
Test: make checkbuild and run cts CtsTextTestCases
Change-Id: I6c1773018f95855eb6599d66f6fb5923c7d48b03
Diffstat (limited to 'library/src/org/hamcrest/collection/IsCollectionContaining.java')
-rw-r--r-- | library/src/org/hamcrest/collection/IsCollectionContaining.java | 65 |
1 files changed, 0 insertions, 65 deletions
diff --git a/library/src/org/hamcrest/collection/IsCollectionContaining.java b/library/src/org/hamcrest/collection/IsCollectionContaining.java deleted file mode 100644 index ba98630..0000000 --- a/library/src/org/hamcrest/collection/IsCollectionContaining.java +++ /dev/null @@ -1,65 +0,0 @@ -package org.hamcrest.collection; - -import static org.hamcrest.core.AllOf.allOf; -import org.hamcrest.Description; -import org.hamcrest.Matcher; -import org.hamcrest.Factory; -import org.hamcrest.TypeSafeMatcher; -import static org.hamcrest.core.IsEqual.equalTo; - -import java.util.Collection; -import java.util.ArrayList; - -public class IsCollectionContaining<T> extends TypeSafeMatcher<Iterable<T>> { - private final Matcher<? extends T> elementMatcher; - - public IsCollectionContaining(Matcher<? extends T> elementMatcher) { - this.elementMatcher = elementMatcher; - } - - public boolean matchesSafely(Iterable<T> collection) { - for (T item : collection) { - if (elementMatcher.matches(item)){ - return true; - } - } - return false; - } - - public void describeTo(Description description) { - description - .appendText("a collection containing ") - .appendDescriptionOf(elementMatcher); - } - - @Factory - public static <T> Matcher<Iterable<T>> hasItem(Matcher<? extends T> elementMatcher) { - return new IsCollectionContaining<T>(elementMatcher); - } - - @Factory - public static <T> Matcher<Iterable<T>> hasItem(T element) { - return hasItem(equalTo(element)); - } - - @Factory - public static <T> Matcher<Iterable<T>> hasItems(Matcher<? extends T>... elementMatchers) { - Collection<Matcher<? extends Iterable<T>>> all - = new ArrayList<Matcher<? extends Iterable<T>>>(elementMatchers.length); - for (Matcher<? extends T> elementMatcher : elementMatchers) { - all.add(hasItem(elementMatcher)); - } - return allOf(all); - } - - @Factory - public static <T> Matcher<Iterable<T>> hasItems(T... elements) { - Collection<Matcher<? extends Iterable<T>>> all - = new ArrayList<Matcher<? extends Iterable<T>>>(elements.length); - for (T element : elements) { - all.add(hasItem(element)); - } - return allOf(all); - } - -} |