Java Code Examples for java.util.concurrent.CopyOnWriteArrayList#addAll()
The following examples show how to use
java.util.concurrent.CopyOnWriteArrayList#addAll() .
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: DefaultSubscriberListener.java From diamond with Apache License 2.0 | 6 votes |
/** * 添加一个DataID对应的一些ManagerListener * * @param dataId * @param addListeners */ public void addManagerListeners(String dataId, String group, List<ManagerListener> addListeners) { if (null == dataId || null == addListeners) { return; } if (addListeners.size() == 0) { return; } String key = makeKey(dataId, group); CopyOnWriteArrayList<ManagerListener> listenerList = allListeners.get(key); if (listenerList == null) { listenerList = new CopyOnWriteArrayList<ManagerListener>(); CopyOnWriteArrayList<ManagerListener> oldList = allListeners.putIfAbsent(key, listenerList); if (oldList != null) { listenerList = oldList; } } listenerList.addAll(addListeners); }
Example 2
Source File: doRandomGivenPercentMutants.java From muJava with Apache License 2.0 | 6 votes |
/** * Gets the minimal tests. * * @param testSets * the test sets * @return the minimal tests */ private static CopyOnWriteArrayList<ArrayList<String>> getMinimalTests(CopyOnWriteArrayList<ArrayList<String>> testSets) { CopyOnWriteArrayList<ArrayList<String>> result = new CopyOnWriteArrayList<>(); List<ArrayList<String>> testSets2 = new CopyOnWriteArrayList<ArrayList<String>>(); List<ArrayList<String>> testSets3 = new CopyOnWriteArrayList<ArrayList<String>>(); testSets2.addAll(testSets); testSets3.addAll(testSets); for (ArrayList<String> test : testSets3) { for (ArrayList<String> test2 : testSets2) { if (test.containsAll(test2) && !test2.containsAll(test)) { testSets.remove(test); testSets2.remove(test); testSets3.remove(test); System.out.println("remove test "+test); break; } } } result.addAll(testSets); return result; }
Example 3
Source File: DefaultSubscriberListener.java From diamond with Apache License 2.0 | 6 votes |
/** * 添加一个DataID对应的一些ManagerListener * * @param dataId * @param addListeners */ public void addManagerListeners(String dataId, String group, List<ManagerListener> addListeners) { if (null == dataId || null == addListeners) { return; } if (addListeners.size() == 0) { return; } String key = makeKey(dataId, group); CopyOnWriteArrayList<ManagerListener> listenerList = allListeners.get(key); if (listenerList == null) { listenerList = new CopyOnWriteArrayList<ManagerListener>(); CopyOnWriteArrayList<ManagerListener> oldList = allListeners.putIfAbsent(key, listenerList); if (oldList != null) { listenerList = oldList; } } listenerList.addAll(addListeners); }
Example 4
Source File: CopyOnWriteArrayListTest.java From j2objc with Apache License 2.0 | 5 votes |
public void testSubListClear() { CopyOnWriteArrayList<String> list = new CopyOnWriteArrayList<String>(); list.addAll(Arrays.asList("a", "b", "c", "d", "e")); List<String> bcd = list.subList(1, 4); bcd.clear(); assertEquals(Arrays.asList("a", "e"), list); bcd.addAll(Arrays.asList("B", "C", "D")); assertEquals(Arrays.asList("a", "B", "C", "D", "e"), list); }
Example 5
Source File: CopyOnWriteArrayListTest.java From j2objc with Apache License 2.0 | 5 votes |
public void testListIterator() { CopyOnWriteArrayList<String> list = new CopyOnWriteArrayList<String>(); list.addAll(Arrays.asList("a", "b", "c", "d", "e")); ListIterator<String> i = list.listIterator(5); list.clear(); assertEquals(5, i.nextIndex()); assertEquals(4, i.previousIndex()); assertEquals("e", i.previous()); assertEquals(4, i.nextIndex()); assertEquals(3, i.previousIndex()); assertTrue(i.hasNext()); assertTrue(i.hasPrevious()); assertEquals("d", i.previous()); assertEquals(3, i.nextIndex()); assertEquals(2, i.previousIndex()); assertTrue(i.hasNext()); assertTrue(i.hasPrevious()); assertEquals("c", i.previous()); assertEquals(2, i.nextIndex()); assertEquals(1, i.previousIndex()); assertTrue(i.hasNext()); assertTrue(i.hasPrevious()); assertEquals("b", i.previous()); assertEquals(1, i.nextIndex()); assertEquals(0, i.previousIndex()); assertTrue(i.hasNext()); assertTrue(i.hasPrevious()); assertEquals("a", i.previous()); assertEquals(0, i.nextIndex()); assertEquals(-1, i.previousIndex()); assertTrue(i.hasNext()); assertFalse(i.hasPrevious()); try { i.previous(); fail(); } catch (NoSuchElementException expected) { } }
Example 6
Source File: CopyOnWriteArrayListTest.java From j2objc with Apache License 2.0 | 5 votes |
public void testSubListAddAll() { CopyOnWriteArrayList<String> list = new CopyOnWriteArrayList<String>(); list.addAll(Arrays.asList("a", "b", "c", "d", "e")); List<String> bcd = list.subList(1, 4); bcd.addAll(1, Arrays.asList("f", "g", "h", "i")); assertEquals(Arrays.asList("a", "b", "f", "g", "h", "i", "c", "d", "e"), list); assertEquals(Arrays.asList("b", "f", "g", "h", "i", "c", "d"), bcd); }
Example 7
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 8
Source File: CopyOnWriteArrayListTest.java From j2objc with Apache License 2.0 | 5 votes |
public void testSubListRemoveAll() { 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.removeAll(Arrays.asList("c", "e", "h")); // the RI fails here assertEquals(Arrays.asList("a", "b", "c", "d", "f", "g", "h", "i"), list); assertEquals(Arrays.asList("d", "f"), def); }
Example 9
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 10
Source File: CopyOnWriteArrayListTest.java From j2objc with Apache License 2.0 | 5 votes |
public void testSubListRemoveByIndex() { CopyOnWriteArrayList<String> list = new CopyOnWriteArrayList<String>(); list.addAll(Arrays.asList("a", "b", "c", "d", "e")); List<String> bcd = list.subList(1, 4); bcd.remove(1); assertEquals(Arrays.asList("b", "d"), bcd); assertEquals(Arrays.asList("a", "b", "d", "e"), list); }
Example 11
Source File: CopyOnWriteArrayListTest.java From j2objc with Apache License 2.0 | 5 votes |
public void testSubListRemoveByValue() { CopyOnWriteArrayList<String> list = new CopyOnWriteArrayList<String>(); list.addAll(Arrays.asList("a", "b", "c", "d", "e")); List<String> bcd = list.subList(1, 4); bcd.remove("c"); // the RI fails here assertEquals(Arrays.asList("b", "d"), bcd); assertEquals(Arrays.asList("a", "b", "d", "e"), list); }
Example 12
Source File: CopyOnWriteArrayListTest.java From j2objc with Apache License 2.0 | 5 votes |
public void testSubListIteratorGetsSnapshot() { CopyOnWriteArrayList<String> list = new CopyOnWriteArrayList<String>(); list.addAll(Arrays.asList("a", "b", "c", "d", "e")); Iterator<String> bcd = list.subList(1, 4).iterator(); list.clear(); assertEquals("b", bcd.next()); assertEquals("c", bcd.next()); assertEquals("d", bcd.next()); assertFalse(bcd.hasNext()); }
Example 13
Source File: CopyOnWriteArrayListTest.java From j2objc with Apache License 2.0 | 5 votes |
public void testRemoveAll() { CopyOnWriteArrayList<String> list = new CopyOnWriteArrayList<String>(); list.addAll(Arrays.asList("a", "b", "c", "d", "e")); list.removeAll(Arrays.asList()); assertEquals(Arrays.asList("a", "b", "c", "d", "e"), list); list.removeAll(Arrays.asList("e")); assertEquals(Arrays.asList("a", "b", "c", "d"), list); list.removeAll(Arrays.asList("b", "c")); assertEquals(Arrays.asList("a", "d"), list); }
Example 14
Source File: CopyOnWriteArrayListTest.java From j2objc with Apache License 2.0 | 5 votes |
public void testSubListAndSizePreservingStructuralChanges() { CopyOnWriteArrayList<String> list = new CopyOnWriteArrayList<String>(); list.addAll(Arrays.asList("a", "b", "c", "d", "e")); List<String> bcd = list.subList(1, 4); list.clear(); list.addAll(Arrays.asList("A", "B", "C", "D", "E")); try { bcd.get(1); fail(); } catch (ConcurrentModificationException expected) { } }
Example 15
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 16
Source File: CopyOnWriteArrayListTest.java From j2objc with Apache License 2.0 | 5 votes |
/** * The sub list throws on non-structural changes, even though that disagrees * with the subList() documentation which suggests that only size-changing * operations will trigger ConcurrentModificationException. */ public void testSubListAndNonStructuralChanges() { CopyOnWriteArrayList<String> list = new CopyOnWriteArrayList<String>(); list.addAll(Arrays.asList("a", "b", "c", "d", "e")); List<String> bcd = list.subList(1, 4); list.set(2, "C"); try { bcd.get(1); fail(); } catch (ConcurrentModificationException expected) { } }
Example 17
Source File: CopyOnWriteArrayListTest.java From j2objc with Apache License 2.0 | 5 votes |
public void testIteratorAndNonStructuralChanges() { CopyOnWriteArrayList<String> list = new CopyOnWriteArrayList<String>(); list.addAll(Arrays.asList("a", "b", "c", "d", "e")); Iterator<String> abcde = list.iterator(); assertEquals("a", abcde.next()); list.set(1, "B"); assertEquals("b", abcde.next()); assertEquals("c", abcde.next()); assertEquals("d", abcde.next()); assertEquals("e", abcde.next()); }
Example 18
Source File: Test6895383.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
public void testAddAll1_IndexOutOfBoundsException() { try { CopyOnWriteArrayList c = new CopyOnWriteArrayList(); c.addAll(-1, new LinkedList()); // should throw IndexOutOfBoundsException } catch (IndexOutOfBoundsException e) { } }