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:com.dianping.lion.web.tag.MainNavigator.java

private NavMenus filterWithPrivilege(NavMenus navMenus) {
    if (navMenus == null) {
        return null;
    }/*  w w  w.j a v  a  2  s  .c  o  m*/
    try {
        NavMenus cloned = (NavMenus) navMenus.clone();
        Iterator<Object> iterator = cloned.menuOrGroups.iterator();
        while (iterator.hasNext()) {
            Object next = iterator.next();
            if (next instanceof MenuGroup) {
                if (hasPrivilege((MenuGroup) next) < 0) {
                    iterator.remove();
                }
            } else if (next instanceof Menu) {
                if (hasPrivilege((Menu) next) < 0) {
                    iterator.remove();
                }
            }
        }
        return cloned;
    } catch (Exception e) {
        logger.error("Generate main navigator failed.", e);
        throw new RuntimeException("Generate main navigator failed.", e);
    }
}

From source file:blue.mixer.ChannelList.java

public void clearChannelsNotInList(ArrayList ids) {
    Iterator iter = channels.iterator();

    while (iter.hasNext()) {
        Channel channel = (Channel) iter.next();

        if (!ids.contains(channel.getName())) {
            iter.remove();
        }/*w  ww .  j a va2s  .c om*/
    }
}

From source file:com.evolveum.midpoint.web.component.form.multivalue.MultiValueDropDownPanel.java

protected void removeValuePerformed(AjaxRequestTarget target, ListItem<T> item) {
    List<T> objects = getModelObject();
    Iterator<T> iterator = objects.iterator();
    while (iterator.hasNext()) {
        T object = iterator.next();/*from  w  ww .  j a v a  2 s. c  om*/
        if (object.equals(item.getModelObject())) {
            iterator.remove();
            break;
        }
    }

    target.add(this);
}

From source file:com.digitalpebble.storm.crawler.filtering.basic.BasicURLNormalizer.java

/**
 * Basic filter to remove query parameters from urls so parameters that
 * don't change the content of the page can be removed. An example would be
 * a google analytics query parameter like "utm_campaign" which might have
 * several different values for a url that points to the same content.
 *//*from ww  w . j a  v  a  2 s.c  o m*/
private String filterQueryElements(String urlToFilter) {
    try {
        // Handle illegal characters by making a url first
        // this will clean illegal characters like |
        URL url = new URL(urlToFilter);

        if (StringUtils.isEmpty(url.getQuery())) {
            return urlToFilter;
        }

        List<NameValuePair> pairs = new ArrayList<NameValuePair>();
        URLEncodedUtils.parse(pairs, new Scanner(url.getQuery()), "UTF-8");
        Iterator<NameValuePair> pairsIterator = pairs.iterator();
        while (pairsIterator.hasNext()) {
            NameValuePair param = pairsIterator.next();
            if (queryElementsToRemove.contains(param.getName())) {
                pairsIterator.remove();
            }
        }

        StringBuilder newFile = new StringBuilder();
        if (url.getPath() != null) {
            newFile.append(url.getPath());
        }
        if (!pairs.isEmpty()) {
            Collections.sort(pairs, comp);
            String newQueryString = URLEncodedUtils.format(pairs, StandardCharsets.UTF_8);
            newFile.append('?').append(newQueryString);
        }
        if (url.getRef() != null) {
            newFile.append('#').append(url.getRef());
        }

        return new URL(url.getProtocol(), url.getHost(), url.getPort(), newFile.toString()).toString();
    } catch (MalformedURLException e) {
        LOG.warn("Invalid urlToFilter {}. {}", urlToFilter, e);
        return null;
    }
}

From source file:nz.net.orcon.kanban.controllers.FormController.java

public void filterMap(Map<String, String> list, String types) throws Exception {
    Iterator<String> it = list.keySet().iterator();
    while (it.hasNext()) {
        String formId = it.next();
        Map<String, String> roles = formCache.getItem(formId).getRoles();
        if (!this.securityTool.isAuthorised(roles, types)) {
            it.remove();
        }/*from w  ww  . j av  a  2  s  . co m*/
    }
}

From source file:com.taobao.diamond.client.impl.PublishTaskProcessor.java

private boolean processPublish(PublishTask publishTask) {
    int count = publishTask.getCount();
    int waitTime = getWaitTime(++count);
    log.info("" + count + "");
    publishTask.setCount(count);/*from w ww .j  a  va2s .c  om*/
    String dataId = publishTask.getDataId();
    String group = publishTask.getGroup();

    Iterator<String> it = publishTask.getContents().iterator();
    while (it.hasNext()) {
        String fullConfig = it.next();
        String config = ContentUtils.getContent(fullConfig);
        if (innerPublish(publishTask, waitTime, dataId, group, config, fullConfig)) {
            it.remove();
        } else {
            return false;
        }
    }
    return true;
}

