some small changes delting unneeded imports. two new exceptions in mir.storage. usage...
[mir.git] / source / mir / util / GeneratorIntegerFunctions.java
1 package mir.util;
2
3 import java.util.List;
4
5 import mir.generator.Generator;
6 import mir.generator.GeneratorExc;
7 import mir.generator.GeneratorFailure;
8
9 public class GeneratorIntegerFunctions {
10
11   private GeneratorIntegerFunctions() {}
12
13   public static class incrementFunction implements Generator.GeneratorFunction {
14     public Object perform(List aParameters) throws GeneratorExc, GeneratorFailure {
15       int incrementValue = 1;
16
17       try {
18         if (aParameters.size()>2 || aParameters.size()<1)
19           throw new GeneratorExc("incrementFunction: 1 or 2 parameters expected: value [increment value]");
20
21         if (aParameters.size()>1)
22           incrementValue = StringRoutines.interpretAsInteger(aParameters.get(1));
23
24         return new Integer(StringRoutines.interpretAsInteger(aParameters.get(0)) + incrementValue);
25       }
26       catch (GeneratorExc e) {
27         throw e;
28       }
29       catch (Throwable t) {
30         throw new GeneratorFailure("incrementFunction: " + t.getMessage(), t);
31       }
32     };
33   }
34
35   public static class isOddFunction implements Generator.GeneratorFunction {
36     public Object perform(List aParameters) throws GeneratorExc, GeneratorFailure {
37       try {
38         if (aParameters.size()!=1)
39           throw new GeneratorExc("isOddFunction: 1 parameters expected: value");
40
41         return new Boolean((StringRoutines.interpretAsInteger(aParameters.get(0)) & 1) == 1);
42       }
43       catch (GeneratorExc e) {
44         throw e;
45       }
46       catch (Throwable t) {
47         throw new GeneratorFailure("isOddFunction: " + t.getMessage(), t);
48       }
49     };
50   }
51 }