/** * Return a deep copy of this object. * @return Deep copy of the object */ public Object clone() { Expression[] copyArgs = LanguageObject.Util.deepClone(this.args); Function copy = new Function(getName(), copyArgs); copy.setType(getType()); copy.setFunctionDescriptor(getFunctionDescriptor()); if(this.isImplicit()) { copy.makeImplicit(); } copy.eval = this.eval; return copy; }
/** * Insert a conversion function at specified index. This is a convenience * method to insert a conversion into the function tree. * @param index Argument index to insert conversion function at * @param functionDescriptor Conversion function descriptor */ public void insertConversion(int index, FunctionDescriptor functionDescriptor) { // Get target type for conversion Class<?> t = functionDescriptor.getReturnType(); String typeName = DataTypeManager.getDataTypeName(t); // Pull old expression at index Expression newArg[] = new Expression[] { args[index], new Constant(typeName) }; // Replace old expression with new expression, using old as arg Function func = new Function(functionDescriptor.getName(), newArg); args[index] = func; // Set function descriptor and type of new function func.setFunctionDescriptor(functionDescriptor); func.setType(t); func.makeImplicit(); }
/** * Insert a conversion function at specified index. This is a convenience * method to insert a conversion into the function tree. * @param index Argument index to insert conversion function at * @param functionDescriptor Conversion function descriptor */ public void insertConversion(int index, FunctionDescriptor functionDescriptor) { // Get target type for conversion Class<?> t = functionDescriptor.getReturnType(); String typeName = DataTypeManager.getDataTypeName(t); // Pull old expression at index Expression newArg[] = new Expression[] { args[index], new Constant(typeName) }; // Replace old expression with new expression, using old as arg Function func = new Function(functionDescriptor.getName(), newArg); args[index] = func; // Set function descriptor and type of new function func.setFunctionDescriptor(functionDescriptor); func.setType(t); func.makeImplicit(); }
/** * Insert a conversion function at specified index. This is a convenience * method to insert a conversion into the function tree. * @param index Argument index to insert conversion function at * @param functionDescriptor Conversion function descriptor */ public void insertConversion(int index, FunctionDescriptor functionDescriptor) { // Get target type for conversion Class<?> t = functionDescriptor.getReturnType(); String typeName = DataTypeManager.getDataTypeName(t); // Pull old expression at index Expression newArg[] = new Expression[] { args[index], new Constant(typeName) }; // Replace old expression with new expression, using old as arg Function func = new Function(functionDescriptor.getName(), newArg); args[index] = func; // Set function descriptor and type of new function func.setFunctionDescriptor(functionDescriptor); func.setType(t); func.makeImplicit(); }
/** * Return a deep copy of this object. * @return Deep copy of the object */ public Object clone() { Expression[] copyArgs = LanguageObject.Util.deepClone(this.args); Function copy = new Function(getName(), copyArgs); copy.setType(getType()); copy.setFunctionDescriptor(getFunctionDescriptor()); if(this.isImplicit()) { copy.makeImplicit(); } copy.eval = this.eval; return copy; }
/** * Return a deep copy of this object. * @return Deep copy of the object */ public Object clone() { Expression[] copyArgs = LanguageObject.Util.deepClone(this.args); Function copy = new Function(getName(), copyArgs); copy.setType(getType()); copy.setFunctionDescriptor(getFunctionDescriptor()); if(this.isImplicit()) { copy.makeImplicit(); } copy.eval = this.eval; return copy; }
/** * IMPORTANT: source and target must be basic runtime types * @param sourceExpression * @param sourceTypeName * @param targetTypeName * @param implicit * @param library * @return */ public static Function getConversion(Expression sourceExpression, String sourceTypeName, String targetTypeName, boolean implicit, FunctionLibrary library) { Class<?> srcType = DataTypeManager.getDataTypeClass(sourceTypeName); Class<?> targetType = DataTypeManager.getDataTypeClass(targetTypeName); try { setDesiredType(sourceExpression, targetType, sourceExpression); } catch (QueryResolverException e) { } FunctionDescriptor fd = library.findTypedConversionFunction(srcType, DataTypeManager.getDataTypeClass(targetTypeName)); Function conversion = new Function(fd.getName(), new Expression[] { sourceExpression, new Constant(targetTypeName) }); conversion.setType(DataTypeManager.getDataTypeClass(targetTypeName)); conversion.setFunctionDescriptor(fd); if (implicit) { conversion.makeImplicit(); } return conversion; }
/** * IMPORTANT: source and target must be basic runtime types * @param sourceExpression * @param sourceTypeName * @param targetTypeName * @param implicit * @param library * @return */ public static Function getConversion(Expression sourceExpression, String sourceTypeName, String targetTypeName, boolean implicit, FunctionLibrary library) { Class<?> srcType = DataTypeManager.getDataTypeClass(sourceTypeName); Class<?> targetType = DataTypeManager.getDataTypeClass(targetTypeName); try { setDesiredType(sourceExpression, targetType, sourceExpression); } catch (QueryResolverException e) { } FunctionDescriptor fd = library.findTypedConversionFunction(srcType, DataTypeManager.getDataTypeClass(targetTypeName)); Function conversion = new Function(fd.getName(), new Expression[] { sourceExpression, new Constant(targetTypeName) }); conversion.setType(DataTypeManager.getDataTypeClass(targetTypeName)); conversion.setFunctionDescriptor(fd); if (implicit) { conversion.makeImplicit(); } return conversion; }
/** * IMPORTANT: source and target must be basic runtime types * @param sourceExpression * @param sourceTypeName * @param targetTypeName * @param implicit * @param library * @return */ public static Function getConversion(Expression sourceExpression, String sourceTypeName, String targetTypeName, boolean implicit, FunctionLibrary library) { Class<?> srcType = DataTypeManager.getDataTypeClass(sourceTypeName); Class<?> targetType = DataTypeManager.getDataTypeClass(targetTypeName); try { setDesiredType(sourceExpression, targetType, sourceExpression); } catch (QueryResolverException e) { } FunctionDescriptor fd = library.findTypedConversionFunction(srcType, DataTypeManager.getDataTypeClass(targetTypeName)); Function conversion = new Function(fd.getName(), new Expression[] { sourceExpression, new Constant(targetTypeName) }); conversion.setType(DataTypeManager.getDataTypeClass(targetTypeName)); conversion.setFunctionDescriptor(fd); if (implicit) { conversion.makeImplicit(); } return conversion; }
@Test public void testDateToTimestampConversion_defect9747() { // Expected left expression ElementSymbol e1 = new ElementSymbol("pm3.g1.e4"); //$NON-NLS-1$ e1.setType(DataTypeManager.DefaultDataClasses.TIMESTAMP); // Expected right expression Constant e2 = new Constant(TimestampUtil.createDate(96, 0, 31), DataTypeManager.DefaultDataClasses.DATE); Function f1 = new Function("convert", new Expression[] { e2, new Constant(DataTypeManager.DefaultDataTypes.TIMESTAMP)}); //$NON-NLS-1$ f1.makeImplicit(); // Expected criteria CompareCriteria expected = new CompareCriteria(); expected.setLeftExpression(e1); expected.setOperator(CompareCriteria.GT); expected.setRightExpression(f1); // Resolve the query and check against expected objects CompareCriteria actual = (CompareCriteria) helpResolveCriteria("pm3.g1.e4 > {d '1996-01-31'}"); //$NON-NLS-1$ assertEquals("Did not match expected criteria", expected, actual); //$NON-NLS-1$ }