Java Code Examples for java.util.concurrent.CopyOnWriteArrayList#subList()
The following examples show how to use
java.util.concurrent.CopyOnWriteArrayList#subList() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CopyOnWriteArrayListTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
/** * sublists contains elements at indexes offset from their base */ public void testSubList() { CopyOnWriteArrayList a = populatedArray(10); assertTrue(a.subList(1,1).isEmpty()); for (int j = 0; j < 9; ++j) { for (int i = j ; i < 10; ++i) { List b = a.subList(j,i); for (int k = j; k < i; ++k) { assertEquals(new Integer(k), b.get(k-j)); } } } List s = a.subList(2, 5); assertEquals(3, s.size()); s.set(2, m1); assertEquals(a.get(4), m1); s.clear(); assertEquals(7, a.size()); }
Example 2
Source File: CopyOnWriteArrayListTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * addAll throws an IndexOutOfBoundsException on a too high index */ public void testAddAll2_IndexOutOfBoundsException() { CopyOnWriteArrayList c = populatedArray(5); List[] lists = { c, c.subList(1, c.size() - 1) }; for (List list : lists) { try { list.addAll(list.size() + 1, new LinkedList()); shouldThrow(); } catch (IndexOutOfBoundsException success) {} } }
Example 3
Source File: CopyOnWriteArrayListTest.java From j2objc with Apache License 2.0 | 5 votes |
public void testSubListRetainAll() { CopyOnWriteArrayList<String> list = new CopyOnWriteArrayList<String>(); list.addAll(Arrays.asList("a", "b", "c", "d", "e", "f", "g", "h", "i")); List<String> def = list.subList(3, 6); def.retainAll(Arrays.asList("c", "e", "h")); // the RI fails here assertEquals(Arrays.asList("a", "b", "c", "e", "g", "h", "i"), list); assertEquals(Arrays.asList("e"), def); }
Example 4
Source File: CopyOnWriteArrayListTest.java From j2objc with Apache License 2.0 | 5 votes |
/** * subList throws an IndexOutOfBoundsException on a negative index */ public void testSubList1_IndexOutOfBoundsException() { CopyOnWriteArrayList c = populatedArray(5); List[] lists = { c, c.subList(1, c.size() - 1) }; for (List list : lists) { try { list.subList(-1, list.size()); shouldThrow(); } catch (IndexOutOfBoundsException success) {} } }
Example 5
Source File: CopyOnWriteArrayListTest.java From j2objc with Apache License 2.0 | 5 votes |
public void testSubListAndStructuralChanges() { CopyOnWriteArrayList<String> list = new CopyOnWriteArrayList<String>(); list.addAll(Arrays.asList("a", "b", "c", "d", "e")); List<String> bcd = list.subList(1, 4); list.clear(); try { bcd.get(1); fail(); } catch (ConcurrentModificationException expected) { } }
Example 6
Source File: CopyOnWriteArrayListTest.java From j2objc with Apache License 2.0 | 5 votes |
/** * addAll throws an IndexOutOfBoundsException on a too high index */ public void testAddAll2_IndexOutOfBoundsException() { CopyOnWriteArrayList c = populatedArray(5); List[] lists = { c, c.subList(1, c.size() - 1) }; for (List list : lists) { try { list.addAll(list.size() + 1, new LinkedList()); shouldThrow(); } catch (IndexOutOfBoundsException success) {} } }
Example 7
Source File: CopyOnWriteArrayListTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * subList throws IndexOutOfBoundsException when the second index * is lower then the first */ public void testSubList3_IndexOutOfBoundsException() { CopyOnWriteArrayList c = populatedArray(5); List[] lists = { c, c.subList(1, c.size() - 1) }; for (List list : lists) { try { list.subList(list.size() - 1, 1); shouldThrow(); } catch (IndexOutOfBoundsException success) {} } }
Example 8
Source File: CopyOnWriteArrayListTest.java From j2objc with Apache License 2.0 | 5 votes |
public void testSubListAddIsAtEnd() { CopyOnWriteArrayList<String> list = new CopyOnWriteArrayList<String>(); list.addAll(Arrays.asList("a", "b", "c", "d", "e")); List<String> bcd = list.subList(1, 4); bcd.add("f"); assertEquals(Arrays.asList("a", "b", "c", "d", "f", "e"), list); assertEquals(Arrays.asList("b", "c", "d", "f"), bcd); }
Example 9
Source File: CopyOnWriteArrayListTest.java From j2objc with Apache License 2.0 | 5 votes |
/** * subList throws IndexOutOfBoundsException when the second index * is lower then the first */ public void testSubList3_IndexOutOfBoundsException() { CopyOnWriteArrayList c = populatedArray(5); List[] lists = { c, c.subList(1, c.size() - 1) }; for (List list : lists) { try { list.subList(list.size() - 1, 1); shouldThrow(); } catch (IndexOutOfBoundsException success) {} } }
Example 10
Source File: CopyOnWriteArrayListTest.java From j2objc with Apache License 2.0 | 5 votes |
/** * remove throws an IndexOutOfBoundsException on a negative index */ public void testRemove1_IndexOutOfBounds() { CopyOnWriteArrayList c = populatedArray(5); List[] lists = { c, c.subList(1, c.size() - 1) }; for (List list : lists) { try { list.remove(-1); shouldThrow(); } catch (IndexOutOfBoundsException success) {} } }
Example 11
Source File: CopyOnWriteArrayListTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * listIterator throws an IndexOutOfBoundsException on a negative index */ public void testListIterator1_IndexOutOfBoundsException() { CopyOnWriteArrayList c = populatedArray(5); List[] lists = { c, c.subList(1, c.size() - 1) }; for (List list : lists) { try { list.listIterator(-1); shouldThrow(); } catch (IndexOutOfBoundsException success) {} } }
Example 12
Source File: CopyOnWriteArrayListTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * addAll throws an IndexOutOfBoundsException on a negative index */ public void testAddAll1_IndexOutOfBoundsException() { CopyOnWriteArrayList c = populatedArray(5); List[] lists = { c, c.subList(1, c.size() - 1) }; for (List list : lists) { try { list.addAll(-1, new LinkedList()); shouldThrow(); } catch (IndexOutOfBoundsException success) {} } }
Example 13
Source File: CopyOnWriteArrayListTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * remove throws an IndexOutOfBoundsException on a too high index */ public void testRemove2_IndexOutOfBounds() { CopyOnWriteArrayList c = populatedArray(5); List[] lists = { c, c.subList(1, c.size() - 1) }; for (List list : lists) { try { list.remove(list.size()); shouldThrow(); } catch (IndexOutOfBoundsException success) {} } }
Example 14
Source File: CopyOnWriteArrayListTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * remove throws an IndexOutOfBoundsException on a negative index */ public void testRemove1_IndexOutOfBounds() { CopyOnWriteArrayList c = populatedArray(5); List[] lists = { c, c.subList(1, c.size() - 1) }; for (List list : lists) { try { list.remove(-1); shouldThrow(); } catch (IndexOutOfBoundsException success) {} } }
Example 15
Source File: CopyOnWriteArrayListTest.java From j2objc with Apache License 2.0 | 5 votes |
/** * listIterator throws an IndexOutOfBoundsException on a too high index */ public void testListIterator2_IndexOutOfBoundsException() { CopyOnWriteArrayList c = populatedArray(5); List[] lists = { c, c.subList(1, c.size() - 1) }; for (List list : lists) { try { list.listIterator(list.size() + 1); shouldThrow(); } catch (IndexOutOfBoundsException success) {} } }
Example 16
Source File: CopyOnWriteArrayListTest.java From j2objc with Apache License 2.0 | 5 votes |
/** * set throws an IndexOutOfBoundsException on a negative index */ public void testSet1_IndexOutOfBoundsException() { CopyOnWriteArrayList c = populatedArray(5); List[] lists = { c, c.subList(1, c.size() - 1) }; for (List list : lists) { try { list.set(-1, "qwerty"); shouldThrow(); } catch (IndexOutOfBoundsException success) {} } }
Example 17
Source File: CopyOnWriteArrayListTest.java From j2objc with Apache License 2.0 | 5 votes |
/** * add throws an IndexOutOfBoundsException on a negative index */ public void testAdd1_IndexOutOfBoundsException() { CopyOnWriteArrayList c = populatedArray(5); List[] lists = { c, c.subList(1, c.size() - 1) }; for (List list : lists) { try { list.add(-1, "qwerty"); shouldThrow(); } catch (IndexOutOfBoundsException success) {} } }
Example 18
Source File: CopyOnWriteArrayListTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * set throws an IndexOutOfBoundsException on a negative index */ public void testSet1_IndexOutOfBoundsException() { CopyOnWriteArrayList c = populatedArray(5); List[] lists = { c, c.subList(1, c.size() - 1) }; for (List list : lists) { try { list.set(-1, "qwerty"); shouldThrow(); } catch (IndexOutOfBoundsException success) {} } }
Example 19
Source File: CopyOnWriteArrayListTest.java From j2objc with Apache License 2.0 | 5 votes |
/** * get throws an IndexOutOfBoundsException on a too high index */ public void testGet2_IndexOutOfBoundsException() { CopyOnWriteArrayList c = populatedArray(5); List[] lists = { c, c.subList(1, c.size() - 1) }; for (List list : lists) { try { list.get(list.size()); shouldThrow(); } catch (IndexOutOfBoundsException success) {} } }
Example 20
Source File: CopyOnWriteArrayListTest.java From j2objc with Apache License 2.0 | 5 votes |
/** * addAll throws an IndexOutOfBoundsException on a negative index */ public void testAddAll1_IndexOutOfBoundsException() { CopyOnWriteArrayList c = populatedArray(5); List[] lists = { c, c.subList(1, c.size() - 1) }; for (List list : lists) { try { list.addAll(-1, new LinkedList()); shouldThrow(); } catch (IndexOutOfBoundsException success) {} } }