1 package com.atlassian.webdriver.testing.matcher;
2
3 import com.google.common.base.Predicate;
4 import org.hamcrest.Matcher;
5
6 import javax.annotation.Nonnull;
7
8
9
10
11
12
13 public final class MatcherPredicate<T> implements Predicate<T>
14 {
15 @Nonnull
16 public static <T> Predicate<T> forMatcher(@Nonnull Matcher<T> matcher)
17 {
18 return new MatcherPredicate<T>(matcher);
19 }
20
21 @Nonnull
22 public static <T> Predicate<T> withMatcher(@Nonnull Matcher<T> matcher)
23 {
24 return new MatcherPredicate<T>(matcher);
25 }
26
27 private final Matcher<T> matcher;
28
29 private MatcherPredicate(Matcher<T> matcher)
30 {
31 this.matcher = matcher;
32 }
33
34 @Override
35 public boolean apply(T input)
36 {
37 return matcher.matches(input);
38 }
39 }