if (iterator.isSyncedWith(key)) return iterator.get(key);
/** * Don't let templates call this, but allow subclasses * and ManagedIterator to have access. * @return pop'ed iterator */ protected ManagedIterator pop() { ManagedIterator i = iterators.pop(); this.lastSyncedValues = i.getLastSyncedValues(); return i; }
/** * Finds the {@link ManagedIterator} with the specified name * if it is in this instance's iterator stack. * @param name loop name * @return loop iterator */ protected ManagedIterator findIterator(String name) { // look for the one with the specified name for (ManagedIterator iterator : iterators) { if (iterator.getName().equals(name)) { return iterator; } } return null; }
/** * This is just like {@link #stop()} except that the stop command is issued * <strong>only</strong> to the loop/iterator with the specified name. * If no such loop is found with that name, then no stop command is issued. * @param name loop name * @see #stop() */ public void stop(String name) { // just stop the matching one for (ManagedIterator iterator : iterators) { if (iterator.getName().equals(name)) { iterator.stop(); break; } } }
/** * Returns the number of items the specified loop has handled. So, if this * is the first iteration, then the count will be 1. If you {@link #skip} * ahead in this loop, those skipped iterations will still be included in * the count. * @param name loop name * @return loop items count */ public Integer getCount(String name) { // just tell the matching one to skip ManagedIterator iterator = findIterator(name); if (iterator != null) { return iterator.getCount(); } return null; }
/** * Asks the loop with the specified name for the current value * of the specified sync'ed iterator, if any. * @param name loop name * @param synced sync'ed Iterator name * @return current iterator value */ public Object get(String name, String synced) { // just ask the matching iterator for the sync'ed value ManagedIterator iterator = findIterator(name); if (iterator != null) { return iterator.get(synced); } return null; }
/** * @return {@code true} if the loop with the specified name * is on its first iteration. * @param name loop name */ public Boolean isFirst(String name) { // just tell the matching one to skip ManagedIterator iterator = findIterator(name); if (iterator != null) { return iterator.isFirst(); } return null; }
/** * @return {@code true} if the loop with the specified name * is on its last iteration. * @param name loop name */ public Boolean isLast(String name) { // just tell the matching one to skip ManagedIterator iterator = findIterator(name); if (iterator != null) { return iterator.isLast(); } return null; }
/** * Returns the number of items the current loop has handled. So, if this * is the first iteration, then the count will be 1. If you {@link #skip} * ahead in this loop, those skipped iterations will still be included in * the count. * @return items count */ public Integer getCount() { if (last != null) { return last.getCount(); } return null; }
private boolean hasNext(boolean popWhenDone) { // we don't if we've stopped if (stopped) { return false; } // we're not stopped, so do we have a next cached? if (this.next != null) { return true; } // try to get a next that satisfies the conditions // if there isn't one, return false; if there is, return true return cacheNext(popWhenDone); }
protected ManagedIterator manage(Iterator iterator, String name) { return new ManagedIterator(name, iterator, this); }
/** * @return the result of {@link #hasNext}. Exists to allow $loop.this.hasNext syntax. */ public boolean getHasNext() { return hasNext(false);//no need to pop, #foreach will always call hasNext() }
/** * @return true if the last element returned by {@link #next()} * is the last element available in the iterator being managed * which satisfies any/all {@link ActionCondition}s set for this * instance. Otherwise, returns false. */ public boolean isLast() { return !hasNext(false); }
/** * Directs this instance to stop iterating immediately prior to * any element equal to the specified Object. * @param compare value to stop at * @return This same {@link ManagedIterator} instance */ public ManagedIterator stop(Object compare) { return condition(new ActionCondition(Action.STOP, new Equals(compare))); }
/** * @return the result of {@link #isFirst}. Exists to allow $loop.this.first syntax. */ public boolean getFirst() { return isFirst(); }
@Override public String toString() { return ManagedIterator.class.getSimpleName()+':'+getName(); } }