Example usage for java.util Iterator remove

List of usage examples for java.util Iterator remove

Introduction

In this page you can find the example usage for java.util Iterator remove.

Prototype

default void remove() 

Source Link

Document

Removes from the underlying collection the last element returned by this iterator (optional operation).

Usage

From source file:cn.leancloud.diamond.io.watch.WatchService.java

/**
 * check//from  w  ww .j a  v  a  2s . c  o  m
 */
public void check() {
    synchronized (this) {
        Iterator<WatchKey> it = watchedKeys.iterator();
        while (it.hasNext()) {
            WatchKey key = it.next();
            try {
                if (key.check()) {
                    changedKeys.add(key);
                    it.remove();
                }
            } catch (Throwable t) {
                log.error("WatchKey,key=" + key, t);
            }
        }
    }
}

From source file:com.taobao.diamond.io.watch.WatchService.java

/**
 * check// ww w  . j  a  v a  2s. c  om
 */
public void check() {
    synchronized (this) {
        Iterator<WatchKey> it = watchedKeys.iterator();
        while (it.hasNext()) {
            WatchKey key = it.next();
            try {
                if (key.check()) {
                    changedKeys.add(key);
                    it.remove();
                }
            } catch (Throwable t) {
                log.error("WatchKey,key=" + key, t);
            }
        }
    }
}

From source file:org.lightadmin.core.persistence.support.DynamicDomainObjectMerger.java

private void removeReferencedItems(Collection<Object> targetCollection,
        Collection<Object> candidatesForRemoval) {
    Iterator<Object> itr = targetCollection.iterator();
    while (itr.hasNext()) {
        Object obj = itr.next();//w w w .  j a  v  a  2s .c om
        if (mathesAny(candidatesForRemoval, obj)) {
            itr.remove();
        }
    }
}

From source file:org.wallride.support.PageUtils.java

public List<TreeNode<Page>> getNodes(boolean includeUnpublished) {
    PageSearchRequest request = new PageSearchRequest();
    if (!includeUnpublished) {
        request.setStatus(Post.Status.PUBLISHED);
    }//w w  w .j a  va  2  s . co m
    Collection<Page> pages = new TreeSet<>(pageService.getPages(request).getContent());

    List<TreeNode<Page>> rootNodes = new ArrayList<>();
    Iterator<Page> i = pages.iterator();
    while (i.hasNext()) {
        Page page = i.next();
        if (page.getParent() == null) {
            TreeNode<Page> node = new TreeNode<>(page);
            rootNodes.add(node);
            i.remove();
        }
    }

    for (TreeNode<Page> node : rootNodes) {
        createNode(node, pages);
    }
    return rootNodes;
}

From source file:com.carolinarollergirls.scoreboard.xml.MediaXmlDocumentManager.java

protected void processChildElement(Element e) throws Exception {
    synchronized (updateLock) { /* prevent element removal while/before updating */
        if (e.getName().equals("Type")) {
            Element type = editor.getElement(getXPathElement(), "Type", editor.getId(e), false);
            if (type == null)
                return;
            Iterator i = e.getChildren(getMediaName()).iterator();
            while (i.hasNext())
                if (!checkMediaNameElement(type, (Element) i.next()))
                    i.remove();
        }/* w  ww .jav a2 s .com*/
        super.processChildElement(e);
    }
}

From source file:com.ironiacorp.http.impl.httpclient3.HttpJobRunnerHttpClient3.java

