private static void addHoles(Automaton.Builder builder, RollingBuffer<Position> positions, int pos) { Position posData = positions.get(pos); Position prevPosData = positions.get(pos-1); while(posData.arriving == -1 || prevPosData.leaving == -1) { if (posData.arriving == -1) { posData.arriving = builder.createState(); builder.addTransition(posData.arriving, posData.leaving, POS_SEP); } if (prevPosData.leaving == -1) { if (pos == 1) { prevPosData.leaving = 0; } else { prevPosData.leaving = builder.createState(); } if (prevPosData.arriving != -1) { builder.addTransition(prevPosData.arriving, prevPosData.leaving, POS_SEP); } } builder.addTransition(prevPosData.leaving, posData.arriving, HOLE); pos--; if (pos <= 0) { break; } posData = prevPosData; prevPosData = positions.get(pos-1); } }
private static void addHoles(State startState, RollingBuffer<Position> positions, int pos) { Position posData = positions.get(pos); Position prevPosData = positions.get(pos-1); while(posData.arriving == null || prevPosData.leaving == null) { if (posData.arriving == null) { posData.arriving = new State(); posData.arriving.addTransition(new Transition(POS_SEP, posData.leaving)); } if (prevPosData.leaving == null) { if (pos == 1) { prevPosData.leaving = startState; } else { prevPosData.leaving = new State(); } if (prevPosData.arriving != null) { prevPosData.arriving.addTransition(new Transition(POS_SEP, prevPosData.leaving)); } } prevPosData.leaving.addTransition(new Transition(HOLE, posData.arriving)); pos--; if (pos <= 0) { break; } posData = prevPosData; prevPosData = positions.get(pos-1); } }