Frames | No Frames |
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 3161 2007-08-13 17:46:03Z mimil $ 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: import org.jfree.formula.typing.sequence.NumberSequence; 37: 38: /** 39: * The type registry manages the known value types. 40: * 41: * @author Thomas Morgner 42: */ 43: public interface TypeRegistry 44: { 45: /** 46: * Returns an comparator for the given types. 47: * 48: * @param type1 49: * @param type2 50: * @return 51: */ 52: public ExtendedComparator getComparator(Type type1, Type type2); 53: 54: /** 55: * Converts the object of the given type into a number. If the object is not 56: * convertible, a NumberFormatException is thrown. (This conversion is used 57: * by the operator implementations.) 58: * 59: * @param type1 60: * @param value 61: * @return the value as number or ZERO if the value is unconvertible. 62: * @throws TypeConversionException if the type cannot be represented as number. 63: */ 64: public Number convertToNumber (Type type1, Object value) 65: throws TypeConversionException ; 66: 67: /** 68: * (This conversion is used by the operator implementations.) 69: * 70: * @param type1 71: * @param value 72: * @return the value as string or an empty string, if the value given is null. 73: * @throws TypeConversionException 74: */ 75: public String convertToText (Type type1, Object value) throws TypeConversionException; 76: 77: /** 78: * Converts the object of the given type into a boolean. 79: * 80: * @param type1 81: * @param value 82: * @return The value as Boolean or null. 83: */ 84: public Boolean convertToLogical (Type type1, Object value) throws TypeConversionException; 85: 86: /** 87: * Converts the object of the given type into a date. 88: * 89: * @param type1 90: * @param value 91: * @return The value as Date or null. 92: */ 93: public Date convertToDate(Type type1, Object value) throws TypeConversionException; 94: 95: public NumberSequence convertToNumberSequence(final Type type, final Object value) throws TypeConversionException; 96: 97: /** 98: * Checks, whether the target type would accept the specified value object 99: * 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: }