Introduce conditional task
authorMathieu Baudier <mbaudier@argeo.org>
Sun, 12 Feb 2012 17:40:43 +0000 (17:40 +0000)
committerMathieu Baudier <mbaudier@argeo.org>
Sun, 12 Feb 2012 17:40:43 +0000 (17:40 +0000)
git-svn-id: https://svn.argeo.org/slc/trunk@5055 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/tasks/If.java [new file with mode: 0644]

diff --git a/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/tasks/If.java b/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/tasks/If.java
new file mode 100644 (file)
index 0000000..e8ec936
--- /dev/null
@@ -0,0 +1,37 @@
+package org.argeo.slc.core.execution.tasks;
+
+import org.argeo.slc.SlcException;
+
+/** Conditional execution */
+public class If implements Runnable {
+       private Boolean bool;
+       private Runnable then;
+       private Runnable els;
+
+       public void run() {
+               if (bool == null)
+                       throw new SlcException("No condition set");
+
+               if (bool) {
+                       if (then != null)
+                               then.run();
+               } else {
+                       if (els != null)
+                               els.run();
+               }
+
+       }
+
+       public void setBool(Boolean bool) {
+               this.bool = bool;
+       }
+
+       public void setThen(Runnable then) {
+               this.then = then;
+       }
+
+       public void setEls(Runnable els) {
+               this.els = els;
+       }
+
+}