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 extends BaseMatcher { private final Collection collection; public IsIn(Collection 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 Matcher isIn(Collection collection) { return new IsIn(collection); } @Factory public static Matcher isIn(T[] elements) { return new IsIn(elements); } @Factory public static Matcher isOneOf(T... elements) { return isIn(elements); } }