diff options
author | Brett Chabot <brettchabot@google.com> | 2014-06-11 16:08:22 -0700 |
---|---|---|
committer | Brett Chabot <brettchabot@google.com> | 2014-06-13 14:18:35 -0700 |
commit | f5e9a2415ec42c425c2bb17db46f2a9649992d80 (patch) | |
tree | 51560c56cffa6e2e751396bf3ccea0124b90efc5 /library/src/org/hamcrest/collection/IsIn.java | |
parent | f79c5d901a0e83f829c2325f5304f2b2c87fac70 (diff) | |
download | hamcrest-f5e9a2415ec42c425c2bb17db46f2a9649992d80.tar.gz |
Add hamcrest 1.1 library and integration source
Change-Id: I98691c987d5845c1d6e05325971517eec7e6f8b5
Diffstat (limited to 'library/src/org/hamcrest/collection/IsIn.java')
-rw-r--r-- | library/src/org/hamcrest/collection/IsIn.java | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/library/src/org/hamcrest/collection/IsIn.java b/library/src/org/hamcrest/collection/IsIn.java new file mode 100644 index 0000000..0a7bbb5 --- /dev/null +++ b/library/src/org/hamcrest/collection/IsIn.java @@ -0,0 +1,45 @@ +package org.hamcrest.collection; + +import java.util.Arrays; +import java.util.Collection; + +import org.hamcrest.BaseMatcher; +import org.hamcrest.Description; +import org.hamcrest.Factory; +import org.hamcrest.Matcher; + +public class IsIn<T> extends BaseMatcher<T> { + private final Collection<T> collection; + + public IsIn(Collection<T> collection) { + this.collection = collection; + } + + public IsIn(T[] elements) { + collection = Arrays.asList(elements); + } + + public boolean matches(Object o) { + return collection.contains(o); + } + + public void describeTo(Description buffer) { + buffer.appendText("one of "); + buffer.appendValueList("{", ", ", "}", collection); + } + + @Factory + public static <T> Matcher<T> isIn(Collection<T> collection) { + return new IsIn<T>(collection); + } + + @Factory + public static <T> Matcher<T> isIn(T[] elements) { + return new IsIn<T>(elements); + } + + @Factory + public static <T> Matcher<T> isOneOf(T... elements) { + return isIn(elements); + } +} |