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 import nl.tudelft.goal.EIS2Java.exception.TranslationException;
23 import nl.tudelft.goal.EIS2Java.translation.Java2Parameter;
24 import nl.tudelft.goal.EIS2Java.translation.Parameter2Java;
25 import nl.tudelft.goal.EIS2Java.translation.Translator;
26 import nl.tudelft.goal.unreal.messages.Team;
27 import eis.iilang.Identifier;
28 import eis.iilang.Parameter;
29
30 public class TeamTranslator implements Parameter2Java<Team>, Java2Parameter<Team> {
31
32 @Override
33 public Team translate(Parameter parameter) throws TranslationException {
34 String teamString = Translator.getInstance().translate2Java(parameter, String.class);
35
36 try {
37 return Team.valueOfIgnoresCase(teamString);
38 } catch (IllegalArgumentException e) {
39 String message = String.format("%s was not a Team. Expected on off %s.", teamString, Team.values());
40 throw new TranslationException(message, e);
41 }
42 }
43
44 @Override
45 public Parameter[] translate(Team o) throws TranslationException {
46 return new Parameter[]{ new Identifier(o.name().toLowerCase()) };
47 }
48
49 @Override
50 public Class<? extends Team> translatesFrom() {
51 return Team.class;
52 }
53
54 @Override
55 public Class<Team> translatesTo() {
56 return Team.class;
57 }
58
59 }