1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.aludratest.service.locator.element;
17
18 import java.util.ArrayList;
19 import java.util.Iterator;
20 import java.util.List;
21
22
23
24
25
26
27
28
29
30
31 public class ElementLocators implements Iterable<GUIElementLocator> {
32
33
34
35 private List<GUIElementLocator> options;
36
37
38
39
40
41 public ElementLocators(GUIElementLocator... locators) {
42 options = new ArrayList<GUIElementLocator>();
43 for (GUIElementLocator locator : locators) {
44 options.add(locator);
45 }
46 }
47
48
49
50
51 @Override
52 public Iterator<GUIElementLocator> iterator() {
53 return options.iterator();
54 }
55
56
57
58
59
60
61
62 public GUIElementLocator newMutableInstance() {
63 return new ElementLocatorsGUI(options);
64 }
65
66
67
68 @Override
69 public int hashCode() {
70 return super.hashCode() * 31 + options.hashCode();
71 }
72
73 @Override
74 public boolean equals(Object obj) {
75 if (this == obj) {
76 return true;
77 }
78 if (!super.equals(obj) || getClass() != obj.getClass()) {
79 return false;
80 }
81 ElementLocators that = (ElementLocators) obj;
82 return (this.options.equals(that.options));
83 }
84
85 @Override
86 public String toString() {
87 StringBuilder builder = new StringBuilder(getClass().getSimpleName()).append("[");
88 builder.append("options=[");
89 for (int i = 0; i < options.size(); i++) {
90 builder.append(i > 0 ? ", " : "");
91 builder.append("#").append(i).append(": ").append(options.get(i));
92 }
93 builder.append("]");
94 return builder.append("]").toString();
95 }
96
97 public static class ElementLocatorsGUI extends GUIElementLocator implements Iterable<GUIElementLocator> {
98
99 private List<GUIElementLocator> options;
100 private GUIElementLocator usedOption;
101
102 private ElementLocatorsGUI(List<GUIElementLocator> options) {
103 super("");
104 this.options = new ArrayList<GUIElementLocator>(options);
105 }
106
107 @Override
108 public Iterator<GUIElementLocator> iterator() {
109 return options.iterator();
110 }
111
112
113
114
115
116
117
118
119
120 public final void setUsedOption(GUIElementLocator option) {
121 this.usedOption = option;
122 }
123
124
125 public GUIElementLocator getUsedOption() {
126 return usedOption;
127 }
128
129
130
131 private int indexOf(GUIElementLocator option) {
132 for (int i = 0; i < options.size(); i++) {
133 GUIElementLocator candidate = options.get(i);
134 if (candidate == option) {
135 return i;
136 }
137 }
138 return -1;
139 }
140
141
142 @Override
143 public int hashCode() {
144 return super.hashCode() * 31 + options.hashCode();
145 }
146
147 @Override
148 public boolean equals(Object obj) {
149 if (this == obj) {
150 return true;
151 }
152 if (!super.equals(obj) || getClass() != obj.getClass()) {
153 return false;
154 }
155 ElementLocatorsGUI that = (ElementLocatorsGUI) obj;
156 return (this.options.equals(that.options) && (this.usedOption == null ? that.usedOption == null : this.usedOption
157 .equals(that.usedOption)));
158 }
159
160 @Override
161 public String toString() {
162 StringBuilder builder = new StringBuilder(getClass().getSimpleName()).append("[");
163 builder.append("options=[");
164 for (int i = 0; i < options.size(); i++) {
165 builder.append(i > 0 ? ", " : "");
166 builder.append("#").append(i).append(": ").append(options.get(i));
167 }
168 builder.append("]");
169 builder.append(", usedLocator=");
170 if (usedOption != null) {
171 builder.append(usedOption.toString());
172 }
173 else {
174 builder.append("none");
175 }
176 return builder.append("]").toString();
177 }
178
179 }
180 }