Coverage Report - org.simpleframework.xml.transform.PrimitiveMatcher
 
Classes in this File Line Coverage Branch Coverage Complexity
PrimitiveMatcher
84%
16/19
81%
13/16
9
 
 1  
 /*
 2  
  * PrimitiveMatcher.java May 2007
 3  
  *
 4  
  * Copyright (C) 2007, Niall Gallagher <niallg@users.sf.net>
 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 
 15  
  * implied. See the License for the specific language governing 
 16  
  * permissions and limitations under the License.
 17  
  */
 18  
 
 19  
 package org.simpleframework.xml.transform;
 20  
 
 21  
 /**
 22  
  * The <code>PrimitiveMatcher</code> object is used to resolve the
 23  
  * primitive types to a stock transform. This will basically use
 24  
  * a transform that is used with the primitives language object.
 25  
  * This will always return a suitable transform for a primitive.
 26  
  * 
 27  
  * @author Niall Gallagher
 28  
  * 
 29  
  * @see org.simpleframework.xml.transform.DefaultMatcher
 30  
  */
 31  
 class PrimitiveMatcher implements Matcher { 
 32  
    
 33  
    /**
 34  
     * Constructor for the <code>PrimitiveMatcher</code> object. The
 35  
     * primitive matcher is used to resolve a transform instance to
 36  
     * convert primitive types to an from strings. If a match is not
 37  
     * found with this matcher then an exception is thrown.
 38  
     */
 39  
    public PrimitiveMatcher() {
 40  985
       super();
 41  985
    }
 42  
    
 43  
    /**
 44  
     * This method is used to match the specified type to primitive
 45  
     * transform implementations. If this is given a primitive then
 46  
     * it will always return a suitable <code>Transform</code>. If
 47  
     * however it is given an object type an exception is thrown.
 48  
     * 
 49  
     * @param type this is the primitive type to be transformed
 50  
     * 
 51  
     * @return this returns a stock transform for the primitive
 52  
     */
 53  
    public Transform match(Class type) throws Exception {     
 54  410
       if(type == int.class) {
 55  210
          return new IntegerTransform();
 56  
       }
 57  200
       if(type == boolean.class) {
 58  64
          return new BooleanTransform();
 59  
       }
 60  136
       if(type == long.class) {
 61  32
          return new LongTransform();
 62  
       }
 63  104
       if(type == double.class) {
 64  37
          return new DoubleTransform();
 65  
       }
 66  67
       if(type == float.class) {
 67  28
          return new FloatTransform();
 68  
       }
 69  39
       if(type == short.class) {
 70  19
          return new ShortTransform();
 71  
       }
 72  20
       if(type == byte.class) {
 73  20
          return new ByteTransform();
 74  
       }
 75  0
       if(type == char.class) {
 76  0
          return new CharacterTransform();
 77  
       }
 78  0
       return null;
 79  
    }
 80  
 }