2556e47c3fd1b4c90b7ddfdd197272de58669331
[fleet.git] / marina / testCode / edu / berkeley / fleet / api / Predicate.java
1 package edu.berkeley.fleet.api;
2
3 /** possible predicate field values */
4 public enum Predicate {
5     Default, FlagA, NotFlagA, FlagB, NotFlagB, FlagC, NotFlagC, IgnoreFlagD, FlagD;
6     public String toString() {
7         switch(this) {
8             case Default:    return "";
9             case FlagA:      return "a";
10             case FlagB:      return "b";
11             case FlagC:      return "c";
12             case NotFlagA:   return "!a";
13             case NotFlagB:   return "!b";
14             case NotFlagC:   return "!c";
15             case IgnoreFlagD:return "*";
16             case FlagD:      return "d";
17             default:         throw new Error("unknown predicate " + this);
18         }
19     }
20
21     /** evaluates this predicate for a given set of flags and olc */
22     public boolean evaluate(boolean flag_a, boolean flag_b, boolean flag_c, boolean flag_d) {
23         switch(this) {
24             case Default:    return !flag_d;
25             case FlagA:      return !flag_d && flag_a;
26             case FlagB:      return !flag_d && flag_b;
27             case FlagC:      return !flag_d && flag_c;
28             case NotFlagA:   return !flag_d && !flag_a;
29             case NotFlagB:   return !flag_d && !flag_b;
30             case NotFlagC:   return !flag_d && !flag_c;
31             case IgnoreFlagD:return true;
32             case FlagD:      return flag_d;
33             default:         throw new Error("unknown predicate " + this);
34         }
35     }
36
37 }