Class DelegatingStemmer<P>

java.lang.Object
opennlp.tools.stemmer.DelegatingStemmer<P>
Type Parameters:
P - the per-thread payload: a bare delegate stemmer, or a delegate paired with per-thread working state such as a cache.
All Implemented Interfaces:
Stemmer
Direct Known Subclasses:
CachingStemmer, SharingStemmer

abstract class DelegatingStemmer<P> extends Object implements Stemmer
Shared plumbing for Stemmer wrappers that route each call to a per-thread payload minted from a StemmerFactory, following the OwnerOrPerThreadState pattern of the thread-safe *ME components. Subclasses differ only in the payload they carry per thread and in what Stemmer.stem(CharSequence) does with it.
  • Field Details

  • Constructor Details

    • DelegatingStemmer

      DelegatingStemmer(Supplier<P> init, Consumer<P> cleanup)
      Creates the payload holder and the owner payload.
      Parameters:
      init - Creates a payload: once for the owner during construction, and once for each other thread on its first call.
      cleanup - Resets the owner payload when the owner thread clears its state.
  • Method Details

    • requireFactory

      static StemmerFactory requireFactory(StemmerFactory factory)
      Validates a factory argument before it is captured by a subclass supplier, so a null factory fails at construction rather than on first use.
      Parameters:
      factory - The factory to validate. Must not be null.
      Returns:
      factory.
      Throws:
      IllegalArgumentException - Thrown if factory is null.
    • clearThreadLocalState

      public void clearThreadLocalState()
      Clears the calling thread's state to prevent classloader leaks in container environments: a per-thread payload is removed, and the owner payload is reset but stays referenced by this instance. Call when the thread is returned to a pool or the stemmer is no longer needed, mirroring clearThreadLocalState() on the thread-safe *ME components.