* Helper class that provides SplitIterators for normal and stream usage
*/
public class SPLIT_ITERATORS
{
#if PRIMITIVES
/**
* Creates A stream compatible split iterator without copying the original array or boxing
* @param array that should be wrapped into a split iterator
* @param characteristics characteristics properties of this spliterator's source or elements.
* @Type(T)
* @return a split iterator of a Stream compatible type
*/
public static GENERIC_KEY_BRACES JAVA_SPLIT_ITERATOR KEY_GENERIC_TYPE createArrayJavaSplititerator(KEY_TYPE[] array, int characteristics) { return createArrayJavaSplititerator(array, 0, array.length, characteristics);}
/**
* Creates A stream compatible split iterator without copying the original array or boxing
* @param array that should be wrapped into a split iterator
* @param size the maximum index within the array
* @param characteristics characteristics properties of this spliterator's source or elements.
* @Type(T)
* @return a split iterator of a Stream compatible type
* @throws IllegalStateException if the size is outside of the array size
*/
public static GENERIC_KEY_BRACES JAVA_SPLIT_ITERATOR KEY_GENERIC_TYPE createArrayJavaSplititerator(KEY_TYPE[] array, int size, int characteristics) { return createArrayJavaSplititerator(array, 0, size, characteristics);}
/**
* Creates A stream compatible split iterator without copying the original array or boxing
* @param array that should be wrapped into a split iterator
* @param offset the starting index of the array
* @param size the maximum index within the array
* @param characteristics characteristics properties of this spliterator's source or elements.
* @Type(T)
* @return a split iterator of a Stream compatible type
* @throws IllegalStateException the offset and size are outside of the arrays range
*/
public static GENERIC_KEY_BRACES JAVA_SPLIT_ITERATOR KEY_GENERIC_TYPE createArrayJavaSplititerator(KEY_TYPE[] array, int offset, int size, int characteristics) {
return new ArraySplitIteratorBRACES(array, offset, size, characteristics);
}
/**
* Creates a stream compatible split iterator without copying it or boxing it
* @param collection the collection that should be wrapped in a split iterator
* @param characteristics characteristics properties of this spliterator's source or elements.
* @Type(T)
* @return a split iterator of a Stream compatible type
*/
public static GENERIC_KEY_BRACES JAVA_SPLIT_ITERATOR KEY_GENERIC_TYPE createJavaSplititerator(COLLECTION KEY_GENERIC_TYPE collection, int characteristics) {
return new IteratorSpliteratorBRACES(collection, characteristics);
}
/**
* Creates a stream compatible split iterator without copying it or boxing it
* @param iterator the Iterator that should be wrapped in a split iterator
* @param characteristics characteristics properties of this spliterator's source or elements.
* @Type(T)
* @return a split iterator of a Stream compatible type
*/
public static GENERIC_KEY_BRACES JAVA_SPLIT_ITERATOR KEY_GENERIC_TYPE createUnknownJavaSplititerator(ITERATOR KEY_GENERIC_TYPE iterator, int characteristics) {
return new IteratorSpliteratorBRACES(iterator, characteristics);
}
/**
* Creates a stream compatible split iterator without copying it or boxing it
* @param iterator the collection that should be wrapped in a split iterator
* @param size the amount of elements in the iterator
* @param characteristics characteristics properties of this spliterator's source or elements.
* @Type(T)
* @return a split iterator of a Stream compatible type
*/
public static GENERIC_KEY_BRACES JAVA_SPLIT_ITERATOR KEY_GENERIC_TYPE createSizedJavaSplititerator(ITERATOR KEY_GENERIC_TYPE iterator, long size, int characteristics) {
return new IteratorSpliteratorBRACES(iterator, size, characteristics);
}
#endif
/**
* Creates a Type Specific SplitIterator to reduce boxing/unboxing
* @param array that should be wrapped into a split iterator
* @param characteristics characteristics properties of this spliterator's source or elements.
* @Type(T)
* @return a Type Specific SplitIterator
*/
public static GENERIC_KEY_BRACES SPLIT_ITERATOR KEY_GENERIC_TYPE createArraySplititerator(KEY_TYPE[] array, int characteristics) { return createArraySplititerator(array, 0, array.length, characteristics);}
/**
* Creates a Type Specific SplitIterator to reduce boxing/unboxing
* @param array that should be wrapped into a split iterator
* @param size the maximum index within the array
* @param characteristics characteristics properties of this spliterator's source or elements.
* @Type(T)
* @return a Type Specific SplitIterator
* @throws IllegalStateException if the size is outside of the array size
*/
public static GENERIC_KEY_BRACES SPLIT_ITERATOR KEY_GENERIC_TYPE createArraySplititerator(KEY_TYPE[] array, int size, int characteristics) { return createArraySplititerator(array, 0, size, characteristics);}
/**
* Creates a Type Specific SplitIterator to reduce boxing/unboxing
* @param array that should be wrapped into a split iterator
* @param offset the starting index of the array
* @param size the maximum index within the array
* @param characteristics characteristics properties of this spliterator's source or elements.
* @Type(T)
* @return a Type Specific SplitIterator
* @throws IllegalStateException the offset and size are outside of the arrays range
*/
public static GENERIC_KEY_BRACES SPLIT_ITERATOR KEY_GENERIC_TYPE createArraySplititerator(KEY_TYPE[] array, int offset, int size, int characteristics) {
return new TypeArraySplitIteratorBRACES(array, offset, size, characteristics);
}
/**
* Creates a Type Specific SplitIterator to reduce boxing/unboxing
* @param collection the collection that should be wrapped in a split iterator
* @param characteristics characteristics properties of this spliterator's source or elements.
* @Type(T)
* @return a Type Specific SplitIterator
*/
public static GENERIC_KEY_BRACES SPLIT_ITERATOR KEY_GENERIC_TYPE createSplititerator(COLLECTION KEY_GENERIC_TYPE collection, int characteristics) {
return new TypeIteratorSpliteratorBRACES(collection, characteristics);
}
/**
* Creates a Type Specific SplitIterator to reduce boxing/unboxing
* @param iterator the Iterator that should be wrapped in a split iterator
* @param characteristics characteristics properties of this spliterator's source or elements.
* @Type(T)
* @return a Type Specific SplitIterator
*/
public static GENERIC_KEY_BRACES SPLIT_ITERATOR KEY_GENERIC_TYPE createUnknownSplititerator(ITERATOR KEY_GENERIC_TYPE iterator, int characteristics) {
return new TypeIteratorSpliteratorBRACES(iterator, characteristics);
}
/**
* Creates a Type Specific SplitIterator to reduce boxing/unboxing
* @param iterator the collection that should be wrapped in a split iterator
* @param size the amount of elements in the iterator
* @param characteristics characteristics properties of this spliterator's source or elements.
* @Type(T)
* @return a Type Specific SplitIterator
*/
public static GENERIC_KEY_BRACES SPLIT_ITERATOR KEY_GENERIC_TYPE createSizedSplititerator(ITERATOR KEY_GENERIC_TYPE iterator, long size, int characteristics) {
return new TypeIteratorSpliteratorBRACES(iterator, size, characteristics);
}
static class TypeIteratorSpliterator KEY_GENERIC_TYPE implements SPLIT_ITERATOR KEY_GENERIC_TYPE {
static final int BATCH_UNIT = 1 << 10;
static final int MAX_BATCH = 1 << 25;
private final COLLECTION KEY_GENERIC_TYPE collection;
private ITERATOR KEY_GENERIC_TYPE it;
private final int characteristics;
private long est;
private int batch;
TypeIteratorSpliterator(COLLECTION KEY_GENERIC_TYPE collection, int characteristics) {