Coverage Report - org.eclipse.swtbot.swt.finder.utils.internal.WidgetIndexFinder
 
Classes in this File Line Coverage Branch Coverage Complexity
WidgetIndexFinder
100%
7/7
N/A
1
 
 1  1224
 /*******************************************************************************
 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  
  *******************************************************************************/
 11  
 package org.eclipse.swtbot.swt.finder.utils.internal;
 12  
 
 13  
 import java.util.Arrays;
 14  
 
 15  
 import org.eclipse.swt.widgets.Widget;
 16  
 import org.eclipse.swtbot.swt.finder.results.IntResult;
 17  
 
 18  
 /**
 19  
  * This is used to find the sibling widget and its index.
 20  
  * <p>
 21  
  * <b>NOTE: This finds all the siblings and finds the index of the widget among the siblings. This does not use SWTUtils
 22  
  * to find siblings for performance reasons</b>
 23  
  * </p>
 24  
  *
 25  
  * @author Ketan Padegaonkar &lt;KetanPadegaonkar [at] gmail [dot] com&gt;
 26  
  * @see PreviousWidgetFinder
 27  
  * @see NextWidgetFinder
 28  
  */
 29  
 public final class WidgetIndexFinder implements IntResult {
 30  
         /**
 31  
          * The widget.
 32  
          */
 33  
         private final Widget        w;
 34  
 
 35  
         /**
 36  
          * Constructs the widget index finder for the given widget.
 37  
          *
 38  
          * @param w the widget.
 39  
          */
 40  1729
         public WidgetIndexFinder(Widget w) {
 41  1729
                 this.w = w;
 42  1729
         }
 43  
 
 44  
         /**
 45  
          * Runs the finder to locate the index of the sibling.
 46  
          *
 47  
          * @see org.eclipse.swtbot.swt.finder.results.IntResult#run()
 48  
          * @return The index value.
 49  
          */
 50  
         public Integer run() {
 51  1729
                 Widget[] siblings = new SiblingFinder(w).run();
 52  1729
                 return indexOf(siblings, w);
 53  
         }
 54  
 
 55  
         /**
 56  
          * Gets the index of the widget in the list of widgets.
 57  
          *
 58  
          * @param widgets The widget set to search through.
 59  
          * @param w The widget to find.
 60  
          * @return The index of the widget.
 61  
          */
 62  
         private int indexOf(Widget[] widgets, Widget w) {
 63  1729
                 return Arrays.asList(widgets).indexOf(w);
 64  
         }
 65  
 }