Skip to content

part 2 is done #57

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.Spliterator;
import java.util.Spliterators;
import java.util.function.Consumer;
import java.util.function.DoubleConsumer;

public class ZipWithIndexDoubleSpliterator extends Spliterators.AbstractSpliterator<IndexedDoublePair> {

Expand All @@ -22,35 +23,42 @@ private ZipWithIndexDoubleSpliterator(int firstIndex, OfDouble inner) {

@Override
public int characteristics() {
// TODO
throw new UnsupportedOperationException();
return inner.characteristics();
}

@Override
public boolean tryAdvance(Consumer<? super IndexedDoublePair> action) {
// TODO
throw new UnsupportedOperationException();
return inner.tryAdvance((DoubleConsumer) d -> {
final IndexedDoublePair pair = new IndexedDoublePair(currentIndex, d);
currentIndex = currentIndex + 1;
action.accept(pair);
});
}

@Override
public void forEachRemaining(Consumer<? super IndexedDoublePair> action) {
// TODO
throw new UnsupportedOperationException();
inner.forEachRemaining((DoubleConsumer) d -> {
final IndexedDoublePair pair = new IndexedDoublePair(currentIndex, d);
currentIndex = currentIndex + 1;
action.accept(pair);
});
}

@Override
public Spliterator<IndexedDoublePair> trySplit() {
// TODO
// if (inner.hasCharacteristics(???)) {
// use inner.trySplit
// } else

return super.trySplit();
if (inner.hasCharacteristics(Spliterator.SUBSIZED)) {
final OfDouble split = this.inner.trySplit();
if (split == null) return null;
final ZipWithIndexDoubleSpliterator result = new ZipWithIndexDoubleSpliterator(currentIndex, split);
currentIndex += split.estimateSize();
return result;
} else {
return super.trySplit();
}
}

@Override
public long estimateSize() {
// TODO
throw new UnsupportedOperationException();
return inner.estimateSize();
}
}