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

Method parseTokenWithSeparator

code/src/java/plugin/lsttokens/KitLst.java:67–129  ·  view source on GitHub ↗
(LoadContext context, CDOMObject obj, String value)

Source from the content-addressed store, hash-verified

65 }
66
67 @Override
68 protected ParseResult parseTokenWithSeparator(LoadContext context, CDOMObject obj, String value)
69 {
70 if (obj instanceof Ungranted)
71 {
72 return new ParseResult.Fail(
73 "Cannot use " + getTokenName() + " on an Ungranted object type: " + obj.getClass().getSimpleName());
74 }
75 if (obj instanceof NonInteractive)
76 {
77 return new ParseResult.Fail("Cannot use " + getTokenName() + " on an Non-Interactive object type: "
78 + obj.getClass().getSimpleName());
79 }
80 StringTokenizer tok = new StringTokenizer(value, Constants.PIPE);
81 Formula count = FormulaFactory.getFormulaFor(tok.nextToken());
82 if (!count.isValid())
83 {
84 return new ParseResult.Fail("Count in " + getTokenName() + " was not valid: " + count.toString());
85 }
86 if (!count.isStatic())
87 {
88 return new ParseResult.Fail("Count in " + getTokenName() + " must be a number");
89 }
90 if (count.resolveStatic().intValue() <= 0)
91 {
92 return new ParseResult.Fail("Count in " + getTokenName() + " must be > 0");
93 }
94 if (!tok.hasMoreTokens())
95 {
96 return new ParseResult.Fail(
97 getTokenName() + " must have a | separating " + "count from the list of possible values: " + value);
98 }
99 List<CDOMReference<Kit>> refs = new ArrayList<>();
100
101 while (tok.hasMoreTokens())
102 {
103 String token = tok.nextToken();
104 CDOMReference<Kit> ref;
105 if (Constants.LST_ALL.equals(token))
106 {
107 ref = context.getReferenceContext().getCDOMAllReference(KIT_CLASS);
108 }
109 else
110 {
111 ref = context.getReferenceContext().getCDOMReference(KIT_CLASS, token);
112 }
113 refs.add(ref);
114 }
115
116 ReferenceChoiceSet<Kit> rcs = new ReferenceChoiceSet<>(refs);
117 if (!rcs.getGroupingState().isValid())
118 {
119 return new ParseResult.Fail(
120 "Non-sensical " + getTokenName() + ": Contains ANY and a specific reference: " + value);
121 }
122 ChoiceSet<Kit> cs = new ChoiceSet<>(getTokenName(), new QualifiedDecorator<>(rcs));
123 cs.setTitle("Kit Selection");
124 TransitionChoice<Kit> tc = new ConcreteTransitionChoice<>(cs, count);

Callers

nothing calls this directly

Calls 15

getTokenNameMethod · 0.95
getFormulaForMethod · 0.95
isValidMethod · 0.95
isStaticMethod · 0.95
resolveStaticMethod · 0.95
getGroupingStateMethod · 0.95
setTitleMethod · 0.95
setRequiredMethod · 0.95
setChoiceActorMethod · 0.95
getSimpleNameMethod · 0.80
nextTokenMethod · 0.80
intValueMethod · 0.80

Tested by

no test coverage detected