Class SingleDelimiterTemplate

java.lang.Object
org.kigalisim.lang.localization.SingleDelimiterTemplate
All Implemented Interfaces:
NumberParseUtilStrategy
Direct Known Subclasses:
OnlyCommasParseStrategy, OnlyPeriodsParseStrategy

public abstract class SingleDelimiterTemplate extends Object implements NumberParseUtilStrategy
Abstract base class for single-separator number parsing strategies.
  • Constructor Details

    • SingleDelimiterTemplate

      public SingleDelimiterTemplate()
      Constructs a new SingleDelimiterTemplate.
  • Method Details

    • parseNumber

      public FlexibleNumberParseResult parseNumber(String numberStr, int commaCount, int periodCount)
      Description copied from interface: NumberParseUtilStrategy
      Parse a number string using this strategy's specific rules.
      Specified by:
      parseNumber in interface NumberParseUtilStrategy
      Parameters:
      numberStr - The cleaned number string (without sign)
      commaCount - Number of commas in the string
      periodCount - Number of periods in the string
      Returns:
      FlexibleNumberParseResult containing either parsed number or error
    • getSeparator

      protected abstract char getSeparator()
      Get the separator character used by this strategy.
      Returns:
      The separator character (',' or '.')
    • getStrategyName

      protected abstract String getStrategyName()
      Get the name of this strategy for error messages.
      Returns:
      The strategy name
    • getSeparatorCount

      protected abstract int getSeparatorCount(int commaCount, int periodCount)
      Get the count of this strategy's separator from the total counts.
      Parameters:
      commaCount - Number of commas in the string
      periodCount - Number of periods in the string
      Returns:
      The count relevant to this strategy
    • handleMultipleSeparators

      protected abstract FlexibleNumberParseResult handleMultipleSeparators(String numberStr, char separator)
      Handle numbers with multiple separators.
      Parameters:
      numberStr - The number string
      separator - The separator character
      Returns:
      FlexibleNumberParseResult containing either parsed number or error
    • handleLeadingSeparator

      protected abstract FlexibleNumberParseResult handleLeadingSeparator(String numberStr)
      Handle numbers with a leading separator.
      Parameters:
      numberStr - The number string starting with separator
      Returns:
      FlexibleNumberParseResult containing either parsed number or error
    • handleSingleNonAmbiguous

      protected abstract FlexibleNumberParseResult handleSingleNonAmbiguous(String numberStr)
      Handle numbers where the separator separates digits in a non-3-digit pattern.
      Parameters:
      numberStr - The number string
      Returns:
      FlexibleNumberParseResult containing either parsed number or error
    • handleAmbiguousCase

      protected abstract FlexibleNumberParseResult handleAmbiguousCase(String numberStr, char separator, int separatorIndex, int digitsBefore)
      Handle ambiguous case where exactly 3 digits follow a single separator.
      Parameters:
      numberStr - The number string
      separator - The separator character
      separatorIndex - The index of the separator
      digitsBefore - Number of digits before the separator
      Returns:
      FlexibleNumberParseResult containing either parsed number or error
    • handleSingleSeparatorType

      protected final FlexibleNumberParseResult handleSingleSeparatorType(String numberStr, char separator, int count)
      Handle numbers with only one type of separator.

      This template method implements the core parsing algorithm for single-separator numbers. It delegates to strategy-specific abstract methods for customization points.

      Parameters:
      numberStr - The number string
      separator - The separator character
      count - Number of occurrences of the separator
      Returns:
      FlexibleNumberParseResult containing either parsed number or error
    • isLikelyThousandsSeparator

      protected final boolean isLikelyThousandsSeparator(String numberStr, int separatorIndex)
      Determine if a single separator with 3 digits after is likely a thousands separator.
      • Numbers starting with 0 (like 0,035 or 0.035) are considered decimals, not thousands separators
      • Only consider as thousands separator if 4 or more digits appear before the separator
      Parameters:
      numberStr - The complete number string
      separatorIndex - The index of the separator
      Returns:
      true if it's likely a thousands separator
    • validateThousandsSeparatorPositions

      protected final FlexibleNumberParseResult validateThousandsSeparatorPositions(String numberStr, char separator)
      Validate that thousands separators are positioned correctly.
      • First part must be 1-3 digits
      • All subsequent parts must be exactly 3 digits
      Parameters:
      numberStr - The number string
      separator - The thousands separator character
      Returns:
      FlexibleNumberParseResult with success or error