public void run() {
    ExecutorService executor = Executors.newFixedThreadPool(maxThreadsCount);
    ExecutorCompletionService<HttpJob> queue = new ExecutorCompletionService<HttpJob>(executor);
    List<Future<?>> workers = new ArrayList<Future<?>>();

    for (HttpJob job : jobs) {
        if (HttpMethod.GET == job.getMethod()) {
            GetRequest request = new GetRequest(httpClient, job);
            Future<HttpJob> jobStatus = queue.submit(request);
            workers.add(jobStatus);/*from w  w  w  .  j  a  va 2 s .c o  m*/
            continue;
        }
        if (HttpMethod.POST == job.getMethod()) {
            PostRequest request = new PostRequest(httpClient, job);
            Future<HttpJob> jobStatus = queue.submit(request);
            workers.add(jobStatus);
            continue;
        }
        // TODO: job cannot be handled, what to do?
    }

    while (!workers.isEmpty()) {
        Iterator<Future<?>> i = workers.iterator();
        while (i.hasNext()) {
            try {
                Future<?> future = i.next();
                // future.get(timeout, TimeUnit.MILLISECONDS);
                future.get();
                i.remove();
                // } catch (TimeoutException e) {
            } catch (InterruptedException ie) {
                System.out.println(ie.getMessage());
            } catch (ExecutionException ee) {
                System.out.println(ee.getMessage());
                i.remove();
            }
        }
    }

    executor.shutdown();
}

From source file:org.jdal.vaadin.beans.VaadinScope.java

private void removeBeans(UI ui) {
    Set<String> keys = beans.keySet();
    Iterator<String> iter = keys.iterator();

    while (iter.hasNext()) {
        String key = iter.next();
        String prefix = getConversationId(ui);

        if (key.startsWith(prefix)) {
            iter.remove();
            if (log.isDebugEnabled())
                log.debug("Removed bean [" + key + "]");
            Runnable callback = callbacks.remove(key);
            if (callback != null) {
                callback.run();/*from   www  .  ja  va 2 s .  c  om*/
            }
        }
    }

}

From source file:com.parse.ParseRemoveOperation.java

@Override
public Object apply(Object oldValue, String key) {
    if (oldValue == null) {
        return new ArrayList<>();
    } else if (oldValue instanceof JSONArray) {
        ArrayList<Object> old = ParseFieldOperations.jsonArrayAsArrayList((JSONArray) oldValue);
        @SuppressWarnings("unchecked")
        ArrayList<Object> newValue = (ArrayList<Object>) this.apply(old, key);
        return new JSONArray(newValue);
    } else if (oldValue instanceof List) {
        ArrayList<Object> result = new ArrayList<>((List<?>) oldValue);
        result.removeAll(objects);//from  ww w  . j  a  v a  2  s  . c o m

        // Remove the removed objects from "objects" -- the items remaining
        // should be ones that weren't removed by object equality.
        ArrayList<Object> objectsToBeRemoved = new ArrayList<>(objects);
        objectsToBeRemoved.removeAll(result);

        // Build up set of object IDs for any ParseObjects in the remaining objects-to-be-removed
        HashSet<String> objectIds = new HashSet<>();
        for (Object obj : objectsToBeRemoved) {
            if (obj instanceof ParseObject) {
                objectIds.add(((ParseObject) obj).getObjectId());
            }
        }

        // And iterate over "result" to see if any other ParseObjects need to be removed
        Iterator<Object> resultIterator = result.iterator();
        while (resultIterator.hasNext()) {
            Object obj = resultIterator.next();
            if (obj instanceof ParseObject && objectIds.contains(((ParseObject) obj).getObjectId())) {
                resultIterator.remove();
            }
        }
        return result;
    } else {
        throw new IllegalArgumentException("Operation is invalid after previous operation.");
    }
}

From source file:de.xaniox.heavyspleef.commands.base.proxy.ProxyExecution.java

public void unattachProxy(Proxy proxy) {
    Validate.isTrue(isProxyAttached(proxy), "Proxy is not attached");

    Iterator<ProxyHolder> iterator = proxies.iterator();
    while (iterator.hasNext()) {
        ProxyHolder holder = iterator.next();
        if (holder.proxy != proxy) {
            continue;
        }//from ww  w .j  a v a2  s .c  om

        iterator.remove();
        break;
    }
}