View Javadoc

1   /**
2    * .
3    */
4   package com.github.mkolisnyk.aerial.expressions.value;
5   
6   import java.util.ArrayList;
7   import java.util.List;
8   
9   import org.apache.commons.lang.StringUtils;
10  
11  import com.github.mkolisnyk.aerial.document.InputRecord;
12  import com.github.mkolisnyk.aerial.expressions.ValueExpression;
13  import com.github.mkolisnyk.aerial.expressions.ValueExpressionType;
14  
15  /**
16   * @author Myk Kolisnyk
17   *
18   */
19  public class EnumValueExpression extends ValueExpression {
20  
21      private List<String> values;
22  
23      /**
24       * @param inputValue
25       */
26      public EnumValueExpression(InputRecord inputValue) {
27          super(inputValue);
28          parse();
29      }
30  
31      private void parse() {
32          values = new ArrayList<String>();
33          for (String value : this.getInput().getValue().trim().split("(?<!\\\\);")) {
34              if (!value.trim().equals("")) {
35                  values.add(value.trim());
36              }
37          }
38      }
39  
40      /* (non-Javadoc)
41       * @see com.github.mkolisnyk.aerial.expressions.ValueExpression#generate()
42       */
43      @Override
44      public List<InputRecord> generate() throws Exception {
45          List<InputRecord> result = new ArrayList<InputRecord>();
46          InputRecord testRecord = (InputRecord) this.getInput().clone();
47          this.validate();
48          for (String value : values) {
49              result.add(
50                      new InputRecord(
51                              testRecord.getName(),
52                              testRecord.getType(),
53                              value.replaceAll("\\\\;", ";"),
54                              testRecord.getCondition(),
55                              true));
56          }
57          String negativeValue = "";
58          for (String value : values) {
59              negativeValue = StringUtils.reverse(negativeValue.concat(value.replaceAll("\\\\;", ";")));
60              if (!values.contains(negativeValue)) {
61                  result.add(
62                      new InputRecord(
63                              testRecord.getName(),
64                              testRecord.getType(),
65                              negativeValue,
66                              testRecord.getCondition(),
67                              false));
68                  break;
69              }
70          }
71          return result;
72      }
73  
74      /* (non-Javadoc)
75       * @see com.github.mkolisnyk.aerial.expressions.ValueExpression#getValueType()
76       */
77      @Override
78      public ValueExpressionType getValueType() {
79          return ValueExpressionType.ENUM;
80      }
81  }