/** * Writes the definitions of all variable sets defined by the given bindings. */ protected void writeVarSets( int varSetLevel, Iterator<VarBinding> varBindings) { xmlWriter_.writeTagStart( "TABLE"); xmlWriter_.writeAttribute( "class", varSetLevel % 2 == 0? "light" : "dark"); xmlWriter_.writeTagEnd(); xmlWriter_.indent(); String varSet = ""; String varSetNext = ""; for( PeekingIterator<VarBinding> peekBindings = new PeekingIterator<VarBinding>( varBindings); peekBindings.hasNext(); varSet = varSetNext) { List<VarBinding> varSetBindings = new ArrayList<VarBinding>(); for( varSetNext = ""; peekBindings.hasNext() && (varSetNext = getVarSet( varSetLevel, peekBindings.peek())).equals( varSet); varSetBindings.add( peekBindings.next())); writeVarSet( varSet, varSetLevel, varSetBindings.iterator()); } xmlWriter_.unindent(); xmlWriter_.writeElementEnd( "TABLE"); }
public DOM transform(DOM dom) throws IOException { this.dom = new DOM(); this.dom.setLines(dom.getLines()); this.dom.setSource(dom.getSource()); iterator = new PeekingIterator<>(dom.iterator()); while (iterator.hasNext()) { Node n = iterator.next(); dispatch(n); } return this.dom; }
@Override public Iterator<Pair<State, String>> iterator() { return new Iterator<Pair<State, String>>() { private Iterator<State> states = ts.getNodes().iterator(); private State currentState = null; private PeekingIterator<String> alphabet = null; @Override public boolean hasNext() { while (true) { if (alphabet == null || !alphabet.hasNext()) { if (!states.hasNext()) return false; currentState = states.next(); alphabet = peekingIterator(ts.getAlphabet().iterator()); } else { if (!SeparationUtility.isEventEnabled(currentState, alphabet.peek())) return true; alphabet.next(); } } } @Override public Pair<State, String> next() { if (!hasNext()) throw new NoSuchElementException(); return new Pair<>(currentState, alphabet.next()); } @Override public void remove() { throw new UnsupportedOperationException(); } }; }
@Override public Iterator<Set<E>> iterator() { return new Iterator<Set<E>>() { private PeekingIterator<Set<E>> iter = peekingIterator(leaderToClass.values().iterator()); @Override public boolean hasNext() { // Skip all sets which have just a single entry Set<E> next = iter.peek(); while (next != null && next.size() == 1) { iter.next(); iter.remove(); next = iter.peek(); } return iter.hasNext(); } @Override public Set<E> next() { hasNext(); return Collections.unmodifiableSet(iter.next()); } @Override public void remove() { throw new UnsupportedOperationException(); } }; }
/** * Gets an iterator that supports one-element lookahead. * * @param <E> the element type * @param iterator the iterator to decorate, not null * @return a peeking iterator * @throws NullPointerException if the iterator is null * @since 4.0 */ public static <E> Iterator<E> peekingIterator(final Iterator<? extends E> iterator) { return PeekingIterator.peekingIterator(iterator); }