Coverage Report - org.kuali.rice.kns.datadictionary.validation.fieldlevel.FloatingPointValidationPattern
 
Classes in this File Line Coverage Branch Coverage Complexity
FloatingPointValidationPattern
0%
0/19
0%
0/6
1.5
 
 1  
 /*
 2  
  * Copyright 2005-2008 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/ecl2.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.kns.datadictionary.validation.fieldlevel;
 17  
 
 18  
 import org.kuali.rice.kns.datadictionary.exporter.ExportMap;
 19  
 import org.kuali.rice.kns.datadictionary.validation.FieldLevelValidationPattern;
 20  
 
 21  
 /**
 22  
  * Validation pattern for matching floating point numbers, optionally matching negative numbers
 23  
  * 
 24  
  * 
 25  
  */
 26  0
 public class FloatingPointValidationPattern extends FieldLevelValidationPattern {
 27  
     protected boolean allowNegative;
 28  
 
 29  
     /**
 30  
      * @return allowNegative
 31  
      */
 32  
     public boolean getAllowNegative() {
 33  0
         return allowNegative;
 34  
     }
 35  
 
 36  
     /**
 37  
      * @param allowNegative
 38  
      */
 39  
     public void setAllowNegative(boolean allowNegative) {
 40  0
         this.allowNegative = allowNegative;
 41  0
     }
 42  
 
 43  
     /**
 44  
      * Adds special handling to account for optional allowNegative
 45  
      * 
 46  
      * @see org.kuali.rice.kns.datadictionary.validation.ValidationPattern#getRegexString()
 47  
      */
 48  
     protected String getRegexString() {
 49  0
         StringBuffer regex = new StringBuffer();
 50  
 
 51  0
         if (allowNegative) {
 52  0
             regex.append("-?");
 53  
         }
 54  0
         regex.append(super.getRegexString());
 55  
 
 56  0
         return regex.toString();
 57  
     }
 58  
 
 59  
     /**
 60  
      * @see org.kuali.rice.kns.datadictionary.validation.FieldLevelValidationPattern#getPatternTypeName()
 61  
      */
 62  
     protected String getPatternTypeName() {
 63  0
         return "floatingPoint";
 64  
     }
 65  
 
 66  
 
 67  
     /**
 68  
      * @see org.kuali.rice.kns.datadictionary.validation.ValidationPattern#buildExportMap(java.lang.String)
 69  
      */
 70  
     public ExportMap buildExportMap(String exportKey) {
 71  0
         ExportMap exportMap = super.buildExportMap(exportKey);
 72  
 
 73  0
         if (allowNegative) {
 74  0
             exportMap.set("allowNegative", "true");
 75  
         }
 76  
 
 77  0
         return exportMap;
 78  
     }
 79  
     
 80  
         /**
 81  
          * @see org.kuali.rice.kns.datadictionary.validation.FieldLevelValidationPattern#getValidationErrorMessageKey()
 82  
          */
 83  
         @Override
 84  
         public String getValidationErrorMessageKey() {
 85  0
                 StringBuilder buf = new StringBuilder();
 86  0
                 buf.append("error.format.").append(getClass().getName());
 87  0
                 if (allowNegative) {
 88  0
                         buf.append(".allowNegative");
 89  
                 }
 90  0
                 return buf.toString();
 91  
         }
 92  
 }