1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.javagen.agile.core.emitter.logic;
17
18 import java.io.File;
19
20 import org.javagen.agile.core.context.Context;
21
22 /***
23 * Equals predicate compares one or more string constants to value abtained from
24 * context using <code>contextKey</code>. If any constant is a match return true.
25 *
26 * @author Richard Easterling
27 */
28 public class Equals implements Predicate {
29 String contextKey;
30 String[] values;
31 public Equals(String contextKey, String value) {
32 super();
33 this.contextKey = contextKey;
34 this.values = new String[] {value};
35 }
36 public Equals(String contextKey, String value1, String value2) {
37 super();
38 this.contextKey = contextKey;
39 this.values = new String[] {value1,value2};
40 }
41 public Equals(String contextKey, String value1, String value2, String value3) {
42 super();
43 this.contextKey = contextKey;
44 this.values = new String[] {value1,value2,value3};
45 }
46 public String getContextKey() {
47 return contextKey;
48 }
49 public String[] getValues() {
50 return values;
51 }
52 public boolean eval(File outputFile, Context context) {
53 Object keyValue = context.get(contextKey);
54 if (values!=null && keyValue!=null) {
55 for(String value : values)
56 if (keyValue.toString().equals(value))
57 return true;
58 }
59 return false;
60 }
61 }