/* * FormulaFunction_Mid.java * * Created on May 1, 2006, 9:46 AM * * Copyright 2006 Lee Lofgern and Accounting Enhancements Inc 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.accountingenhancements.formula; import com.accountingenhancements.common.SupportParameters; import java.text.ParseException; import java.util.HashMap; /** * * @author Lee lofgren lofgren_opensource@accountingenhancements.com * @version 0.1009102006 */ public class FormulaFunction_Mid extends FormulaFunction{ protected static String[][] requiredArguments = {{"ARG1: The source String from which the middle is to be returned","TYPE_?"},{"ARG2: The starting position of the source from which the result is to be return. If the source is less than this starting point then an empty string will be returned","TYPE_LONG"},{"ARG3(Optional): The Length of the segment t be returned. If the end of the String is reached before this size is reached, the string will be shorter than this size.","TYPE_LONG"}}; protected static String[] returnValueDescription = {"Middle section of string ARG1 starting at position ARG2 and not exceeding the length specified in ARG3.","TYPE_STRING"}; /** *Create a new FormulaFunction with an already defined functionArgumentStack. *@param functionArgumentStack a list of FormulaVariables that are needed by the function. */ public FormulaFunction_Mid(FormulaVariableStack functionArgumentStack){ super(functionArgumentStack); } /** *Create a new FormulaFunction with a comma-delimited string representing the arguments needed by the function *@param functionArgumentString the string representing the functions arguments. The outer parentheses must be removed.
*Example: If the function is IIF(A *Example: If the function is IIF(A *This is the most common constructor used. *@param functionVariable a FormulaVariable of TYPE_FUNCTION *@throws ParseException if arguments can't be parsed using parseCommaDelimitedFunctionFields(String,int) */ public FormulaFunction_Mid(FormulaVariable functionVariable) throws ParseException{ super(functionVariable); } protected FormulaVariable solve(FormulaVariableList variableList, int iteration, SupportParameters supportParameters, FormulaFunctionList functionList, int resolveEverythingAboveLevel) throws java.text.ParseException, java.lang.ArithmeticException, ClassNotFoundException{ FormulaVariable result=null; String resultString; FormulaVariable argVariable; int highestLevel; int start=0; int size=0; if(functionArgumentStack==null)throw new java.lang.ArithmeticException("functionArgumentStack is null"); result=functionArgumentStack.get("ARG1"); if(result==null)throw new java.lang.ArithmeticException("ARG1 is missing from functionArgumentStack"); result=result.solve(variableList,iteration,supportParameters,functionList,resolveEverythingAboveLevel); if(result!=null){ resultString=result.getString(); highestLevel=result.getHighestLevel(); if(resultString!=null){ argVariable=functionArgumentStack.get("ARG2"); if(argVariable==null)throw new java.lang.ArithmeticException("ARG2 is missing from functionArgumentStack"); argVariable=argVariable.solve(variableList,iteration,supportParameters,functionList,resolveEverythingAboveLevel); if(argVariable!=null){ start=argVariable.getLong().intValue(); if(highestLevel=0&&sizeresult.getHighestLevel()){ result=result.clone(); //Chances are that if this is true then the result is the original FormulaVariable and we want to leave that alone result.setHighestLevel(highestLevel); } } return result; } /** *@return the name of this function */ public static String getName() { return "Mid"; } /** *@return String[][] of needed arguments and their dataTypes which as {{"Test Argument ARG1","TYPE_BOOLEAN"},{"True Argument ARG2","TYPE_?"},{"False Argument ARG3","TYPE_?"}}
*If handing this routine a FormulaVariableStack functionArgumentStack then the FormulaVariable arguments should be named, ARG1, ARG2, etc... */ public static String[][] getRequiredArguments(){ return requiredArguments; } /** *@return String[] description of the return value as well as it's data type */ public static String[] getReturnValueDescription(){ return returnValueDescription; } }