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.junit.Assert;
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
17
18
19 public class SingleNumericValueExpression extends ValueExpression {
20
21
22
23
24 public SingleNumericValueExpression(InputRecord inputValue) {
25 super(inputValue);
26 }
27
28
29
30
31 @Override
32 public List<InputRecord> generate() throws Exception {
33 List<InputRecord> result = new ArrayList<InputRecord>();
34 InputRecord testRecord = (InputRecord) this.getInput().clone();
35 this.validate();
36
37 result.add(testRecord);
38 result.add(nonCurrentValue(this.getInput()));
39 return result;
40 }
41
42 private InputRecord nonCurrentValue(InputRecord input) {
43 InputRecord testRecord;
44 Integer intValue = new Integer(input.getValue());
45 String updatedValue = "";
46 if (intValue == 0) {
47 updatedValue = "-1";
48 } else {
49 updatedValue = "0";
50 }
51 testRecord = new InputRecord(
52 input.getName(),
53 input.getType(),
54 updatedValue,
55 input.getCondition(),
56 false);
57 return testRecord;
58 }
59
60
61
62
63 @Override
64 public ValueExpressionType getValueType() {
65 return ValueExpressionType.INTEGER;
66 }
67
68
69
70
71 @Override
72 public String getMatchPattern() {
73 return "(([-0-9])(\\d*))";
74 }
75
76
77
78
79 @Override
80 public void validate() throws Exception {
81 super.validate();
82 Assert.assertFalse("Unique attribute isn't applicable for fixed value",
83 this.getInput().isUnique());
84 }
85 }