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

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

Introduction

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

Prototype

public void addTransition(int source, int dest, int label) 

Source Link

Document

Add a new transition with min = max = label.

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 w  w  w .ja  va  2  s.co m*/
    }
    automaton.setAccept(lastState, true);
    automaton.addTransition(lastState, lastState, 0, 255);
    automaton.finishState();
    assert automaton.isDeterministic();
    return automaton;
}