Class NumericFormatModel

java.lang.Object
dev.frostlake.functions.scalar.conversion.NumericFormatModel

public final class NumericFormatModel extends Object
A numeric INPUT format model — the format argument of TO_NUMBER / TO_DECIMAL / TO_NUMERIC, TO_DOUBLE and TO_DECFLOAT over a text, and of their TRY_ twins — scanned into its alternatives and checked the way the account checks it, before the text is read. A model that is not one is refused naming the whole model and the TARGET in the account's own word — FIXED for TO_NUMBER, REAL for TO_DOUBLE, DECFLOAT for TO_DECFLOAT — and the TRY_ twins answer NULL instead (all live-verified):
   TO_NUMBER('1', '9e9')      invalid numeric format keyword: 'e9'          letters, digits, _ $ % in a run
   TO_NUMBER('1', '9+')       invalid character in the format string: '+'   a tab shown as '\011'
   TO_NUMBER('1', '9"')       missing closing " in the literal: '9"'
   TO_NUMBER('1', '9SS')      format element occurs more than once: 'S'
   TO_NUMBER('1', '9D9.9')    format element conflicts with preceding element(s): '.'
   TO_NUMBER('1', '9EE.9')    digit position after an exponent format element: '9EE.9'
   TO_NUMBER('1', '9X')       cannot mix hexadecimal and decimal format elements: '9X'
   TO_NUMBER('1', 'TM99')     cannot mix TM and digit-based numeric format elements: 'TM99'
   TO_NUMBER('1', '$')        no digit format elements in a numeric format: '$'
   TO_NUMBER('1', ',')        missing required input format element(s)      '' and '|9' alike
   TO_DOUBLE('ff', 'XX')      missing required input format element(s)      hexadecimal is FIXED's alone
 

| separates alternatives, each checked in turn and the first that reads the text answering; one trailing | is ignored. AUTO alone is an alternative reading any number, and TM9 takes (digits[,group]). A text the model cannot read is refused by readOrRefuse(java.lang.String, java.lang.String, java.lang.String) with the text exactly as written. Scanning a model is data handling, not SQL: the model is a string VALUE.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    TO_DECFLOAT's target, in the refusal's own word.
    static final String
    The target TO_NUMBER, TO_DECIMAL and TO_NUMERIC convert to, in the refusal's own word.
    static final String
    TO_DOUBLE's target, in the refusal's own word.
  • Method Summary

    Modifier and Type
    Method
    Description
    parse(String format, String target)
    Scan and check a model.
    read(String text)
    The value the first alternative that reads the text gives.
    static BigDecimal
    readOrRefuse(String text, String format, String target)
    A text read under a model, refused as the account refuses it when no alternative reads it — the text echoed exactly as written, its spaces included: TO_NUMBER(' 123 ', '99') is "Can't parse ' 123 ' as number with format '99'".

    Methods inherited from class java.lang.Object

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

    • FIXED

      public static final String FIXED
      The target TO_NUMBER, TO_DECIMAL and TO_NUMERIC convert to, in the refusal's own word.
      See Also:
    • REAL

      public static final String REAL
      TO_DOUBLE's target, in the refusal's own word.
      See Also:
    • DECFLOAT

      public static final String DECFLOAT
      TO_DECFLOAT's target, in the refusal's own word.
      See Also:
  • Method Details

    • parse

      public static NumericFormatModel parse(String format, String target)
      Scan and check a model.
      Parameters:
      format - the model as written
      target - the target the refusal names: FIXED, REAL or DECFLOAT
      Returns:
      the model
    • readOrRefuse

      public static BigDecimal readOrRefuse(String text, String format, String target)
      A text read under a model, refused as the account refuses it when no alternative reads it — the text echoed exactly as written, its spaces included: TO_NUMBER(' 123 ', '99') is "Can't parse ' 123 ' as number with format '99'".
      Parameters:
      text - the text
      format - the model as written
      target - the target a refusal of the model names
      Returns:
      the value the text spells
    • read

      public BigDecimal read(String text)
      The value the first alternative that reads the text gives.
      Parameters:
      text - the text
      Returns:
      the value, or null when no alternative reads it