Java Code Examples for java.util.concurrent.CopyOnWriteArrayList#iterator()
The following examples show how to use
java.util.concurrent.CopyOnWriteArrayList#iterator() .
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: BaseRecycleAdapter.java From FimiX8-RE with MIT License | 6 votes |
public void remoteItem(int position) { MediaModel mediaModel = (MediaModel) this.modelList.get(position); String localPath = mediaModel.getFileLocalPath(); String formateDate = mediaModel.getFormatDate(); this.modelNoHeadList.remove(mediaModel); this.modelList.remove(mediaModel); if (this.stateHashMap != null && localPath != null) { CopyOnWriteArrayList<T> internalList = (CopyOnWriteArrayList) this.stateHashMap.get(formateDate); if (internalList != null) { Iterator it = internalList.iterator(); while (it.hasNext()) { MediaModel cacheModel = (MediaModel) it.next(); if (cacheModel != null && localPath.equals(cacheModel.getFileLocalPath())) { internalList.remove(cacheModel); } } if (internalList.size() < this.internalListBound) { this.modelList.remove(internalList.get(0)); } } } }
Example 2
Source File: BrowserService.java From collect-earth with MIT License | 6 votes |
private Thread getClosingBrowsersThread() { return new Thread("Quit the open browsers") { @Override public void run() { isClosing = true; CopyOnWriteArrayList<RemoteWebDriver> driversCopy = new CopyOnWriteArrayList<>(drivers); for (Iterator<RemoteWebDriver> iterator = driversCopy.iterator(); iterator.hasNext();) { RemoteWebDriver remoteWebDriver = iterator.next(); try { remoteWebDriver.quit(); } catch (final Exception e) { logger.error("Error quitting the browser", e); } } } }; }
Example 3
Source File: CopyOnWriteArrayListUnitTest.java From tutorials with MIT License | 6 votes |
@Test public void givenCopyOnWriteList_whenIterateAndAddElementToUnderneathList_thenShouldNotChangeIterator() { //given final CopyOnWriteArrayList<Integer> numbers = new CopyOnWriteArrayList<>(new Integer[]{1, 3, 5, 8}); //when Iterator<Integer> iterator = numbers.iterator(); numbers.add(10); //then List<Integer> result = new LinkedList<>(); iterator.forEachRemaining(result::add); assertThat(result).containsOnly(1, 3, 5, 8); //and Iterator<Integer> iterator2 = numbers.iterator(); List<Integer> result2 = new LinkedList<>(); iterator2.forEachRemaining(result2::add); //then assertThat(result2).containsOnly(1, 3, 5, 8, 10); }
Example 4
Source File: X8sPanelRecycleAdapter.java From FimiX8-RE with MIT License | 6 votes |
public void remoteItem(int position) { MediaModel mediaModel = (MediaModel) this.modelList.get(position); String localPath = mediaModel.getFileLocalPath(); String formateDate = mediaModel.getFormatDate().split(" ")[0]; this.modelNoHeadList.remove(mediaModel); this.modelList.remove(mediaModel); notifyItemRemoved(mediaModel.getItemPosition()); statisticalFileCount(mediaModel, false); if (this.stateHashMap != null && localPath != null) { CopyOnWriteArrayList<T> internalList = (CopyOnWriteArrayList) this.stateHashMap.get(formateDate); if (internalList != null) { Iterator it = internalList.iterator(); while (it.hasNext()) { MediaModel cacheModel = (MediaModel) it.next(); if (cacheModel != null && localPath.equals(cacheModel.getFileLocalPath())) { internalList.remove(cacheModel); } } if (internalList.size() < this.internalListBound) { this.stateHashMap.remove(((MediaModel) internalList.get(0)).getFormatDate().split(" ")[0]); this.modelList.remove(internalList.get(0)); notifyItemRemoved(((MediaModel) internalList.get(0)).getItemPosition()); } } } }
Example 5
Source File: X8LocalFragmentPresenter.java From FimiX8-RE with MIT License | 6 votes |
private void perfomSelectCategory(CopyOnWriteArrayList<MediaModel> internalList, boolean isSelect) { Iterator it = internalList.iterator(); while (it.hasNext()) { MediaModel mMediaModel = (MediaModel) it.next(); if (isSelect) { if (!mMediaModel.isSelect()) { mMediaModel.setSelect(true); addSelectModel(mMediaModel); } } else if (mMediaModel.isSelect()) { mMediaModel.setSelect(false); removeSelectModel(mMediaModel); } } notifyAllVisible(); callBackSelectSize(this.selectList.size()); if (this.selectList.size() == (this.modelList.size() - this.stateHashMap.size()) - 1) { callAllSelectMode(true); } else { callAllSelectMode(false); } }
Example 6
Source File: X8CameraFragmentPrensenter.java From FimiX8-RE with MIT License | 6 votes |
private void perfomSelectCategory(CopyOnWriteArrayList<MediaModel> internalList, boolean isSelect) { Iterator it = internalList.iterator(); while (it.hasNext()) { MediaModel mMediaModel = (MediaModel) it.next(); if (isSelect) { if (!mMediaModel.isSelect()) { mMediaModel.setSelect(true); addSelectModel(mMediaModel); } } else if (mMediaModel.isSelect()) { mMediaModel.setSelect(false); removeSelectModel(mMediaModel); } } notifyAllVisible(); callBackSelectSize(this.selectList.size()); if (this.selectList.size() == (this.modelList.size() - this.stateHashMap.size()) - 1) { callAllSelectMode(true); } else { callAllSelectMode(false); } }
Example 7
Source File: CopyOnWriteArrayListUnitTest.java From tutorials with MIT License | 5 votes |
@Test(expected = UnsupportedOperationException.class) public void givenCopyOnWriteList_whenIterateOverItAndTryToRemoveElement_thenShouldThrowException() { //given final CopyOnWriteArrayList<Integer> numbers = new CopyOnWriteArrayList<>(new Integer[]{1, 3, 5, 8}); //when Iterator<Integer> iterator = numbers.iterator(); while (iterator.hasNext()) { iterator.remove(); } }
Example 8
Source File: DownFwService.java From FimiX8-RE with MIT License | 5 votes |
private void reportProgress(DownState state, int progress, String name) { if (!state.equals(DownState.StopDown)) { CopyOnWriteArrayList<IDownProgress> list = DownNoticeMananger.getDownNoticManger().getNoticeList(); if (list != null && list.size() > 0) { Iterator it = list.iterator(); while (it.hasNext()) { ((IDownProgress) it.next()).onProgress(state, progress, name); } } } }
Example 9
Source File: CopyOnWriteArrayListTest.java From j2objc with Apache License 2.0 | 5 votes |
/** * iterator.remove throws UnsupportedOperationException */ public void testIteratorRemove() { CopyOnWriteArrayList full = populatedArray(SIZE); Iterator it = full.iterator(); it.next(); try { it.remove(); shouldThrow(); } catch (UnsupportedOperationException success) {} }
Example 10
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 11
Source File: SubsciberMethodHunter.java From AndroidEventBus with Apache License 2.0 | 5 votes |
/** * remove subscriber methods from map * * @param subscriber */ public void removeMethodsFromMap(Object subscriber) { Iterator<CopyOnWriteArrayList<Subscription>> iterator = mSubcriberMap .values().iterator(); while (iterator.hasNext()) { CopyOnWriteArrayList<Subscription> subscriptions = iterator.next(); if (subscriptions != null) { List<Subscription> foundSubscriptions = new LinkedList<Subscription>(); Iterator<Subscription> subIterator = subscriptions.iterator(); while (subIterator.hasNext()) { Subscription subscription = subIterator.next(); // 获取引用 Object cacheObject = subscription.subscriber.get(); if (isObjectsEqual(cacheObject, subscriber) || cacheObject == null) { Log.d("", "### 移除订阅 " + subscriber.getClass().getName()); foundSubscriptions.add(subscription); } } // 移除该subscriber的相关的Subscription subscriptions.removeAll(foundSubscriptions); } // 如果针对某个Event的订阅者数量为空了,那么需要从map中清除 if (subscriptions == null || subscriptions.size() == 0) { iterator.remove(); } } }
Example 12
Source File: XulSubscriberMethodHunter.java From starcor.xul with GNU Lesser General Public License v3.0 | 5 votes |
/** * remove subscriber methods from map */ public void removeMethodsFromMap(Object subscriber) { Iterator<CopyOnWriteArrayList<XulSubscription>> iterator = _subscriberMap.values().iterator(); while (iterator.hasNext()) { CopyOnWriteArrayList<XulSubscription> subscriptions = iterator.next(); if (subscriptions != null) { List<XulSubscription> foundSubscriptions = new LinkedList<XulSubscription>(); Iterator<XulSubscription> subIterator = subscriptions.iterator(); while (subIterator.hasNext()) { XulSubscription xulSubscription = subIterator.next(); // 获取引用 Object cacheObject = xulSubscription.getSubscriber(); if ((cacheObject == null) || cacheObject.equals(subscriber)) { xulSubscription.clearXulMessages(); foundSubscriptions.add(xulSubscription); } } // 移除该subscriber的相关的Subscription subscriptions.removeAll(foundSubscriptions); } // 如果针对某个Msg的订阅者数量为空了,那么需要从map中清除 if (subscriptions == null || subscriptions.size() == 0) { iterator.remove(); } } }
Example 13
Source File: CopyOnWriteArrayListTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * iterator.remove throws UnsupportedOperationException */ public void testIteratorRemove() { CopyOnWriteArrayList full = populatedArray(SIZE); Iterator it = full.iterator(); it.next(); try { it.remove(); shouldThrow(); } catch (UnsupportedOperationException success) {} }
Example 14
Source File: PluginPackageManagerNative.java From Neptune with Apache License 2.0 | 5 votes |
/** * 执行等待中的Action */ private static void executePendingAction() { PluginDebugLog.runtimeLog(TAG, "executePendingAction start...."); for (Map.Entry<String, CopyOnWriteArrayList<Action>> entry : sActionMap.entrySet()) { if (entry != null) { final CopyOnWriteArrayList<Action> actions = entry.getValue(); if (actions == null) { continue; } synchronized (actions) { // Action列表加锁同步 PluginDebugLog.installFormatLog(TAG, "execute %d pending actions!", actions.size()); Iterator<Action> iterator = actions.iterator(); while (iterator.hasNext()) { Action action = iterator.next(); if (action.meetCondition()) { PluginDebugLog.installFormatLog(TAG, "start doAction for pending action %s", action.toString()); action.doAction(); break; } else { PluginDebugLog.installFormatLog(TAG, "remove deprecate pending action from action list for %s", action.toString()); actions.remove(action); // CopyOnWriteArrayList在遍历过程中不能使用iterator删除元素 } } } } } }
Example 15
Source File: NamingServiceProcessor.java From brpc-java with Apache License 2.0 | 5 votes |
private CommunicationClient deleteInstance( CopyOnWriteArrayList<CommunicationClient> list, ServiceInstance item) { CommunicationClient instance = null; Iterator<CommunicationClient> iterator = list.iterator(); while (iterator.hasNext()) { CommunicationClient toCheck = iterator.next(); if (toCheck.getServiceInstance().equals(item)) { instance = toCheck; list.remove(instance); break; } } return instance; }
Example 16
Source File: CopyOnWriteArrayListTest.java From code with Apache License 2.0 | 5 votes |
@Test public void testIterator() { CopyOnWriteArrayList<String> list = new CopyOnWriteArrayList(); list.add("10"); list.add("20"); list.add("30"); Iterator<String> iterator = list.iterator(); list.add("50"); iterator.next(); list.add("50"); }
Example 17
Source File: X8sPanelRecycleAdapter.java From FimiX8-RE with MIT License | 5 votes |
public void updateDeleteItem(int position) { MediaModel mediaModel = (MediaModel) this.modelList.get(position); if (mediaModel != null) { String formateDate = mediaModel.getFormatDate(); String localPath = mediaModel.getFileLocalPath(); this.modelList.remove(position); statisticalFileCount(mediaModel, false); notifyItemRemoved(position); if (!(this.stateHashMap == null || localPath == null)) { CopyOnWriteArrayList<T> internalList = (CopyOnWriteArrayList) this.stateHashMap.get(formateDate.split(" ")[0]); if (internalList != null) { Iterator it = internalList.iterator(); while (it.hasNext()) { MediaModel cacheModel = (MediaModel) it.next(); if (cacheModel != null && localPath.equals(cacheModel.getFileLocalPath())) { internalList.remove(cacheModel); } } if (internalList.size() < this.internalListBound) { if (internalList.size() < this.internalListBound) { if (position - 1 < this.modelList.size()) { this.modelList.remove(position - 1); notifyItemRemoved(position - 1); notifyItemRangeRemoved(position, this.modelList.size() - position); } else { this.modelList.remove(this.modelList.size() - 1); notifyItemRemoved(this.modelList.size() - 1); } } judgeIsNoData(); return; } } } judgeIsNoData(); notifyItemRangeRemoved(position, this.modelList.size() - position); } }
Example 18
Source File: X9CameraPrensenter.java From FimiX8-RE with MIT License | 5 votes |
private void perfomSelectCategory(CopyOnWriteArrayList<MediaModel> internalList, boolean isSelect) { Iterator it = internalList.iterator(); while (it.hasNext()) { MediaModel mMediaModel = (MediaModel) it.next(); if (isSelect) { mMediaModel.setSelect(true); addSelectModel(mMediaModel); } else { mMediaModel.setSelect(false); removeSelectModel(mMediaModel); } } this.mPanelRecycleAdapter.notifyItemRangeChanged(this.mGridLayoutManager.findFirstVisibleItemPosition(), this.mGridLayoutManager.findLastVisibleItemPosition()); }
Example 19
Source File: LocalFragmentPresenter.java From FimiX8-RE with MIT License | 5 votes |
private void perfomSelectCategory(CopyOnWriteArrayList<MediaModel> internalList, boolean isSelect) { Iterator it = internalList.iterator(); while (it.hasNext()) { MediaModel mMediaModel = (MediaModel) it.next(); if (isSelect) { mMediaModel.setSelect(true); addSelectModel(mMediaModel); } else { mMediaModel.setSelect(false); removeSelectModel(mMediaModel); } } this.mPanelRecycleAdapter.notifyItemRangeChanged(this.mGridLayoutManager.findFirstVisibleItemPosition(), this.mGridLayoutManager.findLastVisibleItemPosition()); }
Example 20
Source File: BinaryGapTest.java From algorithms with MIT License | 4 votes |
@Test public void collections() { Map<String, Integer> map1 = new HashMap<>(); map1.values(); map1.keySet(); map1.isEmpty(); map1.clear(); map1.merge("t", 5, (v1, v2) -> v1 +v2); System.out.println(map1.get("t")); map1.merge("t", 4, (v1, v2) -> v1 +v2); System.out.println(map1.get("t")); System.out.println(map1.computeIfAbsent("r", k -> 1)); System.out.println(map1.get("r")); map1.put("", 1); System.out.println(map1.computeIfPresent("", (k, v) -> v + 1)); System.out.println(map1.get("")); System.out.println(map1.getOrDefault("", 5)); map1.merge("", 5, (i, j) -> i + j); map1.merge("a", 5, (i, j) -> i + j); Set<Map.Entry<String, Integer>> entrySet = map1.entrySet(); System.out.println(map1.compute("", (k,i) -> i + 1)); System.out.println(map1.get("")); System.out.println(map1.get("a")); map1.putIfAbsent("d", 8); System.out.println(map1.replace("d", 9)); System.out.println(map1.get("d")); map1.containsKey("d"); map1.containsValue(8); map1.remove("d"); NavigableMap<Integer, Integer> map2 = new TreeMap<>(Comparator.naturalOrder()); map2.ceilingEntry(1); map2.ceilingKey(1); map2.floorEntry(1); map2.floorKey(1); map2.descendingKeySet(); map2.descendingMap(); map2.higherEntry(1); map2.higherKey(1); map2.lowerEntry(1); map2.lowerKey(1); map2.navigableKeySet(); map2.firstEntry(); map2.lastEntry(); map2.pollFirstEntry(); map2.pollLastEntry(); Set<Integer> set = new HashSet<>(); set.containsAll(new ArrayList<>()); set.contains(1); set.add(1); set.size(); set.clear(); set.isEmpty(); set.iterator(); set.remove(1); NavigableSet<Integer> set1 = new TreeSet<>(Comparator.naturalOrder()); set1.ceiling(1); set1.floor(1); set1.higher(1); set1.lower(1); set1.pollFirst(); set1.pollLast(); PriorityQueue<Integer> priorityQueue = new PriorityQueue<>(Comparator.reverseOrder()); priorityQueue.add(4); priorityQueue.add(2); priorityQueue.offer(3); int a = priorityQueue.peek(); int b = priorityQueue.poll(); priorityQueue.remove(1); CopyOnWriteArrayList<Integer> copyList = new CopyOnWriteArrayList<>(); copyList.addIfAbsent(1); AtomicInteger atomicInteger = new AtomicInteger(0); int index = atomicInteger.getAndAccumulate(1, (i, j) -> (i+j) % 20); copyList.set(index, 2); copyList.iterator(); }