org.d2ab.sequence.EquivalentSizeSequence Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sequence Show documentation
Show all versions of sequence Show documentation
A lightweight alternative to Java 8 sequential Stream
The newest version!
package org.d2ab.sequence;
import org.d2ab.collection.SizedIterable;
import java.util.Iterator;
import java.util.function.Function;
/**
* A {@link Sequence} created from another sequence through a mapping function, which has the same size as the original
* {@link Sequence}.
*/
public class EquivalentSizeSequence implements Sequence {
private final SizedIterable original;
private final Function, Iterator> converter;
public EquivalentSizeSequence(SizedIterable original, Function, Iterator> converter) {
this.original = original;
this.converter = converter;
}
@Override
public Iterator iterator() {
return converter.apply(original.iterator());
}
@Override
public int size() {
return original.size();
}
@Override
public SizeType sizeType() {
return original.sizeType();
}
@Override
public boolean isEmpty() {
return original.isEmpty();
}
}