@Override public long[] toLongArray() { final long[] items = new long[size()]; LongIterators.unwrap(iterator(), items); return items; }
@Override public long[] toLongArray() { final long[] items = new long[size()]; LongIterators.unwrap(iterator(), items); return items; }
@Override public long[] toLongArray(long[] a) { long[] output = a; if (output.length < size()) { output = new long[size()]; } final int sz = LongIterators.unwrap(iterator(), output); if (sz < output.length) { output = Arrays.copyOf(output, sz); } return output; }
@Override public long[] toLongArray(long[] a) { long[] output = a; if (output.length < size()) { output = new long[size()]; } final int sz = LongIterators.unwrap(iterator(), output); if (sz < output.length) { output = Arrays.copyOf(output, sz); } return output; }
/** * 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 long[] unwrap(final LongIterator i) { return unwrap(i, Integer.MAX_VALUE); } /**
/** * 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 LongIterator i, final long array[]) { return unwrap(i, array, 0, array.length); } /**
/** * 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 LongArrayList(final Collection<? extends Long> c) { this(c.size()); size = LongIterators.unwrap(LongIterators.asLongIterator(c.iterator()), a); } /**
/** * 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 LongArrayList(final LongCollection c) { this(c.size()); size = LongIterators.unwrap(c.iterator(), a); } /**
@Override public long[] toLongArray() { final long[] items = new long[size()]; LongIterators.unwrap(iterator(), items); return items; }
@Override public long[] toLongArray() { final long[] items = new long[size()]; LongIterators.unwrap(iterator(), items); return items; }
@Override public long[] toLongArray() { final long[] items = new long[size()]; LongIterators.unwrap(iterator(), items); return items; }
@Override public long[] toLongArray(long[] a) { long[] output = a; if (output.length < size()) { output = new long[size()]; } final int sz = LongIterators.unwrap(iterator(), output); if (sz < output.length) { output = Arrays.copyOf(output, sz); } return output; }
@Override public long[] toLongArray(long[] a) { long[] output = a; if (output.length < size()) { output = new long[size()]; } final int sz = LongIterators.unwrap(iterator(), output); if (sz < output.length) { output = Arrays.copyOf(output, sz); } return output; }
@Override public long[] toLongArray(long[] a) { long[] output = a; if (output.length < size()) { output = new long[size()]; } final int sz = LongIterators.unwrap(iterator(), output); if (sz < output.length) { output = Arrays.copyOf(output, sz); } return output; }
@Override public boolean removeAll(Collection<?> c) { if (c instanceof LongCollection) { return removeAll((LongCollection) c); } else { long[] longs = LongIterators.unwrap(LongIterators.asLongIterator(Iterators.filter(c.iterator(), Long.class))); Arrays.sort(longs); return removeAll(LongArrayList.wrap(longs).iterator()); } }
@Override public boolean retainAll(Collection<?> c) { if (c instanceof LongCollection) { return retainAll((LongCollection) c); } else { long[] longs = LongIterators.unwrap(LongIterators.asLongIterator(Iterators.filter(c.iterator(), Long.class))); Arrays.sort(longs); return retainAll(LongArrayList.wrap(longs).iterator()); } } }
@Override public long[] toArray(long a[]) { if (a == null || a.length < size()) a = new long[size()]; LongIterators.unwrap(iterator(), a); return a; } @Override
/** * Run a battery of tests on a standard set. Used to test a variety of * construction scenarios with less code duplication. * * @param set The set {2, 5, 6}. */ private void testSetSimple(LongSortedSet set) { assertFalse(set.isEmpty()); assertEquals(3, set.size()); assertEquals(2, set.firstLong()); assertEquals(6, set.lastLong()); assertEquals(Long.valueOf(2), set.first()); assertEquals(Long.valueOf(6), set.last()); assertTrue(set.contains(2)); assertTrue(set.contains(5)); assertTrue(set.contains(6)); assertFalse(set.contains(0)); assertFalse(set.contains(42)); assertFalse(set.iterator().hasPrevious()); long[] items = LongIterators.unwrap(set.iterator()); assertEquals(2, items[0]); assertEquals(5, items[1]); assertEquals(6, items[2]); }