Coverage report

  %line %branch
org.apache.commons.jelly.tags.swing.converters.DimensionConverter
93% 
89% 

 1  
 /*
 2  
  * Copyright 2002,2004 The Apache Software Foundation.
 3  
  *
 4  
  * Licensed under the Apache 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.apache.org/licenses/LICENSE-2.0
 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.apache.commons.jelly.tags.swing.converters;
 17  
 
 18  
 import java.awt.Dimension;
 19  
 import java.util.StringTokenizer;
 20  
 
 21  
 import org.apache.commons.beanutils.Converter;
 22  
 
 23  
 /**
 24  
  * A Converter that turns Strings in the form "width, height" into Dimension objects
 25  
  *
 26  
  * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
 27  
  * @version $Revision: 155420 $
 28  
  */
 29  4
 public class DimensionConverter implements Converter {
 30  
 
 31  
     public Object convert(Class type, Object value) {
 32  16
         if ( value != null ) {
 33  16
             String text = value.toString();
 34  16
             StringTokenizer dimensionEnum = new StringTokenizer( text, "," );
 35  16
             int width = 0;
 36  16
             int height = 0;
 37  16
             if ( dimensionEnum.hasMoreTokens() ) {
 38  16
                 width = parseNumber( dimensionEnum.nextToken() );
 39  
             }
 40  16
             if ( dimensionEnum.hasMoreTokens() ) {
 41  12
                 height = parseNumber( dimensionEnum.nextToken() );
 42  
             }
 43  
 
 44  
             // now lets parse the dimension...
 45  16
             return new Dimension( width, height );
 46  
         }
 47  0
         return null;
 48  
     }
 49  
 
 50  
     protected int parseNumber(String text) {
 51  28
         text = text.trim();
 52  28
         return Integer.parseInt(text);
 53  
     }
 54  
 
 55  
 }

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