Package io.github.zazalng.handler
package io.github.zazalng.handler
Internal conversion handlers for transforming numeric amounts into language-specific text.
This package is internal (package-private) and not part of the public API.
Users should interact with this functionality only through the public API in
io.github.zazalng and io.github.zazalng.contracts packages.
v2.0.0 Architecture (NEW)
Version 2.0.0 introduces a handler-based architecture:
- LanguageHandler Interface: Public interface in contracts package for language implementations
- Built-in Handlers: ThaiLanguageHandler and EnglishLanguageHandler implement the interface with full conversion logic
- TextConverter Router: Routes conversion requests to the appropriate handler (delegating responsibility to handlers instead of routing on enum)
- FormatApplier: Applies custom format templates (works with handlers)
Package Contents
This package contains the internal implementation of the text conversion algorithm:
- TextConverter - Main routing dispatcher (simplified in v2.0.0)
- ThaiLanguageHandler (v2.0.0) - Thai conversion implementation
- EnglishLanguageHandler (v2.0.0) - English conversion implementation
- ThaiConvertHandler (legacy) - Original Thai logic (kept for reference)
- EnglishConvertHandler (legacy) - Original English logic (kept for reference)
- FormatApplier - Custom format template processor
Handler Responsibility (v2.0.0)
In v2.0.0, language handlers take full responsibility for:
- Amount normalization (precision handling to 2 decimal places)
- Language-specific digit and word conversion
- Negative amount prefix handling
- Unit word inclusion/exclusion based on config
- Format template application (if custom format is configured)
- Returning properly formatted text
Conversion Process (v2.0.0)
The simplified v2.0.0 flow:
- TextConverter.toBahtText() receives ThaiBaht instance
- Validates input (amount not null)
- Delegates to config.getLanguageHandler().convert()
- Handler performs complete conversion
- Returns formatted text
Before vs After Architecture
v1.4.0 (Old):
TextConverter (switch on Language enum) ├─ ThaiConvertHandler (static methods) └─ EnglishConvertHandler (static methods)
v2.0.0 (New):
TextConverter (delegates to handler)
└─ LanguageHandler (polymorphic dispatch)
├─ ThaiLanguageHandler (implements interface)
├─ EnglishLanguageHandler (implements interface)
└─ CustomLanguageHandler (user-implemented, no core changes!)
Performance Characteristics
Conversion algorithm maintains the same complexity as v1.4.0:
- Time Complexity: O(log n) where n is the magnitude
- Space Complexity: O(log n) for output string length
- No Performance Regression: Handler polymorphism has minimal overhead
Thread Safety
The conversion handlers are stateless and thread-safe:
- No mutable instance state maintained between calls
- All state is local to method invocations
- Configuration objects are immutable (passed in)
- Safe for concurrent use without synchronization
Creating Custom Handlers
Users can create custom language handlers by implementing LanguageHandler:
public class MyLanguageHandler implements LanguageHandler {
@Override
public String convert(ThaiBaht baht) {
// 1. Get amount and config
// 2. Normalize to 2 decimal places
// 3. Split into baht and satang parts
// 4. Convert each part to words
// 5. Apply configuration options
// 6. Return formatted text
}
// ... implement other 6 required methods
}
This package design allows for unlimited extensibility while keeping the core library clean and maintainable.- Since:
- 1.0
- Version:
- 2.0.0
- Author:
- Zazalng
- See Also:
-
ClassesClassDescriptionDeprecated.English language implementation of
LanguageHandler.Internal utility for applying custom format templates to baht/satang conversions.Internal router and dispatcher for converting numeric amounts to language-specific text.Deprecated.Thai language implementation ofLanguageHandler.