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:at.tugraz.ist.akm.webservice.requestprocessor.interceptor.HttpClientBackLog.java

private int tryFreeAtLeast(int targetCount) {
    int freed = 0;
    Iterator<Map.Entry<Integer, Long>> iter = mClientBacklog.entrySet().iterator();

    while (iter.hasNext()) {
        Map.Entry<Integer, Long> entry = iter.next();
        if (entry.getValue() < System.currentTimeMillis()) {
            iter.remove();
            freed++;/*from w w w  .  j  a  va  2  s.  co  m*/
            if (freed >= targetCount) {
                break;
            }
        }
    }
    return freed;
}

From source file:at.alladin.rmbt.util.tools.InformationCollectorTool.java

/**
 * /* ww  w  .j a v a  2s  .c  o m*/
 * @param collector
 */
public void removeCollector(final Collector<?, ?> collector) {
    Iterator<CollectorHolder> iterator = collectorList.iterator();
    while (iterator.hasNext()) {
        CollectorHolder holder = iterator.next();
        if (holder.collector == collector) {
            iterator.remove();
        }
    }
}

From source file:com.github.jsonj.JsonSet.java

@Override
public boolean remove(Object o) {
    if (strategy == null) {
        return super.remove(o);
    } else {/*from  ww w .j av  a2  s.  c om*/
        Iterator<JsonElement> it = iterator();
        while (it.hasNext()) {
            JsonElement jsonElement = it.next();
            if (strategy.equals((JsonElement) o, jsonElement)) {
                it.remove();
                return true;
            }
        }
    }
    return false;
}

From source file:com.dianping.lion.web.tag.SubNavigator.java

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

From source file:au.com.jwatmuff.eventmanager.gui.player.PlayerListTableModel.java

public void updateTableFromDatabase() {
    List<Player> players;/*from w  w  w  .j  av a  2  s .co  m*/

    // only fetch players in selected division
    if (fromDivision == null || fromDivision.getID() == -1) {
        players = database.findAll(Player.class, PlayerDAO.ALL);
    } else {
        players = database.findAll(Player.class, PlayerDAO.FOR_POOL, fromDivision.getID(), true);
        players.addAll(database.findAll(Player.class, PlayerDAO.FOR_POOL, fromDivision.getID(), false));
    }

    // filter out name based on search
    if (!StringUtils.isEmpty(nameStartingWith)) {
        Iterator<Player> iter = players.iterator();
        while (iter.hasNext()) {
            Player player = iter.next();
            if (!player.getLastName().toLowerCase().startsWith(nameStartingWith.toLowerCase())
                    && !player.getFirstName().toLowerCase().startsWith(nameStartingWith.toLowerCase())) {
                iter.remove();
            }
        }
    }

    setPlayers(players);
}

From source file:de.voolk.marbles.persistence.services.ApplicationInitialisationService.java

@Override
public void importAuthentificationData(Collection<User> users) {
    for (User user : users) {
        Set<String> rolesFromDatabase = new HashSet<String>();
        Iterator<Role> rolesIter = user.getRoles().iterator();
        while (rolesIter.hasNext()) {
            Role role = rolesIter.next();
            Role dbRole = authentificationService.findRoleByName(role.getName());
            if (dbRole == null) {
                dbRole = authentificationService.createRole(role.getName());
            }// www .  ja v a2s  .c  om
            rolesIter.remove();
            rolesFromDatabase.add(dbRole.getName());
        }
        User dbUser = authentificationService.findUserByName(user.getName());
        if (dbUser == null) {
            authentificationService.persistUser(user);
        } else {
            user = dbUser;
        }
        if (!rolesFromDatabase.isEmpty()) {
            authentificationService.setRolesToUser(user.getId(), rolesFromDatabase.toArray(new String[] {}));
        }
    }
}

From source file:org.shaf.server.controller.ActionProcessController.java

/**
 * Launches the process execution,//w ww. j  a v  a 2s .  c  om
 * 
 * @param cmd
 *            the command which launches a process.
 * @return the view model.
 * @throws Exception
 *             is the view constructing has failed.
 */
