@SuppressWarnings("ModifyingCollectionWithItself") @edu.umd.cs.findbugs.annotations.SuppressWarnings(value="DMI_VACUOUS_SELF_COLLECTION_CALL", justification="Intended vacuous containsAll call on 'c'") private void verify(ConcatenatedLists<Long> c, int last) { assertEquals((last == -1), c.isEmpty()); assertEquals(last + 1, c.size()); // This check is O(n^2), test with care assertTrue(c.containsAll(c)); Long[] array = c.toArray(new Long[c.size()]); List<Long> all = new ArrayList<>(); Iterator<Long> iter = c.iterator(); for (Long i = 0L; i <= last; ++i) { assertTrue(iter.hasNext()); assertEquals(i, iter.next()); assertEquals(i, array[i.intValue()]); assertTrue(c.contains(i)); assertTrue(c.containsAll(Arrays.asList(i))); all.add(i); } assertTrue(c.containsAll(all)); assertFalse(iter.hasNext()); try { iter.next(); fail("Should have thrown"); } catch (NoSuchElementException nsee) { } } }
@Override @SuppressWarnings("unchecked") public <U> U[] toArray(U[] a) { U[] result = (a.length == this.size()) ? a : (U[])Array.newInstance(a.getClass().getComponentType(), this.size); int i = 0; for (List<T> component : this.components) { for (T t : component) { result[i] = (U)t; ++i; } } return result; }
@SuppressWarnings("ModifyingCollectionWithItself") @edu.umd.cs.findbugs.annotations.SuppressWarnings(value="DMI_VACUOUS_SELF_COLLECTION_CALL", justification="Intended vacuous containsAll call on 'c'") private void verify(ConcatenatedLists<Long> c, int last) { assertEquals((last == -1), c.isEmpty()); assertEquals(last + 1, c.size()); // This check is O(n^2), test with care assertTrue(c.containsAll(c)); Long[] array = c.toArray(new Long[c.size()]); List<Long> all = new ArrayList<>(); Iterator<Long> iter = c.iterator(); for (Long i = 0L; i <= last; ++i) { assertTrue(iter.hasNext()); assertEquals(i, iter.next()); assertEquals(i, array[i.intValue()]); assertTrue(c.contains(i)); assertTrue(c.containsAll(Arrays.asList(i))); all.add(i); } assertTrue(c.containsAll(all)); assertFalse(iter.hasNext()); try { iter.next(); fail("Should have thrown"); } catch (NoSuchElementException nsee) { } } }
@SuppressWarnings("ModifyingCollectionWithItself") @edu.umd.cs.findbugs.annotations.SuppressWarnings(value="DMI_VACUOUS_SELF_COLLECTION_CALL", justification="Intended vacuous containsAll call on 'c'") private void verify(ConcatenatedLists<Long> c, int last) { assertEquals((last == -1), c.isEmpty()); assertEquals(last + 1, c.size()); // This check is O(n^2), test with care assertTrue(c.containsAll(c)); Long[] array = c.toArray(new Long[c.size()]); List<Long> all = new ArrayList<>(); Iterator<Long> iter = c.iterator(); for (Long i = 0L; i <= last; ++i) { assertTrue(iter.hasNext()); assertEquals(i, iter.next()); assertEquals(i, array[i.intValue()]); assertTrue(c.contains(i)); assertTrue(c.containsAll(Arrays.asList(i))); all.add(i); } assertTrue(c.containsAll(all)); assertFalse(iter.hasNext()); try { iter.next(); fail("Should have thrown"); } catch (NoSuchElementException nsee) { } } }