/** * Call this function if you want to parse expressions which involve complex numbers. This method * specifies "i" as the imaginary unit (0,1). Two functions re() and im() are also added for * extracting the real or imaginary components of a complex number respectively. * * <p> * * @since 2.3.0 alpha The functions cmod and arg are added to get the modulus and argument. * @since 2.3.0 beta 1 The functions complex and polar to convert x,y and r,theta to Complex. * @since Feb 05 added complex conjugate conj. */ public void addComplex() { // add constants to Symbol Table symTab.addConstant("i", new Complex(0, 1)); funTab.put("re", new Real()); funTab.put("im", new Imaginary()); funTab.put("arg", new Arg()); funTab.put("cmod", new Abs()); funTab.put("complex", new ComplexPFMC()); funTab.put("polar", new Polar()); funTab.put("conj", new Conjugate()); }
/** * Removes a function from the parser. * * @return If the function was added earlier, the function class instance is returned. If the * function was not present, <code>null</code> is returned. */ public Object removeFunction(String name) { return funTab.remove(name); }
/** * Adds a new function to the parser. This must be done before parsing an expression so the parser * is aware that the new function may be contained in the expression. * * @param functionName The name of the function * @param function The function object that is used for evaluating the function */ public void addFunction(String functionName, PostfixMathCommandI function) { funTab.put(functionName, function); }
/** * Adds the standard functions to the parser. If this function is not called before parsing an * expression, functions such as sin() or cos() would produce an "Unrecognized function..." error. * In most cases, this method should be called immediately after the JEP object is created. * * @since 2.3.0 alpha added if and exp functions * @since 2.3.0 beta 1 added str function */ public void addStandardFunctions() { // add functions to Function Table funTab.put("sin", new Sine()); funTab.put("cos", new Cosine()); funTab.put("tan", new Tangent()); funTab.put("asin", new ArcSine()); funTab.put("acos", new ArcCosine()); funTab.put("atan", new ArcTangent()); funTab.put("atan2", new ArcTangent2()); funTab.put("sinh", new SineH()); funTab.put("cosh", new CosineH()); funTab.put("tanh", new TanH()); funTab.put("asinh", new ArcSineH()); funTab.put("acosh", new ArcCosineH()); funTab.put("atanh", new ArcTanH()); funTab.put("log", new Logarithm()); funTab.put("ln", new NaturalLogarithm()); funTab.put("exp", new Exp()); funTab.put("pow", new Power()); funTab.put("sqrt", new SquareRoot()); funTab.put("abs", new Abs()); funTab.put("mod", new Modulus()); funTab.put("sum", new Sum()); funTab.put("rand", new org.nfunk.jep.function.Random()); // rjm additions funTab.put("if", new If()); funTab.put("str", new Str()); // rjm 13/2/05 funTab.put("binom", new Binomial()); // rjm 26/1/07 funTab.put("round", new Round()); funTab.put("floor", new Floor()); funTab.put("ceil", new Ceil()); }
public Table evaluate() throws DatabaseException { DatabaseQueryContext context = new DatabaseQueryContext(database); if (type.equals("create")) { // Does the user have privs to create this tables? if (!database.getDatabase().canUserCreateTableObject(context, user, vname)) { throw new UserAccessException("User not permitted to create view: " + view_name); } // Does the schema exist? boolean ignore_case = database.isInCaseInsensitiveMode(); SchemaDef schema = database.resolveSchemaCase(vname.getSchema(), ignore_case); if (schema == null) { throw new DatabaseException("Schema '" + vname.getSchema() + "' doesn't exist."); } else { vname = new TableName(schema.getName(), vname.getName()); } // Check the permissions for this user to select from the tables in the // given plan. Select.checkUserSelectPermissions(context, user, plan); // Does the table already exist? if (database.tableExists(vname)) { throw new DatabaseException("View or table with name '" + vname + "' already exists."); } // Before evaluation, make a clone of the plan, QueryPlanNode plan_copy; try { plan_copy = (QueryPlanNode) plan.clone(); } catch (CloneNotSupportedException e) { Debug().writeException(e); throw new DatabaseException("Clone error: " + e.getMessage()); } // We have to execute the plan to get the DataTableDef that represents the // result of the view execution. Table t = plan.evaluate(context); DataTableDef data_table_def = new DataTableDef(t.getDataTableDef()); data_table_def.setTableName(vname); // Create a ViewDef object, ViewDef view_def = new ViewDef(data_table_def, plan_copy); // And create the view object, database.createView(query, view_def); // The initial grants for a view is to give the user who created it // full access. database .getGrantManager() .addGrant( Privileges.TABLE_ALL_PRIVS, GrantManager.TABLE, vname.toString(), user.getUserName(), true, Database.INTERNAL_SECURE_USERNAME); } else if (type.equals("drop")) { // Does the user have privs to drop this tables? if (!database.getDatabase().canUserDropTableObject(context, user, vname)) { throw new UserAccessException("User not permitted to drop view: " + view_name); } // Drop the view object database.dropView(vname); // Drop the grants for this object database.getGrantManager().revokeAllGrantsOnObject(GrantManager.TABLE, vname.toString()); } else { throw new Error("Unknown view command type: " + type); } return FunctionTable.resultTable(context, 0); }