Class FrequencyTrie.Builder<V>

java.lang.Object
org.egothor.stemmer.FrequencyTrie.Builder<V>
Type Parameters:
V - value type
Enclosing class:
FrequencyTrie<V>

public static final class FrequencyTrie.Builder<V> extends Object
Builder of FrequencyTrie.

The builder is intentionally mutable and optimized for repeated put(String, Object) calls. The final trie is created by build(), which performs bottom-up subtree reduction and converts the structure to a compact immutable representation optimized for read operations.

  • Constructor Details

    • Builder

      public Builder(IntFunction<V[]> arrayFactory, ReductionSettings reductionSettings)
      Creates a new builder with the provided settings.

      This constructor preserves the historical Egothor behavior and therefore traverses logical keys from their end toward their beginning.

      Parameters:
      arrayFactory - array factory
      reductionSettings - reduction configuration
      Throws:
      NullPointerException - if any argument is null
    • Builder

      public Builder(IntFunction<V[]> arrayFactory, ReductionSettings reductionSettings, WordTraversalDirection traversalDirection)
      Creates a new builder with the provided settings and explicit traversal direction.
      Parameters:
      arrayFactory - array factory
      reductionSettings - reduction configuration
      traversalDirection - logical key traversal direction
      Throws:
      NullPointerException - if any argument is null
    • Builder

      public Builder(IntFunction<V[]> arrayFactory, ReductionSettings reductionSettings, WordTraversalDirection traversalDirection, CaseProcessingMode caseProcessingMode)
      Creates a new builder with the provided settings, explicit traversal direction, and explicit case processing mode.
      Parameters:
      arrayFactory - array factory
      reductionSettings - reduction configuration
      traversalDirection - logical key traversal direction
      caseProcessingMode - dictionary case processing mode
      Throws:
      NullPointerException - if any argument is null
    • Builder

      public Builder(IntFunction<V[]> arrayFactory, ReductionSettings reductionSettings, WordTraversalDirection traversalDirection, CaseProcessingMode caseProcessingMode, DiacriticProcessingMode diacriticProcessingMode)
      Creates a new builder with the provided settings, explicit traversal direction, explicit case processing mode, and explicit diacritic processing mode.
      Parameters:
      arrayFactory - array factory
      reductionSettings - reduction configuration
      traversalDirection - logical key traversal direction
      caseProcessingMode - dictionary case processing mode
      diacriticProcessingMode - dictionary diacritic processing mode
      Throws:
      NullPointerException - if any argument is null
    • Builder

      public Builder(IntFunction<V[]> arrayFactory, ReductionMode reductionMode)
      Creates a new builder using default thresholds for the supplied reduction mode.

      This constructor preserves the historical Egothor behavior and therefore traverses logical keys from their end toward their beginning.

      Parameters:
      arrayFactory - array factory
      reductionMode - reduction mode
      Throws:
      NullPointerException - if any argument is null
    • Builder

      public Builder(IntFunction<V[]> arrayFactory, ReductionMode reductionMode, WordTraversalDirection traversalDirection)
      Creates a new builder using default thresholds for the supplied reduction mode and explicit traversal direction.
      Parameters:
      arrayFactory - array factory
      reductionMode - reduction mode
      traversalDirection - logical key traversal direction
      Throws:
      NullPointerException - if any argument is null
  • Method Details

    • put

      public FrequencyTrie.Builder<V> put(String key, V value)
      Stores a value for the supplied key and increments its local frequency.

      Values are stored at the node addressed by the full key. Since trie values may also appear on internal nodes, an empty key is valid and stores a value directly at the root.

      Parameters:
      key - key
      value - value
      Returns:
      this builder
      Throws:
      NullPointerException - if key or value is null
    • build

      public FrequencyTrie<V> build()
      Builds a compiled read-only trie.
      Returns:
      compiled trie
    • put

      public FrequencyTrie.Builder<V> put(String key, V value, int count)
      Stores a value for the supplied key and increments its local frequency by the specified positive count.

      Values are stored at the node addressed by the full key. Since trie values may also appear on internal nodes, an empty key is valid and stores a value directly at the root.

      This method is functionally equivalent to calling put(String, Object) repeatedly count times, but it avoids unnecessary repeated map updates and is therefore preferable for bulk reconstruction from compiled tries or other aggregated sources.

      Parameters:
      key - key
      value - value
      count - positive frequency increment
      Returns:
      this builder
      Throws:
      NullPointerException - if key or value is null
      IllegalArgumentException - if count is less than 1