Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright 2016 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.checkCriticalElement;
import static javaemul.internal.InternalPreconditions.checkCriticalState;
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.
*
* Since it's hard to implement parallel algorithms in the browser environment
* and to keep code simple, implementation does not provide splitting.
*/
public final class Spliterators {
private abstract static class BaseSpliterator>
implements Spliterator {
private final int characteristics;
private long sizeEstimate;
BaseSpliterator(long size, int characteristics) {
this.sizeEstimate = size;
this.characteristics = (characteristics & Spliterator.SIZED) != 0 ?
characteristics | Spliterator.SUBSIZED : characteristics;
}
public int characteristics() {
return characteristics;
}
public long estimateSize() {
return sizeEstimate;
}
public S trySplit() {
// see javadoc for java.util.Spliterator
return null;
}
}
/**
* See
* the official Java API doc for details.
*/
public abstract static class AbstractSpliterator
extends BaseSpliterator> implements Spliterator {
protected AbstractSpliterator(long size, int characteristics) {
super(size, characteristics);
}
}
/**
* See
* the official Java API doc for details.
*/
public abstract static class AbstractDoubleSpliterator
extends BaseSpliterator implements Spliterator.OfDouble {
protected AbstractDoubleSpliterator(long size, int characteristics) {
super(size, characteristics);
}
}
/**
* See
* the official Java API doc for details.
*/
public abstract static class AbstractIntSpliterator
extends BaseSpliterator implements Spliterator.OfInt {
protected AbstractIntSpliterator(long size, int characteristics) {
super(size, characteristics);
}
}
/**
* See
* the official Java API doc for details.
*/
public abstract static class AbstractLongSpliterator
extends BaseSpliterator implements Spliterator.OfLong {
protected AbstractLongSpliterator(long size, int characteristics) {
super(size, characteristics);
}
}
@SuppressWarnings("unchecked")
public static Spliterator emptySpliterator() {
return (Spliterator) EmptySpliterator.OF_REF;
}
public static Spliterator.OfDouble emptyDoubleSpliterator() {
return EmptySpliterator.OF_DOUBLE;
}
public static Spliterator.OfInt emptyIntSpliterator() {
return EmptySpliterator.OF_INT;
}
public static Spliterator.OfLong emptyLongSpliterator() {
return EmptySpliterator.OF_LONG;
}
public static Spliterator spliterator(Object[] array, int characteristics) {
return new ArraySpliterator<>(array, characteristics);
}
public static Spliterator spliterator(Object[] array, int fromIndex, int toIndex,
int characteristics) {
checkCriticalArrayBounds(fromIndex, toIndex, array.length);
return new ArraySpliterator<>(array, fromIndex, toIndex, characteristics);
}
public static Spliterator.OfInt spliterator(int[] array, int characteristics) {
return new IntArraySpliterator(array, characteristics);
}
public static Spliterator.OfInt spliterator(int[] array, int fromIndex, int toIndex,
int characteristics) {
checkCriticalArrayBounds(fromIndex, toIndex, array.length);
return new IntArraySpliterator(array, fromIndex, toIndex, characteristics);
}
public static Spliterator.OfLong spliterator(long[] array, int characteristics) {
return new LongArraySpliterator(array, characteristics);
}
public static Spliterator.OfLong spliterator(long[] array, int fromIndex, int toIndex,
int characteristics) {
checkCriticalArrayBounds(fromIndex, toIndex, array.length);
return new LongArraySpliterator(array, fromIndex, toIndex, characteristics);
}
public static Spliterator.OfDouble spliterator(double[] array, int characteristics) {
return new DoubleArraySpliterator(array, characteristics);
}
public static Spliterator.OfDouble spliterator(double[] array, int fromIndex, int toIndex,
int characteristics) {
checkCriticalArrayBounds(fromIndex, toIndex, array.length);
return new DoubleArraySpliterator(array, fromIndex, toIndex, characteristics);
}
public static Spliterator spliterator(Collection extends T> c, int characteristics) {
return new IteratorSpliterator<>(c, characteristics);
}
public static Spliterator spliterator(Iterator extends T> it, long size,
int characteristics) {
return new IteratorSpliterator<>(it, size, characteristics);
}
public static Spliterator spliteratorUnknownSize(Iterator extends T> it,
int characteristics) {
return new IteratorSpliterator<>(it, characteristics);
}
public static Spliterator.OfInt spliterator(PrimitiveIterator.OfInt it, long size,
int characteristics) {
return new IntIteratorSpliterator(it, size, characteristics);
}
public static Spliterator.OfInt spliteratorUnknownSize(PrimitiveIterator.OfInt it,
int characteristics) {
return new IntIteratorSpliterator(it, characteristics);
}
public static Spliterator.OfLong spliterator(PrimitiveIterator.OfLong it, long size,
int characteristics) {
return new LongIteratorSpliterator(it, size, characteristics);
}
public static Spliterator.OfLong spliteratorUnknownSize(PrimitiveIterator.OfLong it,
int characteristics) {
return new LongIteratorSpliterator(it, characteristics);
}
public static Spliterator.OfDouble spliterator(PrimitiveIterator.OfDouble it, long size,
int characteristics) {
return new DoubleIteratorSpliterator(it, size, characteristics);
}
public static Spliterator.OfDouble spliteratorUnknownSize(PrimitiveIterator.OfDouble it,
int characteristics) {
return new DoubleIteratorSpliterator(it, characteristics);
}
public static Iterator iterator(Spliterator extends T> spliterator) {
return new ConsumerIterator<>(spliterator);
}
public static PrimitiveIterator.OfDouble iterator(Spliterator.OfDouble spliterator) {
return new DoubleConsumerIterator(spliterator);
}
public static PrimitiveIterator.OfInt iterator(Spliterator.OfInt spliterator) {
return new IntConsumerIterator(spliterator);
}
public static PrimitiveIterator.OfLong iterator(Spliterator.OfLong spliterator) {
return new LongConsumerIterator(spliterator);
}
private abstract static class EmptySpliterator, C>
implements Spliterator {
static final Spliterator