Interface LanguageHandler

All Known Implementing Classes:
EnglishLanguageHandler, ThaiLanguageHandler

public interface LanguageHandler
Interface for language-specific text conversion with self-contained language configuration.

Implement this interface to provide custom language conversion logic for the Thai Baht library. Each handler completely defines its language's behavior, including conversion rules and unit words. This design allows unlimited language extensibility without modifying core library code.

Implementation Guidelines

When implementing this interface:

  • The convert() method must return non-null text representation
  • Language metadata methods must return non-null values
  • Conversion must respect the configuration within the ThaiBaht instance
  • The implementation should be stateless and thread-safe

Built-in Handlers

The library provides default implementations:

Custom Language Example


 public class LaotianLanguageHandler implements LanguageHandler {
     @Override
     public String convert(ThaiBaht baht) {
         // Implement Laotian conversion logic
         return "Laotian text representation";
     }

     @Override
     public String getLanguageCode() { return "lo"; }

     @Override
     public String getLanguageName() { return "Laotian"; }

     @Override
     public String getUnitWord() { return "ກີບ"; } // Kip

     @Override
     public String getExactWord() { return "ເທົ່າ"; }

     @Override
     public String getSatangWord() { return "ແອັດ"; }

     @Override
     public String getNegativePrefix() { return "ລົບ"; }
 }

 // Usage:
 ThaiBahtConfig config = ThaiBahtConfig.builder(new LaotianLanguageHandler())
     .useUnit(true)
     .build();
 
Since:
2.0.0
Author:
Zazalng
See Also:
  • Method Details

    • convert

      String convert(ThaiBaht baht)
      Converts the amount in the given ThaiBaht instance to language-specific text.

      The implementation must respect the configuration options from baht.getConfig(), including unit word inclusion, custom format templates, and negative prefix settings.

      Parameters:
      baht - the ThaiBaht instance containing amount and configuration, never null
      Returns:
      the language-specific textual representation of the amount, never null
      Throws:
      NullPointerException - if baht is null
      IllegalArgumentException - if the amount is null or invalid
    • getLanguageCode

      String getLanguageCode()
      Returns the language code identifier for this handler.

      This is typically a two or three-letter ISO 639 code (e.g., "th" for Thai, "en" for English).

      Returns:
      the language code, never null or empty
    • getLanguageName

      String getLanguageName()
      Returns the human-readable name of this language.

      This is typically used for display and identification purposes.

      Returns:
      the language name (e.g., "Thai", "English"), never null or empty
    • getUnitWord

      String getUnitWord()
      Returns the currency unit word for the integer (baht) part.

      Examples:

      • Thai: "บาท" (Baht)
      • English: "Baht"
      • Laotian: "ກີບ" (Kip)
      Returns:
      the unit word, never null or empty
    • getExactWord

      String getExactWord()
      Returns the exact/only indicator word displayed when satang (fractional part) is zero.

      Examples:

      • Thai: "ถ้วน" (Exact/Full)
      • English: "Only"
      Returns:
      the exact indicator word, never null or empty
    • getSatangWord

      String getSatangWord()
      Returns the satang (fractional currency unit) word.

      Examples:

      • Thai: "สตางค์" (Satang)
      • English: "Satang"
      Returns:
      the satang unit word, never null or empty
    • getNegativePrefix

      String getNegativePrefix()
      Returns the default prefix applied to negative amounts.

      This prefix is used when the amount is negative, unless explicitly overridden via ThaiBahtConfig.Builder.setPrefix(String).

      Examples:

      • Thai: "ลบ" (Thai minus symbol)
      • English: "Minus"
      Returns:
      the negative prefix, never null or empty