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

Method unparse

code/src/java/plugin/lsttokens/ServesAsToken.java:121–150  ·  view source on GitHub ↗
(LoadContext context, CDOMObject obj)

Source from the content-addressed store, hash-verified

119 }
120
121 @Override
122 public String[] unparse(LoadContext context, CDOMObject obj)
123 {
124 String key = StringPClassUtil.getStringFor(obj.getClass());
125 ListKey<CDOMReference> listkey = ListKey.getKeyFor(CDOMReference.class, "SERVES_AS_" + key);
126 Changes<CDOMReference> changes = context.getObjectContext().getListChanges(obj, listkey);
127 Collection<CDOMReference> removedItems = changes.getRemoved();
128 if (removedItems != null && !removedItems.isEmpty() || changes.includesGlobalClear())
129 {
130 context.addWriteMessage(getTokenName() + " does not support .CLEAR");
131 return null;
132 }
133 if (!changes.hasAddedItems())
134 {
135 // Zero indicates no Token (and no global clear, so nothing to do)
136 return null;
137 }
138 TreeMapToList<String, String> map = new TreeMapToList<>();
139 for (CDOMReference<?> ref : changes.getAdded())
140 {
141 map.addToListFor(ref.getPersistentFormat(), ref.getLSTformat(false));
142 }
143 List<String> returnList = new ArrayList<>();
144 for (String mapKey : map.getKeySet())
145 {
146 Set<String> set = new TreeSet<>(map.getListFor(mapKey));
147 returnList.add(mapKey + '|' + StringUtil.join(set, Constants.PIPE));
148 }
149 return returnList.toArray(new String[0]);
150 }
151
152 @Override
153 public Class<CDOMObject> getTokenClass()

Callers

nothing calls this directly

Calls 15

getStringForMethod · 0.95
getKeyForMethod · 0.95
getTokenNameMethod · 0.95
joinMethod · 0.95
getListChangesMethod · 0.65
getObjectContextMethod · 0.65
getRemovedMethod · 0.65
isEmptyMethod · 0.65
includesGlobalClearMethod · 0.65
addWriteMessageMethod · 0.65
hasAddedItemsMethod · 0.65
getAddedMethod · 0.65

Tested by

no test coverage detected