--- /dev/null
+package fi.vtt.simantics.procore.internal;\r
+\r
+import java.util.ArrayList;\r
+import java.util.Collection;\r
+import java.util.Collections;\r
+import java.util.List;\r
+\r
+import org.simantics.db.Operation;\r
+import org.simantics.db.service.ExternalOperation;\r
+\r
+public class OperationImpl implements Operation {\r
+ private final long id;\r
+ private final long csid;\r
+ private Operation combined;\r
+ private final List<ExternalOperation> externals;\r
+ OperationImpl(long id, long csid) {\r
+ this(id, csid, null);\r
+ }\r
+ OperationImpl(long id, long csid, List<ExternalOperation> externals) {\r
+ this.id = id;\r
+ this.csid = csid;\r
+ this.combined = null;\r
+ this.externals = externals.isEmpty() ? null : externals;\r
+ }\r
+ @Override\r
+ public String toString() {\r
+ return "Operation id=" + id + " cs=" + csid + ".";\r
+ }\r
+ @Override\r
+ public long getId() {\r
+ return id;\r
+ }\r
+\r
+ @Override\r
+ public long getCSId() {\r
+ return csid;\r
+ }\r
+\r
+ @Override\r
+ public void combine(Operation operation) {\r
+ combined = operation;\r
+ }\r
+\r
+ @Override\r
+ public List<Operation> getOperations() {\r
+ \r
+ if(combined == null) return Collections.<Operation>singletonList(this);\r
+\r
+ ArrayList<Operation> result = new ArrayList<Operation>();\r
+ OperationImpl current = this;\r
+ while(current != null) {\r
+ result.add(current);\r
+ current = (OperationImpl)(current.combined);\r
+ }\r
+ \r
+ Collections.reverse(result);\r
+ \r
+ return result;\r
+ \r
+ }\r
+ \r
+ @Override\r
+ public Collection<ExternalOperation> getExternalOperations() {\r
+ if(externals == null)\r
+ return Collections.emptyList();\r
+ else\r
+ return externals;\r
+ }\r
+ \r
+}\r