/** Print an iterator (destructive) */ public static <T> void print(final PrintStream out, Iterator<T> stream) { Action<T> x = new Action<T>() { @Override public void apply(T item) { out.println(item) ; } } ; apply(stream, x) ; }
/** Apply an action to every element of an iterator */ public void apply(Consumer<T> action) { apply(iterator, action) ; }
/** Print an iterator (destructive) */ public static <T> void print(final PrintStream out, Iterator<T> stream) { apply(stream, out::println) ; }
/** Print an iterator (destructive) */ public static <T> void print(final PrintStream out, Iterator<T> stream) { apply(stream, out::println) ; }
/** Apply an action to every element of an iterator */ public void apply(Consumer<T> action) { apply(iterator, action) ; }
public void apply(Action<T> action) { apply(iterator, action) ; }
public static <T> void print(final IndentedWriter out, List<T> list, final String sep) { Action<T> output = new Action<T>() { boolean first = true ; @Override public void apply(T item) { if ( ! first ) out.print(sep) ; out.print(item.toString()) ; first = false ; } } ; Iter.apply(list, output) ; }
public static <T> void apply(Iterable<? extends T> stream, Action<T> action) { apply(stream.iterator(), action) ; }
public static <T extends Printable> void print(IndentedWriter out, Iterable<? extends T> struct, String sep) { apply(struct.iterator(), new ActionPrint<T>(out, sep)) ; }
@Override public Set<ScopeEntry> findScopes() { Set<ScopeEntry> x = scope.findScopes() ; Iter.apply(x.iterator(), ScopeEntry.SetOpt) ; return x ; }
@Override public Map<String, String> getMappingCopyStr() { final Map<String, String> smap = new HashMap<String, String>(); ActionKeyValue<String, IRI> action = new ActionKeyValue<String, IRI>() { @Override public void apply(String key, IRI value) { String str = value.toString(); smap.put(key, str); } }; Iter.apply(getMapping(), action); return smap; }
@Override public void output(final IndentedWriter out, SerializationContext sCxt) { final String sep = "\n" ; final Consumer<Quad> strAction = new Consumer<Quad>() { boolean first = true ; @Override public void accept(Quad quad) { if ( ! first ) out.print(sep) ; first = false ; out.print(String.valueOf(quad)) ; } } ; apply(this.iterator(), strAction) ; }
/** Count the iterator (this is destructive on the iterator) */ public long count() { ActionCount<T> action = new ActionCount<T>() ; apply(action) ; return action.getCount() ; }
/** Count the iterator (this is destructive on the iterator) */ public long count() { ActionCount<T> action = new ActionCount<>() ; apply(action) ; return action.getCount() ; }
/** Count the iterator (this is destructive on the iterator) */ public long count() { ActionCount<T> action = new ActionCount<>() ; apply(action) ; return action.getCount() ; }
public static <T extends Printable> String printString(Iterable<? extends T> struct, String sep) { IndentedLineBuffer b = new IndentedLineBuffer() ; apply(struct.iterator(), new ActionPrint<T>(b, sep)) ; return b.asString() ; }