Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
ParameterConstraintNumericImpl |
|
| 2.4;2,4 |
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.util.HashMap; | |
8 | import java.util.Map; | |
9 | ||
10 | import pt.digitalis.dif.dem.interfaces.IStageInstance; | |
11 | ||
12 | /** | |
13 | * Numeric parameter constraint implementation | |
14 | * | |
15 | * @author Pedro Viegas <a href="mailto:pviegas@digitalis.pt">pviegas@digitalis.pt</a> | |
16 | * @created Nov 16, 2007 | |
17 | */ | |
18 | 0 | public class ParameterConstraintNumericImpl extends AbstractNumericParameterConstraint { |
19 | ||
20 | /** Last tested value */ | |
21 | String lastTestedValue; | |
22 | ||
23 | /** | |
24 | * @see pt.digitalis.dif.dem.objects.parameters.constraints.IParameterConstraint#configureConstraint(java.lang.String) | |
25 | */ | |
26 | public void configureConstraint(String configurationString) | |
27 | { | |
28 | // Nothing to do. No parameters to parse. | |
29 | 0 | } |
30 | ||
31 | /** | |
32 | * @see pt.digitalis.dif.dem.objects.parameters.constraints.AbstractParameterConstraint#getErrorMessageValues(boolean) | |
33 | */ | |
34 | @Override | |
35 | protected Map<String, String> getErrorMessageValues(boolean parseValues) | |
36 | { | |
37 | 0 | Map<String, String> substitutions = new HashMap<String, String>(); |
38 | ||
39 | 0 | if (parseValues) |
40 | { | |
41 | 0 | substitutions.put("value", lastTestedValue); |
42 | } | |
43 | ||
44 | 0 | return substitutions; |
45 | } | |
46 | ||
47 | /** | |
48 | * @see pt.digitalis.dif.dem.objects.parameters.constraints.IParameterConstraint#getJavaScriptValidationCondition() | |
49 | */ | |
50 | public String getJavaScriptValidationCondition() | |
51 | { | |
52 | 0 | return "Ext.isNumeric(value)"; |
53 | } | |
54 | ||
55 | /** | |
56 | * @see pt.digitalis.dif.dem.objects.parameters.constraints.impl.numeric.AbstractNumericParameterConstraint#validateConstraint(java.lang.Double, | |
57 | * pt.digitalis.dif.dem.interfaces.IStageInstance) | |
58 | */ | |
59 | @Override | |
60 | public boolean validateConstraint(Double value, IStageInstance stageInstance) | |
61 | { | |
62 | // If it's a boolean it's already validated. Only have to implement this because of the BaseNumericImpl. It will | |
63 | // never be called. | |
64 | 0 | return true; |
65 | } | |
66 | ||
67 | /** | |
68 | * @see pt.digitalis.dif.dem.objects.parameters.constraints.impl.numeric.AbstractNumericParameterConstraint#validateConstraint(java.lang.String, | |
69 | * pt.digitalis.dif.dem.interfaces.IStageInstance) | |
70 | */ | |
71 | @Override | |
72 | public boolean validateConstraint(String value, IStageInstance stageInstance) | |
73 | { | |
74 | ||
75 | 0 | lastTestedValue = value; |
76 | ||
77 | 0 | if (value == null || "".equals(value) || "undefined".equals(value)) |
78 | 0 | return true; |
79 | else | |
80 | try | |
81 | { | |
82 | 0 | value = value.replace(',', '.'); |
83 | ||
84 | 0 | Double.valueOf(value); |
85 | ||
86 | 0 | return true; |
87 | ||
88 | } | |
89 | 0 | catch (NumberFormatException e) |
90 | { | |
91 | 0 | return false; |
92 | } | |
93 | } | |
94 | } |