]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/OperationImpl.java
Cluster loading problem fix made by Antti
[simantics/platform.git] / bundles / org.simantics.db.procore / src / fi / vtt / simantics / procore / internal / OperationImpl.java
1 package fi.vtt.simantics.procore.internal;
2
3 import java.util.ArrayList;
4 import java.util.Collection;
5 import java.util.Collections;
6 import java.util.List;
7
8 import org.simantics.db.Operation;
9 import org.simantics.db.service.ExternalOperation;
10
11 public class OperationImpl implements Operation {
12     private final long id;
13     private final long csid;
14     private Operation combined;
15     private final List<ExternalOperation> externals;
16     OperationImpl(long id, long csid) {
17         this(id, csid, null);
18     }
19     OperationImpl(long id, long csid, List<ExternalOperation> externals) {
20         this.id = id;
21         this.csid = csid;
22         this.combined = null;
23         this.externals = externals.isEmpty() ? null : externals;
24     }
25     @Override
26     public String toString() {
27         return "Operation id=" + id + " cs=" + csid + ".";
28     }
29     @Override
30     public long getId() {
31         return id;
32     }
33
34     @Override
35     public long getCSId() {
36         return csid;
37     }
38
39     @Override
40     public void combine(Operation operation) {
41         combined = operation;
42     }
43
44     @Override
45     public List<Operation> getOperations() {
46         
47         if(combined == null) return Collections.<Operation>singletonList(this);
48
49         ArrayList<Operation> result = new ArrayList<Operation>();
50         OperationImpl current = this;
51         while(current != null) {
52                 result.add(current);
53                 current = (OperationImpl)(current.combined);
54         }
55         
56         Collections.reverse(result);
57         
58         return result;
59         
60     }
61     
62     @Override
63     public Collection<ExternalOperation> getExternalOperations() {
64         if(externals == null)
65                 return Collections.emptyList();
66         else
67                 return externals;
68     }
69     
70 }