]> git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/tasks/If.java
Remove unnecessary check causing failures
[gpl/argeo-slc.git] / runtime / org.argeo.slc.core / src / main / java / org / argeo / slc / core / execution / tasks / If.java
1 /*
2 * Copyright (C) 2007-2012 Argeo GmbH
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package org.argeo.slc.core.execution.tasks;
17
18 import org.argeo.slc.SlcException;
19
20 /** Conditional execution */
21 public class If implements Runnable {
22 private Boolean is;
23 private Boolean not;
24 private Runnable then;
25 private Runnable els;
26
27 public void run() {
28 if (is == null && not == null)
29 throw new SlcException("No condition set");
30 if (is != null && not != null)
31 throw new SlcException("Both is and not cannot be set");
32
33 boolean bool = (is != null ? is : !not);
34 if (bool) {
35 if (then != null)
36 then.run();
37 } else {
38 if (els != null)
39 els.run();
40 }
41
42 }
43
44 public void setIs(Boolean bool) {
45 this.is = bool;
46 }
47
48 public void setThen(Runnable then) {
49 this.then = then;
50 }
51
52 public void setEls(Runnable els) {
53 this.els = els;
54 }
55
56 public Boolean getNot() {
57 return not;
58 }
59
60 public void setNot(Boolean not) {
61 this.not = not;
62 }
63
64 }