@SuppressWarnings("unchecked") @Override public <O> List<O> asList() throws E { return this.iterable.aggregate(new ArrayList<O>(), (l, t) -> { l.add((O) t); return l; }); }
@Override public Iterable<T> asIterable() throws E { return this.iterable.aggregate(new LinkedList<T>(), (l, t) -> { l.add(t); return l; }); }
@SuppressWarnings("unchecked") @Override public <O> Set<O> asSet() throws E { return this.iterable.aggregate(new LinkedHashSet<O>(), (l, t) -> { l.add((O) t); return l; }); }
@Override public <K, V> Map<K, V> asMap(final IFactory<T, K, E> keyFactrory, final IFactory<T, V, E> valueFactrory) throws E { return this.iterable.aggregate(new LinkedHashMap<K, V>(), (l, t) -> { l.put(keyFactrory.create(t), valueFactrory.create(t)); return l; }); }
@Override public <O> IOptional<O, E> aggregate(final O identity, final IAggregator<O, T, O, E> aggegator) { try { return Optional.of(this.exceptionClass, this.iterable.aggregate(identity, aggegator)); } catch (final Exception exception) { return optional(this.exceptionClass, exception); } }