CompiledAutomaton (Lucene 10.5.1 core API)
Description: declaration: package: org.apache.lucene.util.automaton, class: CompiledAutomaton

Package org.apache.lucene.util.automaton

# Class CompiledAutomaton

java.lang.Object
org.apache.lucene.util.automaton.CompiledAutomaton

All Implemented Interfaces:
  `Accountable`

public class CompiledAutomaton extends Object implements Accountable
Immutable class holding compiled details for a given Automaton. The Automaton could either be deterministic or non-deterministic, For deterministic automaton, it must not have dead states but is not necessarily minimal. And will be executed using `ByteRunAutomaton` For non-deterministic automaton, it will be executed using `NFARunAutomaton`

WARNING: This API is experimental and might change in incompatible ways in the next release.

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `static enum`
  `CompiledAutomaton.AUTOMATON_TYPE`
  Automata are compiled into different internal forms for the most efficient execution depending upon the language they accept.

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `final Automaton`
  `automaton`
  Two dimensional array of transitions, indexed by state number for traversal.
  `final BytesRef`
  `commonSuffixRef`
  Shared common suffix accepted by the automaton.
  `final boolean`
  `finite`
  Indicates if the automaton accepts a finite set of strings.
  `final ByteRunAutomaton`
  `runAutomaton`
  Matcher for quickly determining if a byte[] is accepted.
  `final int`
  `sinkState`
  Which state, if any, accepts all suffixes, else -1.
  `final BytesRef`
  `term`
  For `CompiledAutomaton.AUTOMATON_TYPE.SINGLE` this is the singleton term.
  `final CompiledAutomaton.AUTOMATON_TYPE`
  `type`
  If simplify is true this will be the "simplified" type; else, this is NORMAL

  ### Fields inherited from interface org.apache.lucene.util.Accountable

  `NULL_ACCOUNTABLE`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `CompiledAutomaton(Automaton automaton)`
  Create this, passing simplify=true, so that we try to simplify the automaton.
  `CompiledAutomaton(Automaton automaton, boolean finite, boolean simplify)`
  Create this.
  `CompiledAutomaton(Automaton automaton, boolean finite, boolean simplify, boolean isBinary)`
  Create this.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `boolean`
  `equals(Object obj)`
  `BytesRef`
  `floor(BytesRef input, BytesRefBuilder output)`
  Finds largest term accepted by this Automaton, that's <= the provided input term.
  `ByteRunnable`
  `getByteRunnable()`
  Get a `ByteRunnable` instance, it will be different depending on whether a NFA or DFA is passed in, and does not guarantee returning non-null object
  `TermsEnum`
  `getTermsEnum(Terms terms)`
  Return a `TermsEnum` intersecting the provided `Terms` with the terms accepted by this automaton.
  `TransitionAccessor`
  `getTransitionAccessor()`
  Get a `TransitionAccessor` instance, it will be different depending on whether a NFA or DFA is passed in, and does not guarantee returning non-null object
  `int`
  `hashCode()`
  `long`
  `ramBytesUsed()`
  Returns an estimate of the JVM heap memory used by this object in bytes.
  `void`
  `visit(QueryVisitor visitor, Query parent, String field)`
  Report back to a QueryVisitor how this automaton matches terms

  ### Methods inherited from class java.lang.Object

  `clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait`

  ### Methods inherited from interface org.apache.lucene.util.Accountable

  `getChildResources`

- ## Field Details

  - ### type

    public final CompiledAutomaton.AUTOMATON_TYPE type
    If simplify is true this will be the "simplified" type; else, this is NORMAL

  - ### term

    public final BytesRef term
    For `CompiledAutomaton.AUTOMATON_TYPE.SINGLE` this is the singleton term.

  - ### runAutomaton

    public final ByteRunAutomaton runAutomaton
    Matcher for quickly determining if a byte[] is accepted. only valid for `CompiledAutomaton.AUTOMATON_TYPE.NORMAL`.

  - ### automaton

    public final Automaton automaton
    Two dimensional array of transitions, indexed by state number for traversal. The state numbering is consistent with `runAutomaton`. Only valid for `CompiledAutomaton.AUTOMATON_TYPE.NORMAL`.

  - ### commonSuffixRef

    public final BytesRef commonSuffixRef
    Shared common suffix accepted by the automaton. Only valid for `CompiledAutomaton.AUTOMATON_TYPE.NORMAL`, and only when the automaton accepts an infinite language. This will be null if the common prefix is length 0.

  - ### finite

    public final boolean finite
    Indicates if the automaton accepts a finite set of strings. Only valid for `CompiledAutomaton.AUTOMATON_TYPE.NORMAL`.

  - ### sinkState

    public final int sinkState
    Which state, if any, accepts all suffixes, else -1.

- ## Constructor Details

  - ### CompiledAutomaton

    public CompiledAutomaton(Automaton automaton)
    Create this, passing simplify=true, so that we try to simplify the automaton.

  - ### CompiledAutomaton

    public CompiledAutomaton(Automaton automaton, boolean finite, boolean simplify)
    Create this. If simplify is true, we run possibly expensive operations to determine if the automaton is one the cases in `CompiledAutomaton.AUTOMATON_TYPE`. Set finite to true if the automaton is finite, otherwise set to false if infinite or you don't know.

  - ### CompiledAutomaton

    public CompiledAutomaton(Automaton automaton, boolean finite, boolean simplify, boolean isBinary)
    Create this. If simplify is true, we run possibly expensive operations to determine if the automaton is one the cases in `CompiledAutomaton.AUTOMATON_TYPE`. Set finite to true if the automaton is finite, otherwise set to false if infinite or you don't know.

- ## Method Details

  - ### getTermsEnum

    public TermsEnum getTermsEnum(Terms terms) throws IOException
    Return a `TermsEnum` intersecting the provided `Terms` with the terms accepted by this automaton.
    Throws:
      `IOException`

  - ### visit

    public void visit(QueryVisitor visitor, Query parent, String field)
    Report back to a QueryVisitor how this automaton matches terms

  - ### floor

    public BytesRef floor(BytesRef input, BytesRefBuilder output)
    Finds largest term accepted by this Automaton, that's <= the provided input term. The result is placed in output; it's fine for output and input to point to the same bytes. The returned result is either the provided output, or null if there is no floor term (ie, the provided input term is before the first term accepted by this Automaton).

  - ### getByteRunnable

    public ByteRunnable getByteRunnable()
    Get a `ByteRunnable` instance, it will be different depending on whether a NFA or DFA is passed in, and does not guarantee returning non-null object

  - ### getTransitionAccessor

    public TransitionAccessor getTransitionAccessor()
    Get a `TransitionAccessor` instance, it will be different depending on whether a NFA or DFA is passed in, and does not guarantee returning non-null object

  - ### hashCode

    public int hashCode()
    Overrides:
      `hashCode` in class `Object`

  - ### equals

    public boolean equals(Object obj)
    Overrides:
      `equals` in class `Object`

  - ### ramBytesUsed

    public long ramBytesUsed()
    Description copied from interface: `Accountable`
    Returns an estimate of the JVM heap memory used by this object in bytes. The method name uses "ram" for historical reasons; only JVM heap memory should be reported. Off-heap resources such as memory-mapped files or native direct buffers should not be included. Negative values are illegal.
    Specified by:
      `ramBytesUsed` in interface `Accountable`