Example usage for org.apache.lucene.util.automaton Automaton finishState

List of usage examples for org.apache.lucene.util.automaton Automaton finishState

Introduction

In this page you can find the example usage for org.apache.lucene.util.automaton Automaton finishState.

Prototype

public void finishState() 

Source Link

Document

Finishes the current state; call this once you are done adding transitions for a state.

Usage

From source file:com.lucene.MyPrefixQuery.java

License:Apache License

public static Automaton toAutomaton(BytesRef prefix) {
    final int numStatesAndTransitions = prefix.length + 1;
    final Automaton automaton = new Automaton(numStatesAndTransitions, numStatesAndTransitions);
    int lastState = automaton.createState();
    for (int i = 0; i < prefix.length; i++) {
        int state = automaton.createState();
        automaton.addTransition(lastState, state, prefix.bytes[prefix.offset + i] & 0xff);
        lastState = state;//from ww w . j  a v a 2  s  .  co m
    }
    automaton.setAccept(lastState, true);
    automaton.addTransition(lastState, lastState, 0, 255);
    automaton.finishState();
    assert automaton.isDeterministic();
    return automaton;
}