1 package nl.tudelft.goal.unreal.translators;
2
3 import java.util.HashMap;
4 import java.util.Map;
5
6 import nl.tudelft.goal.EIS2Java.exception.TranslationException;
7 import nl.tudelft.goal.EIS2Java.translation.Java2Parameter;
8 import nl.tudelft.goal.EIS2Java.translation.Parameter2Java;
9 import cz.cuni.amis.pogamut.unreal.communication.messages.UnrealId;
10 import eis.iilang.Identifier;
11 import eis.iilang.Parameter;
12
13 public class UnrealIdTranslator implements Java2Parameter<UnrealId>, Parameter2Java<UnrealId> {
14
15 protected Map<Identifier, UnrealId> translated = new HashMap<Identifier, UnrealId>();
16
17 @Override
18 public Parameter[] translate(UnrealId o) throws TranslationException {
19
20 Identifier id;
21
22
23 if (o.getStringId().equalsIgnoreCase("none")) {
24 id = new Identifier("none");
25 } else {
26 id = new Identifier(o.getStringId());
27 }
28
29 translated.put(id, o);
30 return new Parameter[] { id };
31 }
32
33 @Override
34 public Class<? extends UnrealId> translatesFrom() {
35 return UnrealId.class;
36 }
37
38 @Override
39 public UnrealId translate(Parameter parameter) throws TranslationException {
40 if (!translated.containsKey(parameter)) {
41 String message = String.format("The unrealId must be an id that has been translated before. Recieved %s",
42 parameter);
43 throw new TranslationException(message);
44 }
45
46 return translated.get(parameter);
47 }
48
49 @Override
50 public Class<UnrealId> translatesTo() {
51 return UnrealId.class;
52
53 }
54
55 }