/** * Unwraps an iterator, returning an array. * * <p> * This method iterates over the given type-specific iterator and returns an * array containing the elements returned by the iterator. * * @param i * a type-specific iterator. * @return an array containing the elements returned by the iterator. */ public static byte[] unwrap(final ByteIterator i) { return unwrap(i, Integer.MAX_VALUE); } /**
/** * Creates a new array list and fills it with a given collection. * * @param c * a collection that will be used to fill the array list. */ public ByteArrayList(final Collection<? extends Byte> c) { this(c.size()); size = ByteIterators.unwrap(ByteIterators.asByteIterator(c.iterator()), a); } /**
/** * Concatenates all iterators contained in an array. * * <p> * This method returns an iterator that will enumerate in order the elements * returned by all iterators contained in the given array. * * @param a * an array of iterators. * @return an iterator obtained by concatenation. */ public static ByteIterator concat(final ByteIterator a[]) { return concat(a, 0, a.length); } /**
/** * Creates a new tree set using elements provided by an iterator. * * @param i * an iterator whose elements will fill the set. */ public ByteAVLTreeSet(final Iterator<?> i) { this(ByteIterators.asByteIterator(i)); } /**
@Override public ByteListIterator listIterator(final int i) { return ByteIterators.unmodifiable(list.listIterator(i)); } @Override
/** * Pours an iterator, returning a type-specific list. * * <p> * This method iterates over the given type-specific iterator and returns a list * containing the returned elements. Iteration on the returned list is * guaranteed to produce the elements in the same order in which they appeared * in the iterator. * * @param i * a type-specific iterator. * @return a type-specific list containing the returned elements. */ public static ByteList pour(final ByteIterator i) { return pour(i, Integer.MAX_VALUE); } private static class IteratorWrapper implements ByteIterator {
@Override public ByteListIterator listIterator() { return ByteIterators.singleton(element); } @Override
public static boolean any(final ByteIterator iterator, final java.util.function.IntPredicate predicate) { return indexOf(iterator, predicate) != -1; } public static boolean all(final ByteIterator iterator, final java.util.function.IntPredicate predicate) {
/** * Creates a new tree set using elements provided by an iterator. * * @param i * an iterator whose elements will fill the set. */ public ByteRBTreeSet(final Iterator<?> i) { this(ByteIterators.asByteIterator(i)); } /**
@Override public ByteIterator iterator() { return ByteIterators.unmodifiable(collection.iterator()); } @Override
/** * Pours an iterator into a type-specific collection. * * <p> * This method iterates over the given type-specific iterator and adds the * returned elements to the given collection. * * @param i * a type-specific iterator. * @param s * a type-specific collection. * @return the number of elements poured. Note that this is the number of * elements returned by the iterator, which is not necessarily the * number of elements that have been added to the collection (because of * duplicates). */ public static int pour(final ByteIterator i, final ByteCollection s) { return pour(i, s, Integer.MAX_VALUE); } /**
@Override public ByteListIterator iterator() { return ByteIterators.singleton(element); } @Override
/** * Unwraps an iterator into an array. * * <p> * This method iterates over the given type-specific iterator and stores the * elements returned in the given array. The iteration will stop when the * iterator has no more elements or when the end of the array has been reached. * * @param i * a type-specific iterator. * @param array * an array to contain the output of the iterator. * @return the number of elements unwrapped. */ public static int unwrap(final ByteIterator i, final byte array[]) { return unwrap(i, array, 0, array.length); } /**
/** * Creates a new hash set with {@link Hash#DEFAULT_LOAD_FACTOR} as load factor * using elements provided by an iterator. * * @param i * an iterator whose elements will fill the set. * @param strategy * the strategy. */ public ByteOpenCustomHashSet(final Iterator<?> i, final it.unimi.dsi.fastutil.bytes.ByteHash.Strategy strategy) { this(ByteIterators.asByteIterator(i), strategy); } /**
@Override public ByteListIterator listIterator() { return ByteIterators.unmodifiable(list.listIterator()); } @Override
/** * Pours an iterator, returning a type-specific list, with a limit on the number * of elements. * * <p> * This method iterates over the given type-specific iterator and returns a * type-specific list containing the returned elements (up to {@code max}). * Iteration on the returned list is guaranteed to produce the elements in the * same order in which they appeared in the iterator. * * * @param i * a type-specific iterator. * @param max * the maximum number of elements to be poured. * @return a type-specific list containing the returned elements, up to * {@code max}. */ public static ByteList pour(final ByteIterator i, int max) { final ByteArrayList l = new ByteArrayList(); pour(i, l, max); l.trim(); return l; } /**
/** * Generates a byte array by reading the provided stream up to exhaustion, and passes the result * to {@link #fromByteArray(byte[])}. */ @Override public J fromInputStream( InputStream inputStream ) throws IllegalArgumentException, IOException { return fromByteArray( ByteIterators.unwrap( BinIO.asByteIterator( new DataInputStream( inputStream ) ) ) ); }
/** * Creates a new hash set using elements provided by an iterator. * * @param i * an iterator whose elements will fill the set. * @param f * the load factor. */ public ByteOpenHashSet(final Iterator<?> i, final float f) { this(ByteIterators.asByteIterator(i), f); } /**
@Override public ByteBidirectionalIterator iterator() { return ByteIterators.unmodifiable(sortedSet.iterator()); } @Override
/** * Creates a new array list and fills it with a given type-specific collection. * * @param c * a type-specific collection that will be used to fill the array * list. */ public ByteArrayList(final ByteCollection c) { this(c.size()); size = ByteIterators.unwrap(c.iterator(), a); } /**