X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=org.argeo.slc.runtime%2Fsrc%2Forg%2Fargeo%2Fslc%2Fruntime%2Ftasks%2FIf.java;fp=org.argeo.slc.runtime%2Fsrc%2Forg%2Fargeo%2Fslc%2Fruntime%2Ftasks%2FIf.java;h=08eb804ccb1554dc79a05350c79f7a810f1a2651;hb=6fc94d69efe089414ac9e63bde3efab1cbf7b7ca;hp=0000000000000000000000000000000000000000;hpb=b36c62642bd0db11b3133b369cc026fd4b7a1ec6;p=gpl%2Fargeo-slc.git diff --git a/org.argeo.slc.runtime/src/org/argeo/slc/runtime/tasks/If.java b/org.argeo.slc.runtime/src/org/argeo/slc/runtime/tasks/If.java new file mode 100644 index 000000000..08eb804cc --- /dev/null +++ b/org.argeo.slc.runtime/src/org/argeo/slc/runtime/tasks/If.java @@ -0,0 +1,49 @@ +package org.argeo.slc.runtime.tasks; + +import org.argeo.slc.SlcException; + +/** Conditional execution */ +public class If implements Runnable { + private Boolean is; + private Boolean not; + private Runnable then; + private Runnable els; + + public void run() { + if (is == null && not == null) + throw new SlcException("No condition set"); + if (is != null && not != null) + throw new SlcException("Both is and not cannot be set"); + + boolean bool = (is != null ? is : !not); + if (bool) { + if (then != null) + then.run(); + } else { + if (els != null) + els.run(); + } + + } + + public void setIs(Boolean bool) { + this.is = bool; + } + + public void setThen(Runnable then) { + this.then = then; + } + + public void setEls(Runnable els) { + this.els = els; + } + + public Boolean getNot() { + return not; + } + + public void setNot(Boolean not) { + this.not = not; + } + +}