Class Utils

java.lang.Object
parser.methods.ext.Utils

public final class Utils extends Object
  • Constructor Details

    • Utils

      public Utils()
  • Method Details

    • stringsToBigDecimals

      public static List<BigDecimal> stringsToBigDecimals(List<String> tokens)
      Converts list of strings to list of big decimals
    • stringsToBigDecimals

      public static List<BigDecimal> stringsToBigDecimals(List<String> tokens, int headCut)
      Converts list of strings to list of big decimals, and custs first
      Parameters:
      headCut - members to cut of frombthebegining
    • trimList

      public static List<?> trimList(List<?> tokens, int toRemove, int minLength)
      Will remove toRemove elements from BOTH sides of tokens, leaving at least minLength of elements in place. It always take from both sides, or nto at all
    • sum

      public static BigDecimal sum(List<BigDecimal> l)
      Returns:
      the sum of all elements in the data set with BigDecimal precission
    • gsum

      public static BigDecimal gsum(List<BigDecimal> l)
      Returns:
      the geomethrical (multiplied) sum of all elements in the data set
    • getFirstBigDeciamalTokenAsInt

      public static int getFirstBigDeciamalTokenAsInt(List<BigDecimal> tokens)
    • getFirstStringTokenAsInt

      public static int getFirstStringTokenAsInt(List<String> tokens)
    • checkOnlyNumbers

      public static boolean checkOnlyNumbers(List<String> tokens)
    • evaluateSingleToken

      public static List<BigDecimal> evaluateSingleToken(List<String> tokens)
      This is method, which allows the client functions to workaround the https://github.com/gbenroscience/ParserNG/issues/25 Once the issue is fixed, this method will simply change to convert list of strings to list of big decimals withot any evaluations
      Parameters:
      tokens - list of numbers or parts of mathematical expresion
      Returns:
      the converted numbers or evaluated expression as number.
    • tokensToNumbers

      public static List<BigDecimal> tokensToNumbers(List<String> tokens)
    • connectTokens

      public static String connectTokens(List<String> tokens)
    • checkAtLeastArgs

      public static void checkAtLeastArgs(String name, int count, List tokens) throws RuntimeException
      helper method to unify argument check on standart functions
      Parameters:
      name -
      count -
      tokens -
      Throws:
      RuntimeException
    • decimalAndFractionalParts

      public static int[] decimalAndFractionalParts(String s)
    • decimalAndFractionalParts

      public static int[] decimalAndFractionalParts(BigDecimal bd)
    • checkTokensCount

      public static void checkTokensCount(String title, int expected, List tokens)