Package org.kigalisim.lang.localization
Class SingleDelimiterTemplate
java.lang.Object
org.kigalisim.lang.localization.SingleDelimiterTemplate
- All Implemented Interfaces:
NumberParseUtilStrategy
- Direct Known Subclasses:
OnlyCommasParseStrategy,OnlyPeriodsParseStrategy
Abstract base class for single-separator number parsing strategies.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract charGet the separator character used by this strategy.protected abstract intgetSeparatorCount(int commaCount, int periodCount) Get the count of this strategy's separator from the total counts.protected abstract StringGet the name of this strategy for error messages.protected abstract FlexibleNumberParseResulthandleAmbiguousCase(String numberStr, char separator, int separatorIndex, int digitsBefore) Handle ambiguous case where exactly 3 digits follow a single separator.protected abstract FlexibleNumberParseResulthandleLeadingSeparator(String numberStr) Handle numbers with a leading separator.protected abstract FlexibleNumberParseResulthandleMultipleSeparators(String numberStr, char separator) Handle numbers with multiple separators.protected abstract FlexibleNumberParseResulthandleSingleNonAmbiguous(String numberStr) Handle numbers where the separator separates digits in a non-3-digit pattern.protected final FlexibleNumberParseResulthandleSingleSeparatorType(String numberStr, char separator, int count) Handle numbers with only one type of separator.protected final booleanisLikelyThousandsSeparator(String numberStr, int separatorIndex) Determine if a single separator with 3 digits after is likely a thousands separator.parseNumber(String numberStr, int commaCount, int periodCount) Parse a number string using this strategy's specific rules.protected final FlexibleNumberParseResultvalidateThousandsSeparatorPositions(String numberStr, char separator) Validate that thousands separators are positioned correctly.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.kigalisim.lang.localization.NumberParseUtilStrategy
canHandle
-
Constructor Details
-
SingleDelimiterTemplate
public SingleDelimiterTemplate()Constructs a new SingleDelimiterTemplate.
-
-
Method Details
-
parseNumber
Description copied from interface:NumberParseUtilStrategyParse a number string using this strategy's specific rules.- Specified by:
parseNumberin interfaceNumberParseUtilStrategy- Parameters:
numberStr- The cleaned number string (without sign)commaCount- Number of commas in the stringperiodCount- 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
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 stringperiodCount- 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 stringseparator- The separator character- Returns:
- FlexibleNumberParseResult containing either parsed number or error
-
handleLeadingSeparator
Handle numbers with a leading separator.- Parameters:
numberStr- The number string starting with separator- Returns:
- FlexibleNumberParseResult containing either parsed number or error
-
handleSingleNonAmbiguous
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 stringseparator- The separator characterseparatorIndex- The index of the separatordigitsBefore- 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 stringseparator- The separator charactercount- Number of occurrences of the separator- Returns:
- FlexibleNumberParseResult containing either parsed number or error
-
isLikelyThousandsSeparator
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 stringseparatorIndex- 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 stringseparator- The thousands separator character- Returns:
- FlexibleNumberParseResult with success or error
-