/** * 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 IdentityArrayList(final Collection<? extends K> c) { this(c.size()); size = ObjectIterators.unwrap(c.iterator(), a); }
@Override public ObjectIterator<E> iterator() { return ObjectIterators.asObjectIterator(delegate.iterator()); }
/** * 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 <K> ObjectList<K> pour(final Iterator<K> i) { return pour(i, Integer.MAX_VALUE); } private static class IteratorWrapper<K> implements ObjectIterator<K> {
/** * 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 <K> ObjectIterator<K> concat(final ObjectIterator<? extends K> a[]) { return concat(a, 0, a.length); } /**
/** * 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 <K> int pour(final Iterator<K> i, final ObjectCollection<? super K> s) { return pour(i, s, Integer.MAX_VALUE); } /**
/** * 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 IdentityArrayList(final ObjectCollection<? extends K> c) { this(c.size()); size = ObjectIterators.unwrap(c.iterator(), a); }
@Override public ObjectIterator<Entry> iterator() { Iterator<Entry> iter = Iterators.transform(map.entrySet().iterator(), new Function<Map.Entry<Long, Double>, Entry>() { @Nullable @Override public Entry apply(@Nullable Map.Entry<Long, Double> input) { if (input == null) { return null; } return new AbstractLong2DoubleMap.BasicEntry(input.getKey(), input.getValue()); } }); return ObjectIterators.asObjectIterator(iter); }
/** * 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 <K> ObjectList<K> pour(final Iterator<K> i, int max) { final ObjectArrayList<K> l = new ObjectArrayList<>(); pour(i, l, max); l.trim(); return l; } /**
@Override public <T> T[] toArray(T[] a) { if (size() <= a.length) { ObjectIterators.unwrap(iterator(), a); return a; } else { return delegate.toArray(a); } }
@Override public ObjectIterator<E> iterator() { return ObjectIterators.asObjectIterator(delegate.iterator()); }
/** * 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 <K> K[] unwrap(final Iterator<? extends K> i) { return unwrap(i, Integer.MAX_VALUE); } /**
@Override public ObjectIterator<E> iterator() { return ObjectIterators.asObjectIterator(delegate.iterator()); }
/** * 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 <K> int unwrap(final Iterator<? extends K> i, final K array[]) { return unwrap(i, array, 0, array.length); } /**
@Override public ObjectIterator<Entry> iterator() { Iterator<Entry> iter = Iterators.transform(map.entrySet().iterator(), new Function<Map.Entry<Long, Double>, Entry>() { @Nullable @Override public Entry apply(@Nullable Map.Entry<Long, Double> input) { if (input == null) { return null; } return new AbstractLong2DoubleMap.BasicEntry(input.getKey(), input.getValue()); } }); return ObjectIterators.asObjectIterator(iter); }
/** 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 IdentityArrayList ( final Collection<? extends K> c ) { this( c.size() ); size = ObjectIterators.unwrap( c.iterator(), a ); } /** Creates a new array list and fills it with a given type-specific collection.
/** * 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 ReferenceArrayList(final Collection<? extends K> c) { this(c.size()); size = ObjectIterators.unwrap(c.iterator(), a); } /**
/** * 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 ObjectArrayList(final Collection<? extends K> c) { this(c.size()); size = ObjectIterators.unwrap(c.iterator(), a); } /**
@Override public <T> T[] toArray(T[] a) { if (size() <= a.length) { ObjectIterators.unwrap(iterator(), a); return a; } else { return delegate.toArray(a); } }