Coverage Report - org.kuali.rice.krad.datadictionary.validation.constraint.FloatingPointPatternConstraint
 
Classes in this File Line Coverage Branch Coverage Complexity
FloatingPointPatternConstraint
0%
0/16
0%
0/6
1.75
 
 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  
 import java.util.ArrayList;
 19  
 import java.util.List;
 20  
 
 21  
 import org.kuali.rice.core.api.config.property.ConfigurationService;
 22  
 import org.kuali.rice.krad.service.KRADServiceLocator;
 23  
 import org.kuali.rice.krad.uif.UifConstants;
 24  
 
 25  
 /**
 26  
  * Validation pattern for matching floating point numbers, optionally matching negative numbers
 27  
  * 
 28  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 29  
  */
 30  0
 public class FloatingPointPatternConstraint extends ConfigurationBasedRegexPatternConstraint {
 31  
 
 32  
     protected boolean allowNegative;
 33  
 
 34  
     /**
 35  
      * @see org.kuali.rice.krad.datadictionary.validation.constraint.ValidCharactersPatternConstraint#getRegexString()
 36  
      */
 37  
     @Override
 38  
     protected String getRegexString() {
 39  0
         StringBuffer regex = new StringBuffer();
 40  
 
 41  0
         if (isAllowNegative()) {
 42  0
             regex.append("-?");
 43  
         }
 44  0
         regex.append(super.getRegexString());
 45  
 
 46  0
         return regex.toString();
 47  
     }
 48  
 
 49  
     /**
 50  
      * @return the allowNegative
 51  
      */
 52  
     public boolean isAllowNegative() {
 53  0
         return this.allowNegative;
 54  
     }
 55  
 
 56  
     /**
 57  
      * @param allowNegative the allowNegative to set
 58  
      */
 59  
     public void setAllowNegative(boolean allowNegative) {
 60  0
         this.allowNegative = allowNegative;
 61  0
     }
 62  
 
 63  
     /**
 64  
      * This overridden method ...
 65  
      * 
 66  
      * @see org.kuali.rice.krad.datadictionary.validation.constraint.ValidDataPatternConstraint#getValidationMessageParams()
 67  
      */
 68  
     @Override
 69  
     public List<String> getValidationMessageParams() {
 70  0
         if (validationMessageParams == null) {
 71  0
             validationMessageParams = new ArrayList<String>();
 72  0
             ConfigurationService configService = KRADServiceLocator.getKualiConfigurationService();
 73  0
             if (allowNegative) {
 74  0
                 validationMessageParams.add(configService
 75  
                         .getPropertyValueAsString(UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX
 76  
                                 + "positiveOrNegative"));
 77  
             } else {
 78  0
                 validationMessageParams.add(configService
 79  
                         .getPropertyValueAsString(UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "positive"));
 80  
             }
 81  
         }
 82  0
         return validationMessageParams;
 83  
     }
 84  
 }