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

Class StringToken

code/src/java/plugin/lsttokens/choose/StringToken.java:43–205  ·  view source on GitHub ↗

New chooser plugin, handles Strings.

Source from the content-addressed store, hash-verified

41 * New chooser plugin, handles Strings.
42 */
43public class StringToken implements CDOMSecondaryToken<CDOMObject>, Chooser<String>
44{
45
46 @Override
47 public String getTokenName()
48 {
49 return "STRING";
50 }
51
52 @Override
53 public String getParentToken()
54 {
55 return "CHOOSE";
56 }
57
58 @Override
59 public ParseResult parseToken(LoadContext context, CDOMObject obj, String value)
60 {
61 if (value == null || value.isEmpty())
62 {
63 return new ParseResult.Fail("CHOOSE:" + getTokenName() + " must have arguments");
64 }
65 if (value.indexOf(',') != -1)
66 {
67 return new ParseResult.Fail("CHOOSE:" + getTokenName() + " arguments may not contain , : " + value);
68 }
69 if (value.indexOf('[') != -1)
70 {
71 return new ParseResult.Fail("CHOOSE:" + getTokenName() + " arguments may not contain [] : " + value);
72 }
73 if (value.charAt(0) == '|')
74 {
75 return new ParseResult.Fail("CHOOSE:" + getTokenName() + " arguments may not start with | : " + value);
76 }
77 if (value.charAt(value.length() - 1) == '|')
78 {
79 return new ParseResult.Fail("CHOOSE:" + getTokenName() + " arguments may not end with | : " + value);
80 }
81 if (value.contains("||"))
82 {
83 return new ParseResult.Fail("CHOOSE:" + getTokenName() + " arguments uses double separator || : " + value);
84 }
85
86 StringTokenizer tok = new StringTokenizer(value, Constants.PIPE);
87 Set<String> set = new HashSet<>();
88 while (tok.hasMoreTokens())
89 {
90 String tokString = tok.nextToken();
91 set.add(tokString);
92 }
93 SimpleChoiceSet<String> scs = new SimpleChoiceSet<>(set, Constants.PIPE);
94 BasicChooseInformation<String> tc = new BasicChooseInformation<>(getTokenName(), scs, "STRING");
95 tc.setTitle("Choose an Item");
96 tc.setChoiceActor(this);
97 context.getObjectContext().put(obj, ObjectKey.CHOOSE_INFO, tc);
98 return ParseResult.SUCCESS;
99 }
100

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected