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 java.util.HashMap;
23 import java.util.Map;
24
25 import nl.tudelft.goal.EIS2Java.exception.TranslationException;
26 import nl.tudelft.goal.EIS2Java.translation.Java2Parameter;
27 import nl.tudelft.goal.EIS2Java.translation.Parameter2Java;
28 import nl.tudelft.goal.EIS2Java.translation.Translator;
29 import cz.cuni.amis.pogamut.base.communication.worldview.object.WorldObjectId;
30 import cz.cuni.amis.pogamut.unreal.communication.messages.UnrealId;
31 import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.NavPoint;
32 import eis.iilang.Identifier;
33 import eis.iilang.Parameter;
34 import eis.iilang.ParameterList;
35
36 public class NavPointTranslator implements Parameter2Java<NavPoint>, Java2Parameter<NavPoint> {
37
38
39
40
41
42
43 protected Map<WorldObjectId, NavPoint> navPoints = new HashMap<WorldObjectId, NavPoint>();
44
45
46 @Override
47 public Parameter[] translate(NavPoint o) throws TranslationException {
48 navPoints.put(o.getId(), o);
49
50 ParameterList neightbours = new ParameterList();
51 for (UnrealId id : o.getOutgoingEdges().keySet()) {
52 neightbours.add(new Identifier(id.getStringId()));
53 }
54
55
56 return new Parameter[] { new Identifier(o.getId().getStringId()),
57 Translator.getInstance().translate2Parameter(o.getLocation())[0], neightbours };
58 }
59
60 @Override
61 public NavPoint translate(Parameter p) throws TranslationException {
62
63 UnrealId id = Translator.getInstance().translate2Java(p, UnrealId.class);
64
65 NavPoint navPoint = navPoints.get(id);
66
67 if (navPoint == null) {
68 String message = String
69 .format("The identifier must be the unrealID of a navpoint that has been translated once, received: %s.",
70 p);
71 throw new TranslationException(message);
72 }
73
74 return navPoint;
75 }
76
77 @Override
78 public Class<NavPoint> translatesFrom() {
79 return NavPoint.class;
80 }
81
82 @Override
83 public Class<NavPoint> translatesTo() {
84 return NavPoint.class;
85 }
86
87 }