1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package nl.tudelft.goal.unreal.translators;
21
22
23 import nl.tudelft.goal.ut2004.util.Team;
24 import eis.eis2java.exception.TranslationException;
25 import eis.eis2java.translation.Java2Parameter;
26 import eis.eis2java.translation.Parameter2Java;
27 import eis.eis2java.translation.Translator;
28 import eis.iilang.Identifier;
29 import eis.iilang.Parameter;
30
31 public class TeamTranslator implements Parameter2Java<Team>, Java2Parameter<Team> {
32
33 @Override
34 public Team translate(Parameter parameter) throws TranslationException {
35 String teamString = Translator.getInstance().translate2Java(parameter, String.class);
36
37 try {
38 return Team.valueOfIgnoresCase(teamString);
39 } catch (IllegalArgumentException e) {
40 String message = String.format("%s was not a Team. Expected on off %s.", teamString, Team.values());
41 throw new TranslationException(message, e);
42 }
43 }
44
45 @Override
46 public Parameter[] translate(Team o) throws TranslationException {
47 return new Parameter[]{ new Identifier(o.name().toLowerCase()) };
48 }
49
50 @Override
51 public Class<? extends Team> translatesFrom() {
52 return Team.class;
53 }
54
55 @Override
56 public Class<Team> translatesTo() {
57 return Team.class;
58 }
59
60 }