/
MatcherBuilder.java
58 lines (51 loc) · 1.51 KB
/
MatcherBuilder.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*******************************************************************************
* Copyright (c) 2017 Red Hat, Inc and others.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Red Hat, Inc - initial API and implementation
*******************************************************************************/
package org.eclipse.reddeer.common.matcher;
import org.hamcrest.Matcher;
/**
* Builder for building more complex matchers.
*
* @author Jiri Peterka
*
*/
public class MatcherBuilder {
private static MatcherBuilder instance;
/**
* Gets singleton instance of MatcherBuilder.
*
* @return instance of MatcherBuilder
*/
public static MatcherBuilder getInstance() {
if (instance == null) {
instance = new MatcherBuilder();
}
return instance;
}
private MatcherBuilder() {
}
/**
* Adds matcher to the beginning of array of matchers.
*
* @param matchers array of matchers
* @param matcher matcher to add to array of matchers
* @return new array containing old array of matchers and new matcher
*/
@SuppressWarnings("rawtypes")
public Matcher[] addMatcher(Matcher[] matchers, Matcher matcher) {
Matcher[] finalMatchers = new Matcher[matchers.length + 1];
finalMatchers[0]=matcher;
for (int i = 1; i < finalMatchers.length; i++) {
finalMatchers[i] = matchers[i-1];
}
return finalMatchers;
}
}