Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
AbstractNumericParameterConstraint |
|
| 1.3333333333333333;1,333 | ||||
AbstractNumericParameterConstraint$1 |
|
| 1.3333333333333333;1,333 |
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.ArrayList; | |
8 | import java.util.List; | |
9 | ||
10 | import pt.digitalis.dif.dem.interfaces.IStageInstance; | |
11 | import pt.digitalis.dif.dem.objects.parameters.constraints.AbstractParameterConstraint; | |
12 | ||
13 | /** | |
14 | * Base implementation for numeric parameter constraints | |
15 | * | |
16 | * @author Pedro Viegas <a href="mailto:pviegas@digitalis.pt">pviegas@digitalis.pt</a> | |
17 | * @created Nov 16, 2007 | |
18 | */ | |
19 | 0 | public abstract class AbstractNumericParameterConstraint extends AbstractParameterConstraint { |
20 | ||
21 | /** Supported classes by numeric constraints */ | |
22 | @SuppressWarnings("serial") | |
23 | 0 | final static private List<String> supportedClasses = new ArrayList<String>() { |
24 | ||
25 | { | |
26 | 0 | add(Byte.class.getCanonicalName()); |
27 | 0 | add(Integer.class.getCanonicalName()); |
28 | 0 | add(Long.class.getCanonicalName()); |
29 | 0 | add(Double.class.getCanonicalName()); |
30 | ||
31 | 0 | add(byte.class.getCanonicalName()); |
32 | 0 | add(int.class.getCanonicalName()); |
33 | 0 | add(long.class.getCanonicalName()); |
34 | 0 | add(double.class.getCanonicalName()); |
35 | } | |
36 | }; | |
37 | ||
38 | /** | |
39 | * @see pt.digitalis.dif.dem.objects.parameters.constraints.IParameterConstraint#isSupportedClass(java.lang.Class) | |
40 | */ | |
41 | public boolean isSupportedClass(Class<?> clazz) | |
42 | { | |
43 | 0 | return supportedClasses.contains(clazz.getCanonicalName()); |
44 | } | |
45 | ||
46 | /** | |
47 | * Validate method with the value converted to a Double | |
48 | * | |
49 | * @param value | |
50 | * the value to compare | |
51 | * @param stageInstance | |
52 | * the current stage in execution | |
53 | * @return T if the constraint is valid | |
54 | */ | |
55 | abstract public boolean validateConstraint(Double value, IStageInstance stageInstance); | |
56 | ||
57 | /** | |
58 | * @see pt.digitalis.dif.dem.objects.parameters.constraints.IParameterConstraint#validateConstraint(java.lang.String, | |
59 | * pt.digitalis.dif.dem.interfaces.IStageInstance) | |
60 | */ | |
61 | public boolean validateConstraint(String value, IStageInstance stageInstance) | |
62 | { | |
63 | ||
64 | 0 | return (value == null || validateConstraint(new Double(value), stageInstance)); |
65 | } | |
66 | } |