From source file:de.ingrid.iplug.PlugDescriptionFieldFilters.java

public PlugDescription filter(final PlugDescription plugDescription) {
    PlugDescription clone = (PlugDescription) plugDescription.clone();
    Iterator<Entry<Object, Object>> iterator = clone.entrySet().iterator();
    while (iterator.hasNext()) {
        Entry<?, ?> entry = (Entry<?, ?>) iterator.next();
        Object key = entry.getKey();
        for (IPlugdescriptionFieldFilter filter : _filters) {
            if (filter.filter(key)) {
                LOG.info("remove field: " + key);
                iterator.remove();
            }//from  w ww.  ja v  a2  s  .  com
        }
    }
    return clone;
}

From source file:net.ae97.pokebot.extensions.faq.FaqExtension.java

@Override
public void runEvent(CommandEvent event) {
    Database index = getDatabase(event);
    Iterator<TimeKeeper> keeper = timeTracker.iterator();
    long startTime = System.currentTimeMillis() - floodDelay;
    while (keeper.hasNext()) {
        if (keeper.next().getTime() < startTime) {
            keeper.remove();
        }// ww  w  . ja  v a  2  s .com
    }
    for (TimeKeeper time : timeTracker) {
        if (time.getCommand().equalsIgnoreCase(StringUtils.join(event.getArgs(), " "))) {
            event.getUser().send().notice("I already used this command within 10 seconds");
            return;
        }
    }
    timeTracker.add(new TimeKeeper(StringUtils.join(event.getArgs(), " ")));
    for (Entry<String, FaqSubCommand> entry : subCommands.entrySet()) {
        if (event.getCommand().equalsIgnoreCase(entry.getKey())) {
            entry.getValue().execute(this, event, index);
            return;
        }
    }
}

From source file:de.dhke.projects.cutil.collections.aspect.AspectMultiMapEntrySet.java

private boolean batchRemove(Collection<?> c, boolean retain) {
    for (Map.Entry<K, Collection<V>> entry : _entrySet) {
        if (c.contains(entry) != retain) {
            for (V value : entry.getValue()) {
                final Map.Entry<K, V> evEntry = new DefaultMapEntry<>(entry.getKey(), value);
                _aspectMap.notifyBeforeElementRemoved(_aspectMap, evEntry);
            }//from w w  w  . java 2  s . co  m
        }
    }

    final Iterator<Map.Entry<K, Collection<V>>> iter = _entrySet.iterator();
    boolean wasRemoved = false;
    while (iter.hasNext()) {
        Map.Entry<K, Collection<V>> entry = iter.next();
        if (c.contains(entry) != retain) {
            iter.remove();
            wasRemoved = true;
            for (V value : entry.getValue()) {
                Map.Entry<K, V> evEntry = new DefaultMapEntry<>(entry.getKey(), value);
                _aspectMap.notifyAfterElementRemoved(_aspectMap, evEntry);
            }
        }
    }
    return wasRemoved;
}

From source file:eu.stratosphere.nephele.taskmanager.bytebuffered.IncomingConnectionThread.java

@Override
public void run() {

    while (!this.isInterrupted()) {

        synchronized (this.pendingReadEventSubscribeRequests) {
            while (!this.pendingReadEventSubscribeRequests.isEmpty()) {
                final SelectionKey key = this.pendingReadEventSubscribeRequests.poll();
                final IncomingConnection incomingConnection = (IncomingConnection) key.attachment();
                final SocketChannel socketChannel = (SocketChannel) key.channel();

                try {
                    final SelectionKey newKey = socketChannel.register(this.selector, SelectionKey.OP_READ);
                    newKey.attach(incomingConnection);
                } catch (ClosedChannelException e) {
                    incomingConnection.reportTransmissionProblem(key, e);
                }//w  w  w  . j  a va2s  . co m
            }
        }

        try {
            this.selector.select(500);
        } catch (IOException e) {
            LOG.error(e);
        }

        final Iterator<SelectionKey> iter = this.selector.selectedKeys().iterator();

        while (iter.hasNext()) {
            final SelectionKey key = iter.next();

            iter.remove();
            if (key.isValid()) {
                if (key.isReadable()) {
                    doRead(key);
                } else if (key.isAcceptable()) {
                    doAccept(key);
                } else {
                    LOG.error("Unknown key: " + key);
                }
            } else {
                LOG.error("Received invalid key: " + key);
            }
        }
    }

    // Do cleanup, if necessary
    if (this.listeningSocket != null) {
        try {
            this.listeningSocket.close();
        } catch (IOException ioe) {
            // Actually, we can ignore this exception
            LOG.debug(ioe);
        }
    }

    // Finally, close the selector
    try {
        this.selector.close();
    } catch (IOException ioe) {
        LOG.debug(StringUtils.stringifyException(ioe));
    }
}