Class ConstantArgumentTexts

java.lang.Object
dev.frostlake.functions.aggregate.ConstantArgumentTexts

public final class ConstantArgumentTexts extends Object
Reads the constant integer an aggregate call wrote as one of its arguments — the k and the counter limit of the APPROX_TOP_K family — from the argument's text. The compile-time rules have already refused what is not an integral constant, so what remains is the spelling: a bare integer, a parenthesised or plus-signed one, an integral decimal or exponent form (2.0, 1e1), or a quoted number ('2'); anything else falls back to the caller's default.
  • Method Summary

    Modifier and Type
    Method
    Description
    static int
    integer(List<String> argumentTexts, int index, int fallback)
    The integral value of an argument text, or the fallback.
    static BigDecimal
    The integral value a constant text spells, or null when it spells none — a fraction, a non-numeric string, a column or an expression.
    static boolean
    Whether a constant text is a string literal, which live converts through TO_NUMBER.
    static BigDecimal
    The numeric value a constant text spells, quoted or not, or null when it is not a numeric or string literal that reads as a number.
    static String
    unwrap(String text)
    The text without its enclosing parentheses and a leading plus sign — (2) and +2 are the constant 2 (live-verified).

    Methods inherited from class java.lang.Object

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

    • integer

      public static int integer(List<String> argumentTexts, int index, int fallback)
      The integral value of an argument text, or the fallback.
      Parameters:
      argumentTexts - the call's argument texts, or null
      index - which argument
      fallback - the value when the argument is absent or not an integral constant
      Returns:
      the integer
    • integralConstant

      public static BigDecimal integralConstant(String text)
      The integral value a constant text spells, or null when it spells none — a fraction, a non-numeric string, a column or an expression.
      Parameters:
      text - the argument text
      Returns:
      the value, or null
    • numericConstant

      public static BigDecimal numericConstant(String text)
      The numeric value a constant text spells, quoted or not, or null when it is not a numeric or string literal that reads as a number.
      Parameters:
      text - the argument text
      Returns:
      the value, or null
    • isStringLiteral

      public static boolean isStringLiteral(String text)
      Whether a constant text is a string literal, which live converts through TO_NUMBER.
      Parameters:
      text - the argument text
      Returns:
      true for a single-quoted literal
    • unwrap

      public static String unwrap(String text)
      The text without its enclosing parentheses and a leading plus sign — (2) and +2 are the constant 2 (live-verified).
      Parameters:
      text - the argument text, or null
      Returns:
      the bare text, trimmed, or null