public Node find(Condition condition) { for (Iterator iterator = iterator(); iterator.hasNext(); ) { if (condition.check(iterator.next())) { return iterator.current(); } } return null; }
private static String format(List list) { StringBuilder builder = new StringBuilder(); builder.append('['); Iterator it = list.iterator(); while (it.hasNext()) { Map.Entry entry = (Map.Entry) it.next(); builder.append(format(entry.getValue())); if (it.hasNext()) { builder.append(", "); } } builder.append(']'); return builder.toString(); }
private static String format(Map map) { StringBuilder builder = new StringBuilder(); builder.append('{'); Iterator it = map.entrySet().iterator(); while (it.hasNext()) { Map.Entry entry = (Map.Entry) it.next(); builder.append(entry.getKey()).append(": ").append(format(entry.getValue())); if (it.hasNext()) { builder.append(", "); } } builder.append('}'); return builder.toString(); }
public void forEach(Closure closure) { for (Iterator iterator = iterator(); iterator.hasNext(); ) { closure.execute(iterator.next()); } }