Package adams.parser

Class ParserHelper

    • Constructor Detail

      • ParserHelper

        public ParserHelper()
        Initializes the helper.
    • Method Detail

      • reportToSymbols

        public static HashMap reportToSymbols​(Report report)
        Turns the content of the report into symbols.
        Parameters:
        report - the report
        Returns:
        the evaluated result
      • initialize

        protected void initialize()
        Initializes members.
      • setSymbols

        public void setSymbols​(HashMap value)
        Sets the symbols in use.
        Parameters:
        value - the symbols
      • getSymbols

        public HashMap getSymbols()
        Returns the currently used symbols.
        Returns:
        the symbols
      • getCalendar

        public Calendar getCalendar()
        Returns the calendar instance to use.
        Returns:
        the calendar
      • getCalendar

        public Calendar getCalendar​(Date date)
        Returns the calendar instance to use.
        Parameters:
        date - the date to initialize the calendar with
        Returns:
        the calendar
      • setBusinessDays

        public void setBusinessDays​(BusinessDays value)
        Sets the type of business days to use.
        Parameters:
        value - the type
      • getBusinessDays

        public BusinessDays getBusinessDays()
        Returns the type of business days to use.
        Returns:
        the type
      • adjustAmount

        protected TimeAmount adjustAmount​(Date d,
                                          Double n,
                                          TimeAmount t)
        Corrects the amount using the factor and the note in the amount.
        Parameters:
        t - the amount to correct
        Returns:
        the (potentially) corrected amount
      • add

        public Date add​(Date d,
                        Double n,
                        TimeAmount t)
        Adds the request amount of time.
        Parameters:
        d - the current date
        n - the factor
        t - the time amount to use
        Returns:
        the new date
      • getDateFieldFromString

        public Double getDateFieldFromString​(Object obj,
                                             int field)
        Returns the specified date from the object (if it is a String or Date object).
        Parameters:
        obj - the object to extract the date field from
        field - the date field (see constants of Calendar class)
        Returns:
        the value or NaN if failed to convert
      • isBusinessDay

        public boolean isBusinessDay​(Object obj)
        Checks whether the string/date represents a business day.
        Parameters:
        obj - the string/date to check
        Returns:
        true if business day
        See Also:
        getBusinessDays()
      • toNumber

        public Double toNumber​(Object obj)
        Turns the object into a double.
        Parameters:
        obj - the object to convert
        Returns:
        the numeric value, NaN if not a number
      • toDouble

        public Double toDouble​(Object obj)
        Turns the object into a double.
        Parameters:
        obj - the object to convert
        Returns:
        the numeric value, NaN if not a double
      • toInteger

        public Integer toInteger​(Object obj)
        Turns the object (ie double) into an integer.
        Parameters:
        obj - the object to convert
        Returns:
        the numeric value, MAX_VALUE if not a double
      • toBoolean

        public Boolean toBoolean​(Object obj)
        Turns the object into a boolean.
        Parameters:
        obj - the object to convert
        Returns:
        the boolean, false if not a boolean
      • toString

        public String toString​(Object obj)
        Turns the object into a string.
        Parameters:
        obj - the object to convert
        Returns:
        the string representation
      • toDate

        public Date toDate​(String s)
        Turns the string into a Date object.
        Parameters:
        s - the string to convert
        Returns:
        the Date object, null if failed to convert
      • compare

        public Double compare​(Object o1,
                              Object o2)
        Compares two objects.
        Parameters:
        o1 - the first object
        o2 - the second object
        Returns:
        the comparison, NaN if failed to compare
      • substitute

        public String substitute​(String str,
                                 String find,
                                 String replace)
        Substitutes a occurrences of a string with a replacement string.
        Parameters:
        str - the string to process
        find - the string to replace
        replace - the replacement string
      • repeat

        public String repeat​(String str,
                             int num)
        Generates a string made up of multiple copies of a string.
        Parameters:
        str - the string to copy multiple times
        num - the number of times to copy
        Returns:
        the generated string
      • replace

        public String replace​(String str,
                              int pos,
                              int len,
                              String newStr)
        Replaces a sub-string at a specified location with a new string.
        Parameters:
        str - the string to update
        pos - the starting position (0-based)
        len - the length of the substring to replace
        newStr - the new String to insert
        Returns:
        the updated string
      • substitute

        public String substitute​(String str,
                                 String find,
                                 String replace,
                                 int occurrences)
        Substitutes a occurrences of a string with a replacement string.
        Parameters:
        str - the string to process
        find - the string to replace
        replace - the replacement string
        occurrences - the maximum number of occurrences, use <= 0 to ignore
      • left

        public String left​(String str,
                           int len)
        Returns the specified number of characters from the left of the string. If string is shorter than specified length, all of the string is returned.
        Parameters:
        str - the source string
        len - the number of characters
        Returns:
        the substring
      • mid

        public String mid​(String str,
                          int pos,
                          int len)
        Returns the specified substring from the string. If the start position is greater than the string's length itself, then an empty string is returned. If (pos+len) exceeds the string's length, then only the available substring is returned.
        Parameters:
        str - the source string
        pos - the starting position (0-based)
        len - the number of characters to copy
        Returns:
        the substring
      • right

        public String right​(String str,
                            int len)
        Returns the specified number of characters from the right of the string. If string is shorter than specified length, all of the string is returned.
        Parameters:
        str - the source string
        len - the number of characters
        Returns:
        the substring
      • initFunctions

        protected static void initFunctions()
        Initializes the additional functions.
      • getFunction

        protected static ParserFunction getFunction​(String name)
        Returns the function associated with the given function name.
        Parameters:
        name - the name of the function
        Returns:
        the instance of the function
        Throws:
        IllegalArgumentException - if the function name is not available
      • getFunctionOverview

        public static String getFunctionOverview()
        Builds a string of all the additionally available functions.
        Returns:
        the generated overview
      • callFunction

        public Object callFunction​(String name,
                                   Object[] params)
        Call function.
        Parameters:
        name - the name of the function
        params - the parameters of the function
        Returns:
        the result of the function call
      • initProcedures

        protected static void initProcedures()
        Initializes the additional procedures.
      • getProcedure

        protected static ParserProcedure getProcedure​(String name)
        Returns the procedure associated with the given procedure name.
        Parameters:
        name - the name of the procedure
        Returns:
        the instance of the procedure
        Throws:
        IllegalArgumentException - if the procedure name is not available
      • getProcedureOverview

        public static String getProcedureOverview()
        Builds a string of all the additionally available procedures.
        Returns:
        the generated overview
      • callProcedure

        public void callProcedure​(String name,
                                  Object[] params)
        Call procedure.
        Parameters:
        name - the name of the procedure
        params - the parameters of the prodcure