| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| WaitForObjectCondition |
|
| 1.0;1 |
| 1 | /******************************************************************************* | |
| 2 | * Copyright (c) 2008-2009 SWTBot Committers 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.waits; | |
| 12 | ||
| 13 | import java.util.ArrayList; | |
| 14 | import java.util.List; | |
| 15 | ||
| 16 | import org.hamcrest.Matcher; | |
| 17 | ||
| 18 | /** | |
| 19 | * Waits for objects to appear until the matcher evaluates to true. | |
| 20 | * | |
| 21 | * @see Conditions | |
| 22 | * @author Ketan Padegaonkar <KetanPadegaonkar [at] gmail [dot] com> | |
| 23 | * @version $Id$ | |
| 24 | */ | |
| 25 | public abstract class WaitForObjectCondition<T> extends DefaultCondition { | |
| 26 | ||
| 27 | /** The matcher that is used to match widgets. */ | |
| 28 | protected final Matcher<T> matcher; | |
| 29 | private final List<T> matches; | |
| 30 | ||
| 31 | /** | |
| 32 | * Waits until the matcher is true. | |
| 33 | * | |
| 34 | * @param matcher the matcher. | |
| 35 | */ | |
| 36 | 1816 | public WaitForObjectCondition(Matcher<T> matcher) { |
| 37 | 1816 | this.matcher = matcher; |
| 38 | 1816 | matches = new ArrayList<T>(); |
| 39 | 1816 | } |
| 40 | ||
| 41 | public boolean test() throws Exception { | |
| 42 | 1926 | matches.clear(); |
| 43 | 1926 | matches.addAll(findMatches()); |
| 44 | 1926 | return !matches.isEmpty(); |
| 45 | } | |
| 46 | ||
| 47 | /** | |
| 48 | * @return the matches that subclasses that matched. | |
| 49 | */ | |
| 50 | protected abstract List<T> findMatches(); | |
| 51 | ||
| 52 | /** | |
| 53 | * @return all objects that matched the matcher. | |
| 54 | */ | |
| 55 | public List<T> getAllMatches() { | |
| 56 | 38 | return this.matches; |
| 57 | } | |
| 58 | ||
| 59 | /** | |
| 60 | * @param index the index of the object. | |
| 61 | * @return the element at the specified index in the list of matched objects. | |
| 62 | */ | |
| 63 | public T get(int index) { | |
| 64 | 1749 | return this.matches.get(index); |
| 65 | } | |
| 66 | } |