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

Method unparse

code/src/java/plugin/lsttokens/auto/EquipToken.java:162–237  ·  view source on GitHub ↗
(LoadContext context, CDOMObject obj)

Source from the content-addressed store, hash-verified

160 }
161
162 @Override
163 public String[] unparse(LoadContext context, CDOMObject obj)
164 {
165 List<String> list = new ArrayList<>();
166 PrerequisiteWriter prereqWriter = new PrerequisiteWriter();
167
168 Changes<ChooseSelectionActor<?>> listChanges =
169 context.getObjectContext().getListChanges(obj, ListKey.NEW_CHOOSE_ACTOR);
170 Changes<QualifiedObject<CDOMReference<Equipment>>> changes =
171 context.getObjectContext().getListChanges(obj, ListKey.EQUIPMENT);
172 Collection<QualifiedObject<CDOMReference<Equipment>>> added = changes.getAdded();
173 HashMapToList<List<Prerequisite>, CDOMReference<Equipment>> m = new HashMapToList<>();
174 if (added != null)
175 {
176 for (QualifiedObject<CDOMReference<Equipment>> qo : added)
177 {
178 m.addToListFor(qo.getPrerequisiteList(), qo.getRawObject());
179 }
180 }
181 Collection<ChooseSelectionActor<?>> listAdded = listChanges.getAdded();
182 if (listAdded != null && !listAdded.isEmpty())
183 {
184 for (ChooseSelectionActor<?> cra : listAdded)
185 {
186 if (cra.getSource().equals(getTokenName()))
187 {
188 try
189 {
190 list.add(cra.getLstFormat());
191 }
192 catch (PersistenceLayerException e)
193 {
194 context.addWriteMessage("Error writing Prerequisite: " + e);
195 return null;
196 }
197 }
198 }
199 }
200 for (List<Prerequisite> prereqs : m.getKeySet())
201 {
202 List<CDOMReference<Equipment>> eq = m.getListFor(prereqs);
203 WeightedCollection<CDOMReference<Equipment>> refs =
204 new WeightedCollection<>(ReferenceUtilities.REFERENCE_SORTER);
205 refs.addAll(eq);
206 String ab = ReferenceUtilities.joinLstFormat(refs, Constants.PIPE);
207 if (prereqs != null && !prereqs.isEmpty())
208 {
209 if (prereqs.size() > 1)
210 {
211 context.addWriteMessage("Error: " + obj.getClass().getSimpleName()
212 + " had more than one Prerequisite for " + getFullName());
213 return null;
214 }
215 Prerequisite p = prereqs.get(0);
216 StringWriter swriter = new StringWriter();
217 try
218 {
219 prereqWriter.write(swriter, p);

Callers

nothing calls this directly

Calls 15

getTokenNameMethod · 0.95
addAllMethod · 0.95
joinLstFormatMethod · 0.95
getFullNameMethod · 0.95
writeMethod · 0.95
getRawObjectMethod · 0.80
getSimpleNameMethod · 0.80
getListChangesMethod · 0.65
getObjectContextMethod · 0.65
getAddedMethod · 0.65
addToListForMethod · 0.65
getPrerequisiteListMethod · 0.65

Tested by

no test coverage detected