Class FrequencyTrieBuilders

java.lang.Object
org.egothor.stemmer.FrequencyTrieBuilders

public final class FrequencyTrieBuilders extends Object
Factory utilities related to FrequencyTrie.Builder.

This helper reconstructs writable builders from compiled read-only tries. The reconstruction preserves the semantics and local counts of the compiled trie as currently stored, which makes it suitable for subsequent modifications followed by recompilation.

Reconstruction operates on the compiled form. Therefore, if the compiled trie was produced using a reduction mode that merged semantically equivalent subtrees, the recreated builder reflects that reduced compiled state rather than the exact original unreduced insertion history.

  • Method Details

    • copyOf

      public static <V> FrequencyTrie.Builder<V> copyOf(FrequencyTrie<V> source, IntFunction<V[]> arrayFactory, ReductionSettings reductionSettings)
      Reconstructs a new writable builder from a compiled read-only trie.

      The returned builder contains the same key-local value counts as the supplied compiled trie. Callers may continue modifying the returned builder and then compile a new FrequencyTrie instance.

      Type Parameters:
      V - value type
      Parameters:
      source - source compiled trie
      arrayFactory - array factory for the reconstructed builder
      reductionSettings - reduction settings to associate with the new builder
      Returns:
      reconstructed writable builder
      Throws:
      NullPointerException - if any argument is null
    • copyOf

      public static <V> FrequencyTrie.Builder<V> copyOf(FrequencyTrie<V> source, IntFunction<V[]> arrayFactory, ReductionMode reductionMode)
      Reconstructs a new writable builder from a compiled read-only trie using default settings for the supplied reduction mode.
      Type Parameters:
      V - value type
      Parameters:
      source - source compiled trie
      arrayFactory - array factory for the reconstructed builder
      reductionMode - reduction mode to associate with the new builder
      Returns:
      reconstructed writable builder
      Throws:
      NullPointerException - if any argument is null