Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
ParameterConstraintMaxImpl |
|
| 1.5;1,5 |
1 | 0 | /** |
2 | * 2007, Digitalis Informatica. All rights reserved. Distribuicao e Gestao de Informatica, Lda. Estrada de Paco de Arcos | |
3 | * num.9 - Piso -1 2780-666 Paco de Arcos Telefone: (351) 21 4408990 Fax: (351) 21 4408999 http://www.digitalis.pt | |
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 | * Max parameter constraint implementation | |
15 | * | |
16 | * @author Pedro Viegas <a href="mailto:pviegas@digitalis.pt">pviegas@digitalis.pt</a> | |
17 | * @created Nov 16, 2007 | |
18 | */ | |
19 | 0 | public class ParameterConstraintMaxImpl extends AbstractNumericParameterConstraint { |
20 | ||
21 | /** Last tested value */ | |
22 | Double lastTestedValue; | |
23 | ||
24 | /** Max value to compare to */ | |
25 | Double maxValue; | |
26 | ||
27 | /** | |
28 | * @see pt.digitalis.dif.dem.objects.parameters.constraints.IParameterConstraint#configureConstraint(java.lang.String) | |
29 | */ | |
30 | public void configureConstraint(String configurationString) | |
31 | { | |
32 | ||
33 | 0 | String value = configurationString.substring(configurationString.indexOf("=") + 1); |
34 | ||
35 | 0 | maxValue = new Double(value.trim()); |
36 | 0 | } |
37 | ||
38 | /** | |
39 | * @see pt.digitalis.dif.dem.objects.parameters.constraints.AbstractParameterConstraint#getErrorMessageValues(boolean) | |
40 | */ | |
41 | @Override | |
42 | protected Map<String, String> getErrorMessageValues(boolean parseValues) | |
43 | { | |
44 | 0 | Map<String, String> substitutions = new HashMap<String, String>(); |
45 | ||
46 | 0 | DecimalFormat df = new DecimalFormat("0"); |
47 | 0 | if (parseValues) |
48 | { | |
49 | 0 | substitutions.put("value", df.format(lastTestedValue)); |
50 | } | |
51 | 0 | substitutions.put("max", df.format(maxValue)); |
52 | ||
53 | 0 | return substitutions; |
54 | } | |
55 | ||
56 | /** | |
57 | * @see pt.digitalis.dif.dem.objects.parameters.constraints.IParameterConstraint#getJavaScriptValidationCondition() | |
58 | */ | |
59 | public String getJavaScriptValidationCondition() | |
60 | { | |
61 | 0 | return "parseInt(value) <= " + maxValue; |
62 | } | |
63 | ||
64 | /** | |
65 | * @see pt.digitalis.dif.dem.objects.parameters.constraints.impl.numeric.AbstractNumericParameterConstraint#validateConstraint(java.lang.Double, | |
66 | * pt.digitalis.dif.dem.interfaces.IStageInstance) | |
67 | */ | |
68 | @Override | |
69 | public boolean validateConstraint(Double value, IStageInstance stageInstance) | |
70 | { | |
71 | ||
72 | 0 | lastTestedValue = value; |
73 | ||
74 | 0 | return (value != null && value <= maxValue); |
75 | } | |
76 | } |