Coverage Report - net.sourceforge.jeuclid.context.typewrapper.AbstractSimpleTypeWrapper
 
Classes in this File Line Coverage Branch Coverage Complexity
AbstractSimpleTypeWrapper
72%
8/11
50%
2/4
2
 
 1  
 /*
 2  
  * Copyright 2008 - 2008 JEuclid, http://jeuclid.sf.net
 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  
 
 17  
 /* $Id: AbstractSimpleTypeWrapper.java,v 03dc0884e86f 2008/06/21 10:53:35 maxberger $ */
 18  
 
 19  
 package net.sourceforge.jeuclid.context.typewrapper;
 20  
 
 21  
 /**
 22  
  * Basic (and simple) implementation of TypeWrapper. Maintains an instance of
 23  
  * type being wrapped as well as provides reasonable default implementations
 24  
  * for all the operations.
 25  
  * 
 26  
  * @version $Revision: 03dc0884e86f $
 27  
  */
 28  
 public abstract class AbstractSimpleTypeWrapper implements TypeWrapper {
 29  
     /**
 30  
      * 
 31  
      */
 32  
     private static final long serialVersionUID = 1L;
 33  
 
 34  
     /** the class instance being wrapped */
 35  
     private final Class<?> valueType;
 36  
 
 37  
     /**
 38  
      * @param valType
 39  
      *            a Class object
 40  
      */
 41  1881
     protected AbstractSimpleTypeWrapper(final Class<?> valType) {
 42  1881
         this.valueType = valType;
 43  1881
     }
 44  
 
 45  
     /** {@inheritDoc} */
 46  
     public Class<?> getValueType() {
 47  1672
         return this.valueType;
 48  
     }
 49  
 
 50  
     /** {@inheritDoc} */
 51  
     public boolean valid(final Object o) {
 52  4180
         return this.valueType.isInstance(o);
 53  
     }
 54  
 
 55  
     /** {@inheritDoc} */
 56  
     public Object fromString(final String value) {
 57  0
         if (value == null) {
 58  0
             return null;
 59  
         }
 60  0
         throw new IllegalArgumentException(TypeWrapper.FAILED_TO_CONVERT
 61  
                 + value + TypeWrapper.TO + this.valueType);
 62  
     }
 63  
 
 64  
     /** {@inheritDoc} */
 65  
     public String toString(final Object value) {
 66  1045
         if (value == null) {
 67  209
             return null;
 68  
         } else {
 69  836
             return value.toString();
 70  
         }
 71  
     }
 72  
 }