001    /**
002     * =========================================
003     * LibFormula : a free Java formula library
004     * =========================================
005     *
006     * Project Info:  http://reporting.pentaho.org/libformula/
007     *
008     * (C) Copyright 2006-2007, by Pentaho Corporation and Contributors.
009     *
010     * This library is free software; you can redistribute it and/or modify it under the terms
011     * of the GNU Lesser General Public License as published by the Free Software Foundation;
012     * either version 2.1 of the License, or (at your option) any later version.
013     *
014     * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
015     * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
016     * See the GNU Lesser General Public License for more details.
017     *
018     * You should have received a copy of the GNU Lesser General Public License along with this
019     * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
020     * Boston, MA 02111-1307, USA.
021     *
022     * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
023     * in the United States and other countries.]
024     *
025     *
026     * ------------
027     * $Id: TypeRegistry.java 3161 2007-08-13 17:46:03Z mimil $
028     * ------------
029     * (C) Copyright 2006-2007, by Pentaho Corporation.
030     */
031    package org.jfree.formula.typing;
032    
033    import java.util.Date;
034    
035    import org.jfree.formula.lvalues.TypeValuePair;
036    import org.jfree.formula.typing.sequence.NumberSequence;
037    
038    /**
039     * The type registry manages the known value types.
040     *
041     * @author Thomas Morgner
042     */
043    public interface TypeRegistry
044    {
045      /**
046       * Returns an comparator for the given types.
047       *
048       * @param type1
049       * @param type2
050       * @return
051       */
052      public ExtendedComparator getComparator(Type type1, Type type2);
053    
054      /**
055       * Converts the object of the given type into a number. If the object is not
056       * convertible, a NumberFormatException is thrown. (This conversion is used
057       * by the operator implementations.)
058       *
059       * @param type1
060       * @param value
061       * @return the value as number or ZERO if the value is unconvertible.
062       * @throws TypeConversionException if the type cannot be represented as number.
063       */
064      public Number convertToNumber (Type type1, Object value)
065          throws TypeConversionException ;
066    
067      /**
068       * (This conversion is used by the operator implementations.)
069       *
070       * @param type1
071       * @param value
072       * @return the value as string or an empty string, if the value given is null.
073       * @throws TypeConversionException 
074       */
075      public String convertToText (Type type1, Object value) throws TypeConversionException;
076    
077      /**
078       * Converts the object of the given type into a boolean.
079       *
080       * @param type1
081       * @param value
082       * @return The value as Boolean or null.
083       */
084      public Boolean convertToLogical (Type type1, Object value) throws TypeConversionException;
085    
086      /**
087       * Converts the object of the given type into a date.
088       *
089       * @param type1
090       * @param value
091       * @return The value as Date or null.
092       */
093      public Date convertToDate(Type type1, Object value)  throws TypeConversionException;
094    
095      public NumberSequence convertToNumberSequence(final Type type, final Object value) throws TypeConversionException;
096    
097      /**
098       * Checks, whether the target type would accept the specified value object
099       * and value type. (This conversion is used by the functions.)
100       *
101       * @param targetType
102       * @param valuePair
103       */
104      public TypeValuePair convertTo(final Type targetType,
105                                     final TypeValuePair valuePair) throws TypeConversionException;
106      
107      public Type guessTypeOfObject(Object o);
108    }