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