Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
AllOf |
|
| 1.6;1.6 |
1 | /******************************************************************************* | |
2 | * Copyright (c) 2008 Ketan Padegaonkar and others. | |
3 | * All rights reserved. This program and the accompanying materials | |
4 | * are made available under the terms of the Eclipse Public License v1.0 | |
5 | * which accompanies this distribution, and is available at | |
6 | * http://www.eclipse.org/legal/epl-v10.html | |
7 | * | |
8 | * Contributors: | |
9 | * Ketan Padegaonkar - initial API and implementation | |
10 | * Ketan Padegaonkar - http://swtbot.org/bugzilla/show_bug.cgi?id=126 | |
11 | *******************************************************************************/ | |
12 | package org.eclipse.swtbot.swt.finder.matchers; | |
13 | ||
14 | import java.util.Arrays; | |
15 | ||
16 | import org.eclipse.swt.widgets.Widget; | |
17 | import org.hamcrest.Description; | |
18 | import org.hamcrest.Factory; | |
19 | import org.hamcrest.Matcher; | |
20 | ||
21 | /** | |
22 | * A matcher that evaluates to <code>true</code> if and only if all the matchers evaluate to <code>true</code>. | |
23 | * | |
24 | * @author Ketan Padegaonkar <KetanPadegaonkar [at] gmail [dot] com> | |
25 | * @version $Id$ | |
26 | */ | |
27 | public class AllOf<T> extends AbstractMatcher<T> { | |
28 | private final Iterable<Matcher<? extends T>> matchers; | |
29 | ||
30 | 1272 | AllOf(Iterable<Matcher<? extends T>> matchers) { |
31 | 1272 | this.matchers = matchers; |
32 | 1272 | } |
33 | ||
34 | protected boolean doMatch(Object o) { | |
35 | 226277 | for (Matcher<? extends T> matcher : matchers) { |
36 | 128035 | if (!matcher.matches(o)) { |
37 | 95028 | return false; |
38 | } | |
39 | } | |
40 | 1607 | return true; |
41 | } | |
42 | ||
43 | public void describeTo(Description description) { | |
44 | 6211 | description.appendList("(", " and ", ")", matchers); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ |
45 | 6211 | } |
46 | ||
47 | /** | |
48 | * Evaluates to true only if ALL of the passed in matchers evaluate to true. | |
49 | * | |
50 | * @return a matcher. | |
51 | */ | |
52 | @Factory | |
53 | public static <T extends Widget> Matcher<T> allOf(Matcher<? extends T>... matchers) { | |
54 | 1272 | return new AllOf<T>(Arrays.asList(matchers)); |
55 | } | |
56 | ||
57 | /** | |
58 | * Evaluates to true only if ALL of the passed in matchers evaluate to true. | |
59 | * | |
60 | * @return a matcher. | |
61 | */ | |
62 | @Factory | |
63 | public static <T extends Widget> Matcher<T> allOf(Iterable<Matcher<? extends T>> matchers) { | |
64 | 0 | return new AllOf<T>(matchers); |
65 | } | |
66 | ||
67 | } |