Coverage Report - org.eclipse.swtbot.swt.finder.matchers.AnyOf
 
Classes in this File Line Coverage Branch Coverage Complexity
AnyOf
72%
8/11
100%
4/4
1.6
 
 1  
 /*******************************************************************************
 2  
  * Copyright (c) 2010 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  
  *******************************************************************************/
 11  
 package org.eclipse.swtbot.swt.finder.matchers;
 12  
 
 13  
 import java.util.Arrays;
 14  
 
 15  
 import org.eclipse.swt.widgets.Widget;
 16  
 import org.hamcrest.Description;
 17  
 import org.hamcrest.Factory;
 18  
 import org.hamcrest.Matcher;
 19  
 
 20  
 /**
 21  
  * A matcher that evaluates to <code>true</code> if any the matchers evaluate to <code>true</code>.
 22  
  *
 23  
  * @author Ketan Padegaonkar &lt;KetanPadegaonkar [at] gmail [dot] com&gt;
 24  
  * @version $Id$
 25  
  */
 26  
 public class AnyOf<T> extends AbstractMatcher<T> {
 27  
         private final Iterable<Matcher<? extends T>>        matchers;
 28  
 
 29  2
         AnyOf(Iterable<Matcher<? extends T>> matchers) {
 30  2
                 this.matchers = matchers;
 31  2
         }
 32  
 
 33  
         protected boolean doMatch(Object o) {
 34  6
                 for (Matcher<? extends T> matcher : matchers) {
 35  3
                         if (matcher.matches(o)) {
 36  1
                                 return true;
 37  
                         }
 38  
                 }
 39  1
                 return false;
 40  
         }
 41  
 
 42  
         public void describeTo(Description description) {
 43  0
                 description.appendList("(", " or ", ")", matchers); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
 44  0
         }
 45  
 
 46  
         /**
 47  
          * Evaluates to true only if ANY of the passed in matchers evaluate to true.
 48  
          *
 49  
          * @return a matcher.
 50  
          */
 51  
         @Factory
 52  
         public static <T extends Widget> Matcher<T> anyOf(Matcher<? extends T>... matchers) {
 53  2
                 return new AnyOf<T>(Arrays.asList(matchers));
 54  
         }
 55  
 
 56  
         /**
 57  
          * Evaluates to true only if ANY of the passed in matchers evaluate to true.
 58  
          *
 59  
          * @return a matcher.
 60  
          */
 61  
         @Factory
 62  
         public static <T extends Widget> Matcher<T> anyOf(Iterable<Matcher<? extends T>> matchers) {
 63  0
                 return new AnyOf<T>(matchers);
 64  
         }
 65  
 
 66  
 }