1
2
3
4
5 package pt.digitalis.dif.dem.objects.parameters.constraints.impl.numeric;
6
7 import java.text.DecimalFormat;
8 import java.util.HashMap;
9 import java.util.Map;
10
11 import pt.digitalis.dif.dem.interfaces.IStageInstance;
12
13
14
15
16
17
18
19 public class ParameterConstraintMaxImpl extends AbstractNumericParameterConstraint {
20
21
22 Double lastTestedValue;
23
24
25 Double maxValue;
26
27
28
29
30 public void configureConstraint(String configurationString)
31 {
32
33 String value = configurationString.substring(configurationString.indexOf("=") + 1);
34
35 maxValue = new Double(value.trim());
36 }
37
38
39
40
41 @Override
42 protected Map<String, String> getErrorMessageValues(boolean parseValues)
43 {
44 Map<String, String> substitutions = new HashMap<String, String>();
45
46 DecimalFormat df = new DecimalFormat("0");
47 if (parseValues)
48 {
49 substitutions.put("value", df.format(lastTestedValue));
50 }
51 substitutions.put("max", df.format(maxValue));
52
53 return substitutions;
54 }
55
56
57
58
59 public String getJavaScriptValidationCondition()
60 {
61 return "parseInt(value) <= " + maxValue;
62 }
63
64
65
66
67
68 @Override
69 public boolean validateConstraint(Double value, IStageInstance stageInstance)
70 {
71
72 lastTestedValue = value;
73
74 return (value != null && value <= maxValue);
75 }
76 }