java.util.concurrent.CopyOnWriteArrayList#iterator ( )源码实例Demo

下面列出了java.util.concurrent.CopyOnWriteArrayList#iterator ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: FimiX8-RE   文件: BaseRecycleAdapter.java
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));
            }
        }
    }
}
 
源代码2 项目: collect-earth   文件: BrowserService.java
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);
					}
				}

			}
		};
	}
 
源代码3 项目: FimiX8-RE   文件: X8sPanelRecycleAdapter.java
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());
            }
        }
    }
}
 
源代码4 项目: FimiX8-RE   文件: X8LocalFragmentPresenter.java
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);
    }
}
 
源代码5 项目: FimiX8-RE   文件: X8CameraFragmentPrensenter.java
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);
    }
}
 
源代码6 项目: tutorials   文件: CopyOnWriteArrayListUnitTest.java
@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);

}
 
源代码7 项目: FimiX8-RE   文件: DownFwService.java
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);
            }
        }
    }
}
 
源代码8 项目: FimiX8-RE   文件: LocalFragmentPresenter.java
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());
}
 
源代码9 项目: FimiX8-RE   文件: X9CameraPrensenter.java
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());
}
 
源代码10 项目: FimiX8-RE   文件: X8sPanelRecycleAdapter.java
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);
    }
}
 
源代码11 项目: code   文件: CopyOnWriteArrayListTest.java
@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");
}
 
源代码12 项目: brpc-java   文件: NamingServiceProcessor.java
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;
}
 
源代码13 项目: Neptune   文件: PluginPackageManagerNative.java
/**
 * 执行等待中的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删除元素
                    }
                }
            }
        }
    }
}
 
源代码14 项目: openjdk-jdk9   文件: CopyOnWriteArrayListTest.java
/**
 * iterator.remove throws UnsupportedOperationException
 */
public void testIteratorRemove() {
    CopyOnWriteArrayList full = populatedArray(SIZE);
    Iterator it = full.iterator();
    it.next();
    try {
        it.remove();
        shouldThrow();
    } catch (UnsupportedOperationException success) {}
}
 
源代码15 项目: starcor.xul   文件: XulSubscriberMethodHunter.java
/**
 * 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();
        }
    }
}
 
源代码16 项目: AndroidEventBus   文件: SubsciberMethodHunter.java
/**
 * 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();
        }
    }
}
 
源代码17 项目: j2objc   文件: CopyOnWriteArrayListTest.java
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());
}
 
源代码18 项目: j2objc   文件: CopyOnWriteArrayListTest.java
/**
 * iterator.remove throws UnsupportedOperationException
 */
public void testIteratorRemove() {
    CopyOnWriteArrayList full = populatedArray(SIZE);
    Iterator it = full.iterator();
    it.next();
    try {
        it.remove();
        shouldThrow();
    } catch (UnsupportedOperationException success) {}
}
 
源代码19 项目: tutorials   文件: CopyOnWriteArrayListUnitTest.java
@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();
    }
}
 
源代码20 项目: algorithms   文件: BinaryGapTest.java
@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();
}