Class Automaton.Builder

  • Enclosing class:
    Automaton

    public static class Automaton.Builder
    extends java.lang.Object
    Records new states and transitions and then finish() creates the Automaton. Use this when you cannot create the Automaton directly because it's too restrictive to have to add all transitions leaving each state at once.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.BitSet isAccept  
      private int nextState  
      private int nextTransition  
      private Sorter sorter
      Sorts transitions first then min label ascending, then max label ascending, then dest ascending
      private int[] transitions  
    • Constructor Summary

      Constructors 
      Constructor Description
      Builder()
      Default constructor, pre-allocating for 16 states and transitions.
      Builder​(int numStates, int numTransitions)
      Constructor which creates a builder with enough space for the given number of states and transitions.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addEpsilon​(int source, int dest)
      Add a [virtual] epsilon transition between source and dest.
      void addTransition​(int source, int dest, int label)
      Add a new transition with min = max = label.
      void addTransition​(int source, int dest, int min, int max)
      Add a new transition with the specified source, dest, min, max.
      void copy​(Automaton other)
      Copies over all states/transitions from other.
      void copyStates​(Automaton other)
      Copies over all states from other.
      int createState()
      Create a new state.
      Automaton finish()
      Compiles all added states and transitions into a new Automaton and returns it.
      int getNumStates()
      How many states this automaton has.
      boolean isAccept​(int state)
      Returns true if this state is an accept state.
      void setAccept​(int state, boolean accept)
      Set or clear this state as an accept state.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • nextState

        private int nextState
      • isAccept

        private final java.util.BitSet isAccept
      • transitions

        private int[] transitions
      • nextTransition

        private int nextTransition
      • sorter

        private final Sorter sorter
        Sorts transitions first then min label ascending, then max label ascending, then dest ascending
    • Constructor Detail

      • Builder

        public Builder()
        Default constructor, pre-allocating for 16 states and transitions.
      • Builder

        public Builder​(int numStates,
                       int numTransitions)
        Constructor which creates a builder with enough space for the given number of states and transitions.
        Parameters:
        numStates - Number of states.
        numTransitions - Number of transitions.
    • Method Detail

      • addTransition

        public void addTransition​(int source,
                                  int dest,
                                  int label)
        Add a new transition with min = max = label.
      • addTransition

        public void addTransition​(int source,
                                  int dest,
                                  int min,
                                  int max)
        Add a new transition with the specified source, dest, min, max.
      • addEpsilon

        public void addEpsilon​(int source,
                               int dest)
        Add a [virtual] epsilon transition between source and dest. Dest state must already have all transitions added because this method simply copies those same transitions over to source.
      • finish

        public Automaton finish()
        Compiles all added states and transitions into a new Automaton and returns it.
      • createState

        public int createState()
        Create a new state.
      • setAccept

        public void setAccept​(int state,
                              boolean accept)
        Set or clear this state as an accept state.
      • isAccept

        public boolean isAccept​(int state)
        Returns true if this state is an accept state.
      • getNumStates

        public int getNumStates()
        How many states this automaton has.
      • copy

        public void copy​(Automaton other)
        Copies over all states/transitions from other.
      • copyStates

        public void copyStates​(Automaton other)
        Copies over all states from other.