Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
FixedPointPatternConstraint |
|
| 1.25;1.25 |
1 | /* | |
2 | * Copyright 2011 The Kuali Foundation | |
3 | * | |
4 | * Licensed under the Educational Community License, Version 2.0 (the "License"); | |
5 | * you may not use this file except in compliance with the License. | |
6 | * You may obtain a copy of the License at | |
7 | * | |
8 | * http://www.opensource.org/licenses/ecl1.php | |
9 | * | |
10 | * Unless required by applicable law or agreed to in writing, software | |
11 | * distributed under the License is distributed on an "AS IS" BASIS, | |
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | * See the License for the specific language governing permissions and | |
14 | * limitations under the License. | |
15 | */ | |
16 | package org.kuali.rice.krad.datadictionary.validation.constraint; | |
17 | ||
18 | /** | |
19 | * TODO delyea don't forget to fill this in. | |
20 | * | |
21 | * @author Kuali Rice Team (rice.collab@kuali.org) | |
22 | */ | |
23 | 0 | public class FixedPointPatternConstraint extends ValidDataPatternConstraint { |
24 | ||
25 | protected boolean allowNegative; | |
26 | protected int precision; | |
27 | protected int scale; | |
28 | ||
29 | /** | |
30 | * Overriding retrieval of | |
31 | * | |
32 | * @see org.kuali.rice.krad.datadictionary.validation.constraint.ValidCharactersPatternConstraint#getRegexString() | |
33 | */ | |
34 | @Override | |
35 | protected String getRegexString() { | |
36 | 0 | StringBuilder regex = new StringBuilder(); |
37 | ||
38 | 0 | if (isAllowNegative()) { |
39 | 0 | regex.append("-?"); |
40 | } | |
41 | // final patter will be: -?([0-9]{0,p-s}\.[0-9]{1,s}|[0-9]{1,p-s}) where p = precision, s=scale | |
42 | 0 | regex.append("("); |
43 | 0 | regex.append("[0-9]{0," + (getPrecision() - getScale()) + "}"); |
44 | 0 | regex.append("\\."); |
45 | 0 | regex.append("[0-9]{1," + getScale() + "}"); |
46 | 0 | regex.append("|[0-9]{1," + (getPrecision() - getScale()) + "}"); |
47 | 0 | regex.append(")"); |
48 | 0 | return regex.toString(); |
49 | } | |
50 | ||
51 | /** | |
52 | * @see org.kuali.rice.krad.datadictionary.validation.constraint.BaseConstraint#getLabelKey() | |
53 | */ | |
54 | @Override | |
55 | public String getLabelKey() { | |
56 | 0 | StringBuffer buf = new StringBuffer("validation.format." + getPatternTypeKey()); |
57 | 0 | if (isAllowNegative()) { |
58 | 0 | buf.append(".allowNegative"); |
59 | } | |
60 | 0 | return buf.toString(); |
61 | } | |
62 | ||
63 | /** | |
64 | * @return the allowNegative | |
65 | */ | |
66 | public boolean isAllowNegative() { | |
67 | 0 | return this.allowNegative; |
68 | } | |
69 | ||
70 | /** | |
71 | * @param allowNegative the allowNegative to set | |
72 | */ | |
73 | public void setAllowNegative(boolean allowNegative) { | |
74 | 0 | this.allowNegative = allowNegative; |
75 | 0 | } |
76 | ||
77 | /** | |
78 | * @return the precision | |
79 | */ | |
80 | public int getPrecision() { | |
81 | 0 | return this.precision; |
82 | } | |
83 | ||
84 | /** | |
85 | * @param precision the precision to set | |
86 | */ | |
87 | public void setPrecision(int precision) { | |
88 | 0 | this.precision = precision; |
89 | 0 | } |
90 | ||
91 | /** | |
92 | * @return the scale | |
93 | */ | |
94 | public int getScale() { | |
95 | 0 | return this.scale; |
96 | } | |
97 | ||
98 | /** | |
99 | * @param scale the scale to set | |
100 | */ | |
101 | public void setScale(int scale) { | |
102 | 0 | this.scale = scale; |
103 | 0 | } |
104 | ||
105 | /*******************************************************************************/ | |
106 | ||
107 | /** | |
108 | * This overridden method ... | |
109 | * | |
110 | * @see org.kuali.rice.krad.datadictionary.validation.ValidationPattern#getValidationErrorMessageParameters(java.lang.String) | |
111 | */ | |
112 | // @Override | |
113 | // public String[] getValidationErrorMessageParameters(String attributeLabel) { | |
114 | // return new String[]{attributeLabel, String.valueOf(precision), String.valueOf(scale)}; | |
115 | // } | |
116 | ||
117 | } |