]> gerrit.simantics Code Review - simantics/interop.git/commitdiff
Getters for specific class UpdateOps 64/3764/1
authorMarko Luukkainen <marko.luukkainen@semantum.fi>
Thu, 9 Jan 2020 11:53:22 +0000 (13:53 +0200)
committerMarko Luukkainen <marko.luukkainen@semantum.fi>
Thu, 9 Jan 2020 11:53:22 +0000 (13:53 +0200)
gitlab #20

Change-Id: Ic40fd6d18dca5839fa179083bbb754de1869aac9

org.simantics.interop.update/src/org/simantics/interop/update/model/UpdateOp.java

index 50954ec1ffca968cc3e06a6dfbd1b09a59e4765e..3b633c28cdfd5a017995ff7e2c1a364b9cc4d22f 100644 (file)
@@ -2,6 +2,7 @@ package  org.simantics.interop.update.model;
 
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.List;
 
 import org.simantics.db.Resource;
 import org.simantics.db.Statement;
@@ -37,10 +38,26 @@ public abstract class UpdateOp {
                return parentOps;
        }
        
+       public <T extends UpdateOp> Collection<T> getParentOpsWithClass(Class<T> cls) {
+               List<T> ops = new ArrayList<T>(parentOps.size());
+               for (UpdateOp op : parentOps)
+                       if (cls.isAssignableFrom(op.getClass()))
+                               ops.add((T)op);
+               return ops;
+       }
+       
        public Collection<UpdateOp> getSubOps() {
                return subOps;
        }
        
+       public <T extends UpdateOp> Collection<T> getSubOpsWithClass(Class<T> cls) {
+               List<T> ops = new ArrayList<T>(subOps.size());
+               for (UpdateOp op : subOps)
+                       if (cls.isAssignableFrom(op.getClass()))
+                               ops.add((T)op);
+               return ops;
+       }
+       
        public void addParentOp(UpdateOp op) {
                assert (!op.equals(this));
                parentOps.add(op);