Coverage Report - net.sourceforge.jeuclid.context.typewrapper.TypeWrapper
 
Classes in this File Line Coverage Branch Coverage Complexity
TypeWrapper
N/A
N/A
1
 
 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: TypeWrapper.java,v 03dc0884e86f 2008/06/21 10:53:35 maxberger $ */
 18  
 
 19  
 package net.sourceforge.jeuclid.context.typewrapper;
 20  
 
 21  
 import java.io.Serializable;
 22  
 
 23  
 /**
 24  
  * Encapsulates information about a parameter's value type and how values
 25  
  * should be converted between strings and the appropriate object instances.
 26  
  * <p>
 27  
  * This allows elimination of an additional "evil" if-elseif...else" pattern.
 28  
  * 
 29  
  * @version $Revision: 03dc0884e86f $
 30  
  */
 31  
 public interface TypeWrapper extends Serializable {
 32  
 
 33  
     /** Error message for failed to convert 1/2. */
 34  
     String FAILED_TO_CONVERT = "Failed to convert <";
 35  
 
 36  
     /** Error message for failed to convert 2/2. */
 37  
     String TO = "> to ";
 38  
 
 39  
     /**
 40  
      * @return the class instance being wrapped
 41  
      */
 42  
     Class<?> getValueType();
 43  
 
 44  
     /**
 45  
      * Checks if the object is of a valid type for this type info.
 46  
      * 
 47  
      * @param o
 48  
      *            the object to check
 49  
      * @return true if the parameter can be set.
 50  
      */
 51  
     boolean valid(Object o);
 52  
 
 53  
     /**
 54  
      * Attempts to convert a parameter value expressed as string into an
 55  
      * instance of the appropriate (for this parameter) type.
 56  
      * 
 57  
      * @param value
 58  
      *            parameter value as string
 59  
      * @return parameter value as an instance of the proper type
 60  
      */
 61  
     Object fromString(String value);
 62  
 
 63  
     /**
 64  
      * Attempts to convert a parameter value expressed as an object of the
 65  
      * appropriate (for this parameter) type into a string representation.
 66  
      * 
 67  
      * @param value
 68  
      *            parameter value as object
 69  
      * @return parameter value as string
 70  
      */
 71  
     String toString(Object value);
 72  
 }