List of usage examples for org.apache.commons.lang3.mutable MutableLong toLong
public Long toLong()
From source file:enumj.Reversible.java
/** * Applies a {@code Enumerator.map(BiFunction)} operation * upon {@code source}, in reverse if necessary. * * @param <E> type of unmapped enumerated elements. * @param <R> type of mapped enumerated elements. * @param source {@link Enumerator} to apply the operation on. * @param mapper {@link BiFunction} to apply. * @param reversed true if the operation is applied in reverse, * false otherwise.//from w ww .jav a2 s . c o m * @return mapped {@code Enumerator}. */ static <E, R> Enumerator<R> map(Enumerator<E> source, BiFunction<? super E, ? super Long, ? extends R> mapper, boolean reversed) { Checks.ensureNotNull(mapper, Messages.NULL_ENUMERATOR_MAPPER); final MutableLong index = new MutableLong(0); final Function<E, R> fun = e -> { final R result = mapper.apply(e, index.toLong()); index.increment(); return result; }; if (reversed) { final PipeEnumerator pipe = (PipeEnumerator) source; return pipe.reversedMap(fun); } return source.map(fun); }