MCPcopy Create free account
hub / github.com/OpenEndedGroup/Field2 / uniqify

Method uniqify

src/main/java/fieldbox/io/IO.java:156–185  ·  view source on GitHub ↗
(Box x)

Source from the content-addressed store, hash-verified

154 ArrayList<Dict.Prop> k = new ArrayList<>(x.properties.getMap()
155 .keySet());
156
157 List<Runnable> undo = new LinkedList<>();
158
159 for (Dict.Prop kk : k) {
160 if (kk.getName()
161 .startsWith("__filename__") || kk.getName()
162 .startsWith("__datafilename__")) {
163 Object was = x.properties.remove(kk);
164 undo.add(() -> {
165 x.properties.put(kk, was);
166 });
167 }
168 }
169
170 if (x.properties.has(IO.id)) {
171 String was = x.properties.remove(IO.id);
172 undo.add(() -> {
173 x.properties.put(IO.id, was);
174 });
175 x.properties.put(IO.id, Box.newID());
176 } else
177 x.properties.put(IO.id, Box.newID());
178
179 return () -> {
180 for (Runnable u : undo) u.run();
181 };
182 }
183
184
185 public static boolean uniqifyIfNecessary(Box root, Box x) {
186
187 String id = x.properties.computeIfAbsent(IO.id, k -> Box.newID());
188

Callers 11

saveAsNewFileMethod · 0.95
RenameMethod · 0.95
runMethod · 0.95
FileBrowserMethod · 0.95
copyFromFileCalledMethod · 0.95
insertFromFileCalledMethod · 0.95
duplicateGroupMethod · 0.95
saveAsTemplateMethod · 0.95
loadBoxMethod · 0.95
dropMethod · 0.95
loadBoxesMethod · 0.95

Calls 8

newIDMethod · 0.95
getMapMethod · 0.80
getNameMethod · 0.45
removeMethod · 0.45
addMethod · 0.45
putMethod · 0.45
hasMethod · 0.45
runMethod · 0.45

Tested by

no test coverage detected