Coverage report

  %line %branch
org.apache.turbine.services.intake.model.DoubleField
0% 
0% 

 1  
 package org.apache.turbine.services.intake.model;
 2  
 
 3  
 /*
 4  
  * Copyright 2001-2005 The Apache Software Foundation.
 5  
  *
 6  
  * Licensed under the Apache License, Version 2.0 (the "License")
 7  
  * you may not use this file except in compliance with the License.
 8  
  * You may obtain a copy of the License at
 9  
  *
 10  
  *     http://www.apache.org/licenses/LICENSE-2.0
 11  
  *
 12  
  * Unless required by applicable law or agreed to in writing, software
 13  
  * distributed under the License is distributed on an "AS IS" BASIS,
 14  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 15  
  * See the License for the specific language governing permissions and
 16  
  * limitations under the License.
 17  
  */
 18  
 
 19  
 import org.apache.commons.lang.StringUtils;
 20  
 
 21  
 import org.apache.turbine.services.intake.IntakeException;
 22  
 import org.apache.turbine.services.intake.validator.DoubleValidator;
 23  
 import org.apache.turbine.services.intake.xmlmodel.XmlField;
 24  
 
 25  
 /**
 26  
  * Creates Double Field objects.
 27  
  *
 28  
  * @author <a href="mailto:quintonm@bellsouth.net">Quinton McCombs</a>
 29  
  * @version $Id: DoubleField.java 264148 2005-08-29 14:21:04Z henning $
 30  
  */
 31  
 public class DoubleField
 32  
         extends Field
 33  
 {
 34  
     /**
 35  
      * Constructor.
 36  
      *
 37  
      * @param field xml field definition object
 38  
      * @param group xml group definition object
 39  
      * @throws IntakeException thrown by superclass
 40  
      */
 41  
     public DoubleField(XmlField field, Group group)
 42  
             throws IntakeException
 43  
     {
 44  0
         super(field, group);
 45  0
     }
 46  
 
 47  
     /**
 48  
      * Sets the default value for a Double Field
 49  
      *
 50  
      * @param prop Parameter for the default values
 51  
      */
 52  
     public void setDefaultValue(String prop)
 53  
     {
 54  0
         defaultValue = null;
 55  
 
 56  0
         if (prop == null)
 57  
         {
 58  0
             return;
 59  
         }
 60  
 
 61  0
         defaultValue = new Double(prop);
 62  0
     }
 63  
 
 64  
     /**
 65  
      * Set the empty Value. This value is used if Intake
 66  
      * maps a field to a parameter returned by the user and
 67  
      * the corresponding field is either empty (empty string)
 68  
      * or non-existant.
 69  
      *
 70  
      * @param prop The value to use if the field is empty.
 71  
      */
 72  
     public void setEmptyValue(String prop)
 73  
     {
 74  0
         emptyValue = null;
 75  
 
 76  0
         if (prop == null)
 77  
         {
 78  0
             return;
 79  
         }
 80  
 
 81  0
         emptyValue = new Double(prop);
 82  0
     }
 83  
 
 84  
     /**
 85  
      * Provides access to emptyValue such that the value returned will be
 86  
      * acceptable as an argument parameter to Method.invoke.  Subclasses
 87  
      * that deal with primitive types should ensure that they return an
 88  
      * appropriate value wrapped in the object wrapper class for the
 89  
      * primitive type.
 90  
      *
 91  
      * @return the value to use when the field is empty or an Object that
 92  
      * wraps the empty value for primitive types.
 93  
      */
 94  
     protected Object getSafeEmptyValue()
 95  
     {
 96  0
         if (isMultiValued)
 97  
         {
 98  0
             return new double[0];
 99  
         }
 100  
         else
 101  
         {
 102  0
             return (null == getEmptyValue())
 103  
                     ? new Double(0.0) : getEmptyValue();
 104  
         }
 105  
     }
 106  
 
 107  
     /**
 108  
      * A suitable validator.
 109  
      *
 110  
      * @return A suitable validator
 111  
      */
 112  
     protected String getDefaultValidator()
 113  
     {
 114  0
         return DoubleValidator.class.getName();
 115  
     }
 116  
 
 117  
     /**
 118  
      * Sets the value of the field from data in the parser.
 119  
      */
 120  
     protected void doSetValue()
 121  
     {
 122  0
         if (isMultiValued)
 123  
         {
 124  0
             String[] inputs = parser.getStrings(getKey());
 125  0
             double[] values = new class="keyword">double[inputs.length];
 126  0
             for (int i = 0; i < inputs.length; i++)
 127  
             {
 128  0
                 values[i] = StringUtils.isNotEmpty(inputs[i])
 129  
                         ? new Double(inputs[i]).doubleValue()
 130  
                         : ((Double) getEmptyValue()).doubleValue();
 131  
             }
 132  0
             setTestValue(values);
 133  
         }
 134  
         else
 135  
         {
 136  0
             String val = parser.getString(getKey());
 137  0
             setTestValue(StringUtils.isNotEmpty(val)
 138  
                     ? new Double(val) : (Double) getEmptyValue());
 139  
         }
 140  0
     }
 141  
 
 142  
 }

This report is generated by jcoverage, Maven and Maven JCoverage Plugin.