MCPcopy Create free account
hub / github.com/PCGen/pcgen / getToken

Method getToken

code/src/java/plugin/exporttokens/VisionToken.java:43–102  ·  view source on GitHub ↗
(String tokenSource, CharacterDisplay display, ExportHandler eh)

Source from the content-addressed store, hash-verified

41 }
42
43 @Override
44 public String getToken(String tokenSource, CharacterDisplay display, ExportHandler eh)
45 {
46 StringTokenizer aTok = new StringTokenizer(tokenSource, ".");
47 aTok.nextToken();
48
49 List<Vision> visionList = new ArrayList<>(display.getVisionList());
50
51 int visionIndex = 0;
52 int startIndex = 0;
53
54 if (aTok.hasMoreTokens())
55 {
56 try
57 {
58 startIndex = Integer.parseInt(aTok.nextToken());
59 visionIndex = startIndex + 1;
60 }
61 catch (NumberFormatException e)
62 {
63 //TODO: Should this really be ignored?
64 }
65 }
66 else
67 {
68 visionIndex = visionList.size();
69 }
70
71 if (visionList.isEmpty() || startIndex >= visionList.size())
72 {
73 return "";
74 }
75
76 List<Vision> subList = visionList.subList(Math.max(startIndex, 0), Math.min(visionIndex, visionList.size()));
77
78 StringBuilder result = new StringBuilder();
79 for (Vision vision : subList)
80 {
81 if (result.length() > 0)
82 {
83 result.append(", ");
84 }
85 result.append(vision.getType());
86 String distStr = vision.getDistance().toString();
87 int dist = 0;
88 if ((distStr != null) && (!distStr.trim().isEmpty()))
89 {
90 dist = Integer.parseInt(distStr);
91 }
92 if (dist > 0)
93 {
94 result.append(" (");
95 result.append(Globals.getGameModeUnitSet().displayDistanceInUnitSet(dist));
96 result.append(Globals.getGameModeUnitSet().getDistanceUnit());
97 result.append(')');
98 }
99 }
100

Callers

nothing calls this directly

Calls 15

getGameModeUnitSetMethod · 0.95
nextTokenMethod · 0.80
getVisionListMethod · 0.80
hasMoreTokensMethod · 0.80
parseIntMethod · 0.80
getDistanceMethod · 0.80
trimMethod · 0.80
getDistanceUnitMethod · 0.80
sizeMethod · 0.65
isEmptyMethod · 0.65
getTypeMethod · 0.65

Tested by

no test coverage detected