Class Utils

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

public final class Utils
extends java.lang.Object
  • Constructor Summary

    Constructors 
    Constructor Description
    Utils()  
  • Method Summary

    Modifier and Type Method Description
    static void checkAtLeastArgs​(java.lang.String name, int count, java.util.List tokens)
    helper method to unify argument check on standart functions
    static boolean checkOnlyNumbers​(java.util.List<java.lang.String> tokens)  
    static void checkTokensCount​(java.lang.String title, int expected, java.util.List tokens)  
    static java.lang.String connectTokens​(java.util.List<java.lang.String> tokens)  
    static int[] decimalAndFractionalParts​(java.lang.String s)  
    static int[] decimalAndFractionalParts​(java.math.BigDecimal bd)  
    static java.util.List<java.math.BigDecimal> evaluateSingleToken​(java.util.List<java.lang.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
    static int getFirstBigDeciamalTokenAsInt​(java.util.List<java.math.BigDecimal> tokens)  
    static int getFirstStringTokenAsInt​(java.util.List<java.lang.String> tokens)  
    static java.math.BigDecimal gsum​(java.util.List<java.math.BigDecimal> l)  
    static java.util.List<java.math.BigDecimal> stringsToBigDecimals​(java.util.List<java.lang.String> tokens)
    Converts list of strings to list of big decimals
    static java.util.List<java.math.BigDecimal> stringsToBigDecimals​(java.util.List<java.lang.String> tokens, int headCut)
    Converts list of strings to list of big decimals, and custs first
    static java.math.BigDecimal sum​(java.util.List<java.math.BigDecimal> l)  
    static java.util.List<java.math.BigDecimal> tokensToNumbers​(java.util.List<java.lang.String> tokens)  
    static java.util.List<?> trimList​(java.util.List<?> tokens, int toRemove, int minLength)
    Will remove toRemove elements from BOTH sides of tokens, leaving at least minLength of elements in place.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

  • Method Details

    • stringsToBigDecimals

      public static java.util.List<java.math.BigDecimal> stringsToBigDecimals​(java.util.List<java.lang.String> tokens)
      Converts list of strings to list of big decimals
    • stringsToBigDecimals

      public static java.util.List<java.math.BigDecimal> stringsToBigDecimals​(java.util.List<java.lang.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 java.util.List<?> trimList​(java.util.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 java.math.BigDecimal sum​(java.util.List<java.math.BigDecimal> l)
      Returns:
      the sum of all elements in the data set with BigDecimal precission
    • gsum

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

      public static int getFirstBigDeciamalTokenAsInt​(java.util.List<java.math.BigDecimal> tokens)
    • getFirstStringTokenAsInt

      public static int getFirstStringTokenAsInt​(java.util.List<java.lang.String> tokens)
    • checkOnlyNumbers

      public static boolean checkOnlyNumbers​(java.util.List<java.lang.String> tokens)
    • evaluateSingleToken

      public static java.util.List<java.math.BigDecimal> evaluateSingleToken​(java.util.List<java.lang.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 java.util.List<java.math.BigDecimal> tokensToNumbers​(java.util.List<java.lang.String> tokens)
    • connectTokens

      public static java.lang.String connectTokens​(java.util.List<java.lang.String> tokens)
    • checkAtLeastArgs

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

      public static int[] decimalAndFractionalParts​(java.lang.String s)
    • decimalAndFractionalParts

      public static int[] decimalAndFractionalParts​(java.math.BigDecimal bd)
    • checkTokensCount

      public static void checkTokensCount​(java.lang.String title, int expected, java.util.List tokens)