@RequestMapping(value = "/launch/{cmd}", method = RequestMethod.POST)
public ModelAndView onLaunch(@PathVariable String cmd) throws Exception {
    LOG.debug("CALL: /proc/action/launch/{" + cmd + "}");

    // Launching parameters extraction.
    BiMap<String, String> params = HashBiMap.create();
    Enumeration<String> names = REQUEST.getParameterNames();
    while (names.hasMoreElements()) {
        String name = names.nextElement();
        String value = REQUEST.getParameter(name);
        LOG.debug("PARAMS: " + name + "=" + value);

        if (name.startsWith("radio")) {
            String group = name.substring(0, name.indexOf('-'));
            String quantifier = name.substring(name.indexOf('-') + 1);

            if (quantifier.equals("opt")) {
                // This is a selected radio button option.
                if (params.containsKey(name)) {
                    params.inverse().put(params.get(name), value);
                } else {
                    params.put(value, group + "-arg");
                }
            } else {
                // This is a selected radio button argument.
                if (params.inverse().containsKey(name)) {
                    params.put(params.inverse().get(name), value);
                } else {
                    params.inverse().put(value, group + "-opt");
                }
            }
        } else {
            params.put(name, value);
        }
    }

    // Launching parameters cleanup.
    Iterator<String> keys = params.keySet().iterator();
    while (keys.hasNext()) {
        String key = keys.next();
        if (key.startsWith("radio")) {
            keys.remove();
        } else {

            String value = params.get(key);
            if (value == null) {
                params.put(key, "");
            } else {
                if (value.startsWith("radio")) {
                    params.put(key, "");
                }
            }
        }

    }

    StringBuilder args = new StringBuilder();
    if (params.containsKey("command-line")) {
        args.append(params.get("command-line"));
    } else {
        for (Map.Entry<String, String> param : params.entrySet()) {
            if (args.length() > 0) {
                args.append(' ');
            }
            args.append('-');
            args.append(param.getKey());
            if (!param.getValue().isEmpty()) {
                args.append(' ');
                if (param.getValue().contains(" ")) {
                    args.append('\"' + param.getValue() + '\"');
                } else {
                    args.append(param.getValue());
                }
            }
        }
    }

    String id = OPER.launchProcess(cmd, args.toString());

    return ViewJob.getInfoView().header("job", "Job: " + id).addJobId(id).addJobActiveStatus(true)
            .addJobFailedStatus(false).addJobOutcome(OPER.getJobOutcome(id))
            .info("The job execution in progress.");
}

From source file:org.taverna.server.master.ContentsDescriptorBuilder.java

/**
 * Build a description of a list value./*from   ww w.  j  a va2 s.com*/
 * 
 * @param dir
 *            The directory representing the list.
 * @param ub
 *            The factory for URIs.
 * @return A value descriptor.
 * @throws FilesystemAccessException
 *             If anything goes wrong.
 */
private ListValue constructListValue(Directory dir, UriBuilder ub) throws FilesystemAccessException {
    ListValue v = new ListValue();
    v.length = 0;
    Set<DirectoryEntry> contents = new HashSet<>(dir.getContents());
    Iterator<DirectoryEntry> it = contents.iterator();
    while (it.hasNext())
        if (!it.next().getName().matches("^[0-9]+([.].*)?$"))
            it.remove();
    for (int i = 1; !contents.isEmpty(); i++) {
        String exact = Integer.toString(i);
        AbstractValue subval = constructValue(contents, ub, exact);
        v.contents.add(subval);
        if (!(subval instanceof AbsentValue)) {
            v.length = i;
            String pfx = i + ".";
            for (DirectoryEntry de : contents)
                if (de.getName().equals(exact) || de.getName().startsWith(pfx)) {
                    contents.remove(de);
                    break;
                }
        }
    }
    return v;
}

From source file:com.muk.services.security.DefaultUaaLoginService.java

private void removeCookie(List<String> cookies, String name) {
    final Iterator<String> iterator = cookies.iterator();

    while (iterator.hasNext()) {
        final String current = iterator.next();
        if (current.startsWith(name)) {
            iterator.remove();
        }/* www . j a v  a 2 s.c  o m*/
    }
}

From source file:com.yy.kunka.core.workflow.state.ActivityStateManagerImpl.java

@Override
public void clearRegionState(String region) {
    RollbackStateLocal rollbackStateLocal = getRollbackStateLocal();
    List<StateContainer> containers = stateMap
            .get(rollbackStateLocal.getThreadId() + "_" + rollbackStateLocal.getWorkflowId());
    if (containers != null) {
        Iterator<StateContainer> itr = containers.iterator();
        while (itr.hasNext()) {
            String myRegion = itr.next().getRegion();
            if ((region == null && myRegion == null) || (region != null && region.equals(myRegion))) {
                itr.remove();
                break;
            }//from  w  w  w  .ja  v a 2 s  .  c  o m
        }
    }
}