View Javadoc

1   /*
2    * Copyright 2006 Outsource Cafe, Inc.
3    *
4    * Licensed under the Apache License, Version 2.0 (the 'License')
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *    http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an 'AS IS' BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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  }