actions
[jcryptoboard.git] / jcryptoboard-crypto / src / main / java / jcryptoboard / actions / generator / IntegerGenerator.java
blob6b21048af3a8d95980ebe6063c1232fc117698bf
1 package jcryptoboard.actions.generator;
3 import jcryptoboard.api.model.AbstractAction;
4 import jcryptoboard.api.model.ActionResult;
5 import org.apache.commons.lang.mutable.MutableInt;
7 public class IntegerGenerator extends AbstractAction {
10 public static final int DEFUALT_START = 0;
11 public static final int DEFUALT_END = 100;
12 public static final int DEFUALT_STEP = 1;
14 protected MutableInt start = new MutableInt(DEFUALT_START);
15 protected MutableInt end = new MutableInt(DEFUALT_END);
16 protected MutableInt step = new MutableInt(DEFUALT_STEP);
18 protected MutableInt value = new MutableInt(DEFUALT_START);
20 public ActionResult execute() throws Exception {
22 final int startVal = start.intValue();
23 final int endVal = end.intValue();
24 final int stepVal = step.intValue();
26 if (stepVal > 0) {
27 while (value.intValue() < endVal) {
28 ActionResult ar = nextAction.execute();
29 if (ar != ActionResult.OK) {
30 return ar;
32 value.add(stepVal);
35 else if (stepVal < 0) {
36 while (value.intValue() > endVal) {
37 ActionResult ar = nextAction.execute();
38 if (ar != ActionResult.OK) {
39 return ar;
41 value.add(stepVal);
44 return ActionResult.OK;