java.util.PrimitiveIterator Maven / Gradle / Ivy
The newest version!
/*
* Copyright 2015 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package java.util;
import static javaemul.internal.InternalPreconditions.checkNotNull;
import java.util.function.Consumer;
import java.util.function.DoubleConsumer;
import java.util.function.IntConsumer;
import java.util.function.LongConsumer;
/**
* See
* the official Java API doc for details.
*
* @param element type
* @param consumer type
*/
public interface PrimitiveIterator extends Iterator {
void forEachRemaining(C consumer);
/**
* See
* the official Java API doc for details.
*/
interface OfDouble extends PrimitiveIterator {
double nextDouble();
@Override
default Double next() {
return nextDouble();
}
@Override
default void forEachRemaining(DoubleConsumer consumer) {
checkNotNull(consumer);
while (hasNext()) {
consumer.accept(nextDouble());
}
}
@Override
default void forEachRemaining(Consumer super Double> consumer) {
if (consumer instanceof DoubleConsumer) {
forEachRemaining((DoubleConsumer) consumer);
} else {
forEachRemaining((DoubleConsumer) consumer::accept);
}
}
}
/**
* See
* the official Java API doc for details.
*/
interface OfInt extends PrimitiveIterator {
int nextInt();
@Override
default Integer next() {
return nextInt();
}
@Override
default void forEachRemaining(IntConsumer consumer) {
checkNotNull(consumer);
while (hasNext()) {
consumer.accept(nextInt());
}
}
@Override
default void forEachRemaining(Consumer super Integer> consumer) {
if (consumer instanceof IntConsumer) {
forEachRemaining((IntConsumer) consumer);
} else {
forEachRemaining((IntConsumer) consumer::accept);
}
}
}
/**
* See
* the official Java API doc for details.
*/
interface OfLong extends PrimitiveIterator {
long nextLong();
@Override
default Long next() {
return nextLong();
}
@Override
default void forEachRemaining(LongConsumer consumer) {
checkNotNull(consumer);
while (hasNext()) {
consumer.accept(nextLong());
}
}
@Override
default void forEachRemaining(Consumer super Long> consumer) {
if (consumer instanceof LongConsumer) {
forEachRemaining((LongConsumer) consumer);
} else {
forEachRemaining((LongConsumer) consumer::accept);
}
}
}
}