/** * Copyright 2006 Bertoli Marco * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gamingmesh.jobs.resources.jfep; /** *

Name: FunctionNode

*

Description: * This node is used to evaluate every kind of function with a single parameter, like abs(...) or sin(...) *

*

Date: 08/dic/06 * Time: 16:31:14

* @author Bertoli Marco * @version 1.0 */ public class FunctionNode implements ExpressionNode { /** List of supported functions */ public static final String[] FUNCTIONS = new String[] {"-", "sin", "cos", "tan", "asin", "acos", "atan", "sinh", "cosh", "tanh", "asinh", "acosh", "atanh", "ln", "log", "abs", "rand", "sqrt", "erf", "erfc", "gamma", "exp", "cot", "log2"}; /** Child node */ protected ExpressionNode child; /** Function of this node */ protected int function; /** An array with children */ protected ExpressionNode[] children; /** * Creates a function node. * @param child child node of this node * @param function function to be evaluated. This is the index in FUNCTIONS array * @see FunctionNode#FUNCTIONS */ public FunctionNode(ExpressionNode child, int function) { this.child = child; this.function = function; children = new ExpressionNode[] {child}; } /** * Creates a function node. * @param child child node of this node * @param function name of function to be evaluated. * @throws IllegalArgumentException if function is unsupported */ public FunctionNode(ExpressionNode child, String function) throws IllegalArgumentException { this.child = child; this.function = -1; children = new ExpressionNode[] {child}; for (int i=0; i