View Javadoc

1   package br.com.caelum.seleniumdsl.search;
2   
3   import java.util.ArrayList;
4   import java.util.List;
5   
6   import br.com.caelum.seleniumdsl.table.Row;
7   import br.com.caelum.seleniumdsl.table.Table;
8   
9   
10  public class Search implements RowMatcher {
11  
12  	protected List<Matcher> matchers = new ArrayList<Matcher>();
13  	private Table table;
14  	private int currentRow = 0;
15  	private int rowCount;
16  	
17  	protected void where(String name, Matcher matcher) {
18  		matcher.setColumn(name);
19  		matchers.add(matcher);
20  	}
21  	
22  	protected Matcher equals(String content) {
23  		return new EqualsMatcher(content);
24  	}
25  	
26  	protected Matcher containsAll(String...contents) {
27  		return new ContainsAllMatcher(contents);
28  	}
29  	
30  	public void setTable(Table table) {
31  		this.table = table;
32  		this.rowCount = table.getRowCount();
33  	}
34  	
35  	public Row next() {
36  		OUTTER:
37  		for (currentRow++; currentRow <= rowCount; currentRow++) {
38  			Row row = table.row(currentRow);
39  			for (Matcher matcher : matchers) {
40  				if(!matcher.matches(row))
41  					continue OUTTER;
42  			}
43  			return row;
44  		}
45  		return null;
46  	}
47  }