Source for org.jfree.formula.typing.TypeRegistry

   1: /**
   2:  * =========================================
   3:  * LibFormula : a free Java formula library
   4:  * =========================================
   5:  *
   6:  * Project Info:  http://reporting.pentaho.org/libformula/
   7:  *
   8:  * (C) Copyright 2006-2007, by Pentaho Corporation and Contributors.
   9:  *
  10:  * This library is free software; you can redistribute it and/or modify it under the terms
  11:  * of the GNU Lesser General Public License as published by the Free Software Foundation;
  12:  * either version 2.1 of the License, or (at your option) any later version.
  13:  *
  14:  * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
  15:  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  16:  * See the GNU Lesser General Public License for more details.
  17:  *
  18:  * You should have received a copy of the GNU Lesser General Public License along with this
  19:  * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  20:  * Boston, MA 02111-1307, USA.
  21:  *
  22:  * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
  23:  * in the United States and other countries.]
  24:  *
  25:  *
  26:  * ------------
  27:  * $Id: TypeRegistry.java,v 1.10 2007/05/07 22:57:01 mimil Exp $
  28:  * ------------
  29:  * (C) Copyright 2006-2007, by Pentaho Corporation.
  30:  */
  31: package org.jfree.formula.typing;
  32: 
  33: import java.util.Date;
  34: 
  35: import org.jfree.formula.lvalues.TypeValuePair;
  36: 
  37: /**
  38:  * The type registry manages the known value types.
  39:  *
  40:  * @author Thomas Morgner
  41:  */
  42: public interface TypeRegistry
  43: {
  44:   /**
  45:    * Returns an comparator for the given types.
  46:    *
  47:    * @param type1
  48:    * @param type2
  49:    * @return
  50:    */
  51:   public ExtendedComparator getComparator(Type type1, Type type2);
  52: 
  53:   /**
  54:    * Converts the object of the given type into a number. If the object is not
  55:    * convertible, a NumberFormatException is thrown. (This conversion is used
  56:    * by the operator implementations.)
  57:    *
  58:    * @param type1
  59:    * @param value
  60:    * @return the value as number or ZERO if the value is unconvertible.
  61:    * @throws TypeConversionException if the type cannot be represented as number.
  62:    */
  63:   public Number convertToNumber (Type type1, Object value)
  64:       throws TypeConversionException ;
  65: 
  66:   /**
  67:    * (This conversion is used by the operator implementations.)
  68:    *
  69:    * @param type1
  70:    * @param value
  71:    * @return the value as string or an empty string, if the value given is null.
  72:    * @throws TypeConversionException 
  73:    */
  74:   public String convertToText (Type type1, Object value) throws TypeConversionException;
  75: 
  76:   /**
  77:    * Converts the object of the given type into a boolean.
  78:    *
  79:    * @param type1
  80:    * @param value
  81:    * @return The value as Boolean or null.
  82:    */
  83:   public Boolean convertToLogical (Type type1, Object value) throws TypeConversionException;
  84: 
  85:   /**
  86:    * Converts the object of the given type into a date.
  87:    *
  88:    * @param type1
  89:    * @param value
  90:    * @return The value as Date or null.
  91:    */
  92:   public Date convertToDate(Type type1, Object value)  throws TypeConversionException;
  93: 
  94:   /**
  95:    * Checks, whether the target type would accept the specified value object
  96:    * and value type. (This conversion is used by the functions.)
  97:    *
  98:    * @param targetType
  99:    * @param valuePair
 100:    */
 101:   public TypeValuePair convertTo(final Type targetType,
 102:                                  final TypeValuePair valuePair) throws TypeConversionException;
 103:   
 104:   public Type guessTypeOfObject(Object o);
 105: }