]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.graph.compiler/src/org/simantics/graph/compiler/internal/procedures/PropagateNewMarks.java
c9235361bae0bdb7000d2eb8a66e28d490daee26
[simantics/platform.git] / bundles / org.simantics.graph.compiler / src / org / simantics / graph / compiler / internal / procedures / PropagateNewMarks.java
1 package org.simantics.graph.compiler.internal.procedures;
2
3 import org.simantics.graph.store.GraphStore;
4 import org.simantics.graph.store.IdentityStore;
5
6 public class PropagateNewMarks implements Runnable {
7         IdentityStore identities;
8
9         public PropagateNewMarks(GraphStore store) {
10                 this.identities = store.identities;
11         }
12
13         private void propagateNewMarks(int resource) {
14                 for(int child : identities.getChildren(resource))
15                         if(identities.markNew(child))
16                                 propagateNewMarks(child);
17         }
18
19         /**
20          * Mark all parents of resources marked new as optional provisionally. This mark is removed
21          * in ValidateGraph.run, if the resource can be found in dependencies.
22          */
23         private void propagateOptionalMarks(int child) {
24                 int parent = identities.getParent(child);
25                 if(parent >= 0 && !identities.isRoot(parent) && !identities.isNewResource(parent) && identities.markOptional(parent))
26                         propagateOptionalMarks(parent);
27         }
28
29         @Override
30         public void run() {
31                 int[] originalNewResources = identities.getNewResources();
32                 for(int resource : originalNewResources)
33                         propagateNewMarks(resource);
34                 for(int resource : originalNewResources)
35                         propagateOptionalMarks(resource);
36         }
37 }