-
Notifications
You must be signed in to change notification settings - Fork 210
/
Querier.java
51 lines (41 loc) · 1.24 KB
/
Querier.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
package com.swjtu.querier;
import com.swjtu.http.AbstractHttpAttribute;
import com.swjtu.lang.LANG;
import com.swjtu.tts.AbstractTTS;
import java.util.ArrayList;
import java.util.List;
public final class Querier<T extends AbstractHttpAttribute> {
private LANG from;
private LANG to;
private String text;
private List<T> collection;
public Querier() {
collection = new ArrayList<T>();
}
public List<String> execute() {
List<String> result = new ArrayList<String>();
for (T element : collection) {
if (element.getClass().getName().contains("Translator")) {
result.add(element.run(from, to, text));
} else if (element.getClass().getName().contains("TTS")) {
result.add(element.run(from, text));
}
}
return result;
}
public void setParams(LANG from, LANG to, String text) {
this.from = from;
this.to = to;
this.text = text;
}
public void setParams(LANG source, String text) {
this.from = source;
this.text = text;
}
public void attach(T element){
collection.add(element);
}
public void detach(T element) {
collection.remove(element);
}
}