| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| FloatingPointPatternConstraint |
|
| 1.5;1.5 |
| 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 | * Validation pattern for matching floating point numbers, optionally matching negative numbers | |
| 20 | * | |
| 21 | * @author Kuali Rice Team (rice.collab@kuali.org) | |
| 22 | */ | |
| 23 | 0 | public class FloatingPointPatternConstraint extends ConfigurationBasedRegexPatternConstraint { |
| 24 | ||
| 25 | protected boolean allowNegative; | |
| 26 | ||
| 27 | /** | |
| 28 | * @see org.kuali.rice.krad.datadictionary.validation.constraint.ValidCharactersPatternConstraint#getRegexString() | |
| 29 | */ | |
| 30 | @Override | |
| 31 | protected String getRegexString() { | |
| 32 | 0 | StringBuffer regex = new StringBuffer(); |
| 33 | ||
| 34 | 0 | if (isAllowNegative()) { |
| 35 | 0 | regex.append("-?"); |
| 36 | } | |
| 37 | 0 | regex.append(super.getRegexString()); |
| 38 | ||
| 39 | 0 | return regex.toString(); |
| 40 | } | |
| 41 | ||
| 42 | /** | |
| 43 | * @see org.kuali.rice.krad.datadictionary.validation.constraint.ValidDataPatternConstraint#getLabelKey() | |
| 44 | */ | |
| 45 | @Override | |
| 46 | public String getLabelKey() { | |
| 47 | 0 | StringBuffer buf = new StringBuffer("validation.format." + getPatternTypeKey()); |
| 48 | 0 | if (isAllowNegative()) { |
| 49 | 0 | buf.append(".allowNegative"); |
| 50 | } | |
| 51 | 0 | return buf.toString(); |
| 52 | } | |
| 53 | ||
| 54 | /** | |
| 55 | * @return the allowNegative | |
| 56 | */ | |
| 57 | public boolean isAllowNegative() { | |
| 58 | 0 | return this.allowNegative; |
| 59 | } | |
| 60 | ||
| 61 | /** | |
| 62 | * @param allowNegative the allowNegative to set | |
| 63 | */ | |
| 64 | public void setAllowNegative(boolean allowNegative) { | |
| 65 | 0 | this.allowNegative = allowNegative; |
| 66 | 0 | } |
| 67 | ||
| 68 | /*******************************************************************************/ | |
| 69 | ||
| 70 | /** | |
| 71 | * This overridden method ... | |
| 72 | * | |
| 73 | * @see org.kuali.rice.krad.datadictionary.validation.ValidationPattern#getValidationErrorMessageParameters(java.lang.String) | |
| 74 | */ | |
| 75 | // @Override | |
| 76 | // public String[] getValidationErrorMessageParameters(String attributeLabel) { | |
| 77 | // return new String[]{attributeLabel, String.valueOf(precision), String.valueOf(scale)}; | |
| 78 | // } | |
| 79 | ||
| 80 | } |