1 package cz.cuni.amis.pogamut.ut2004.tournament.botexecution;
2
3 import java.io.File;
4 import java.util.HashMap;
5 import java.util.Map;
6
7 import cz.cuni.amis.pogamut.ut2004.tournament.match.UT2004BotConfig;
8 import cz.cuni.amis.utils.NullCheck;
9 import cz.cuni.amis.utils.token.IToken;
10 import cz.cuni.amis.utils.token.Tokens;
11
12 public class UT2004BotExecutionConfig {
13
14
15
16
17
18
19 private IToken botId;
20
21
22
23
24 private String pathToBotJar = null;
25
26
27
28
29 private boolean redirectStdErr = true;
30
31
32
33
34 private boolean redirectStdOut = true;
35
36
37
38
39 private File fileToJar;
40
41
42
43
44 private Map<String, Object> parameters = new HashMap<String, Object>();
45
46
47
48
49
50
51
52
53 public IToken getBotId() {
54 return botId;
55 }
56
57
58
59
60 public UT2004BotExecutionConfig() {
61 }
62
63
64
65
66
67 public UT2004BotExecutionConfig(UT2004BotConfig value) {
68 this.botId = value.getBotId();
69 this.setPathToBotJar(value.getPathToBotJar());
70 this.redirectStdErr = value.isRedirectStdErr();
71 this.redirectStdOut = value.isRedirectStdOut();
72 }
73
74
75
76
77
78
79
80
81 public UT2004BotExecutionConfig setBotId(String botId) {
82 NullCheck.check(botId, "botId");
83 this.botId = Tokens.get(botId);
84 return this;
85 }
86
87
88
89
90
91
92
93
94 public UT2004BotExecutionConfig setBotId(IToken botId) {
95 NullCheck.check(botId, "botId");
96 this.botId = botId;
97 return this;
98 }
99
100
101
102
103
104 public String getPathToBotJar() {
105 return pathToBotJar;
106 }
107
108
109
110
111
112 public UT2004BotExecutionConfig setPathToBotJar(String pathToBotJar) {
113 if (pathToBotJar != null) {
114 this.fileToJar = new File(pathToBotJar);
115 } else {
116 this.fileToJar = null;
117 }
118 this.pathToBotJar = pathToBotJar;
119 return this;
120 }
121
122
123
124
125
126 public boolean isBotJarExist() {
127 if (this.pathToBotJar == null) return false;
128 File file = getJarFile();
129 return file.exists() && file.isFile();
130 }
131
132
133
134
135
136 public File getJarFile() {
137 return fileToJar;
138 }
139
140
141
142
143
144 public boolean isRedirectStdErr() {
145 return redirectStdErr;
146 }
147
148
149
150
151
152 public UT2004BotExecutionConfig setRedirectStdErr(boolean redirectStdErr) {
153 this.redirectStdErr = redirectStdErr;
154 return this;
155 }
156
157
158
159
160
161 public boolean isRedirectStdOut() {
162 return redirectStdOut;
163 }
164
165
166
167
168
169 public UT2004BotExecutionConfig setRedirectStdOut(boolean redirectStdOut) {
170 this.redirectStdOut = redirectStdOut;
171 return this;
172 }
173
174
175
176
177
178
179
180
181 public Object addParameter(String key, Object value) {
182 return this.parameters.put(key, value);
183 }
184
185
186
187
188
189
190
191 public Object removeParameter(String key) {
192 return this.parameters.remove(key);
193 }
194
195 public Map<String, Object> getParameters() {
196 return this.parameters;
197 }
198
199 public void setParameters(Map<String, ?> parameters) {
200 this.parameters = (Map<String, Object>) parameters;
201 }
202
203 @Override
204 public String toString() {
205 return "UT2004BotExecutionConfig[botId=" + botId.getToken() + ", jar=" + pathToBotJar + "]";
206 }
207
208 }