Example usage for java.util Set remove

List of usage examples for java.util Set remove

Introduction

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

Prototype

boolean remove(Object o);

Source Link

Document

Removes the specified element from this set if it is present (optional operation).

Usage

From source file:com.globalsight.everest.webapp.pagehandler.administration.projects.ModifyProjectHandler.java

private void prepareUsersData(HttpServletRequest request, String action, Project project, Locale locale) {
    HttpSession session = request.getSession(false);
    SessionManager sessionMgr = (SessionManager) session.getAttribute(SESSION_MANAGER);

    List<UserInfo> defUsers = ProjectHandlerHelper.getPossibleUsersForProject(null);

    // loop through and make three lists. The first list is all
    // the Users that are available for all projects and cannot
    // be removed from a project. They are added to a project by
    // default. The second list is users that can be added
    // and removed from projects. The third list is the list of
    // added users that weren't added by default.
    ArrayList<UserInfo> possibleUsers = new ArrayList<UserInfo>();
    @SuppressWarnings("unchecked")
    Set<String> addedUsers = new TreeSet<String>(project.getUserIds());

    for (int i = 0; i < defUsers.size(); i++) {
        UserInfo userInfo = (UserInfo) defUsers.get(i);
        if (userInfo.isInAllProjects()) {
            // It's added by default, remove it from added list
            addedUsers.remove(userInfo.getUserId());
        } else {/*from  w  w  w .  j a va 2 s  .  c  o  m*/
            possibleUsers.add(userInfo);
            defUsers.remove(i--);
        }
    }

    // If we got here via a sort, then addedUsers may not be correct.
    // Check request for hidden field "toField". If it's set, use
    // that list rather than the addedUsers just calculated.
    String toField = (String) request.getParameter("toField");
    if (toField != null) {
        String[] userids = toField.split(",");
        addedUsers = new TreeSet<String>();
        for (int i = 0; i < userids.length; i++) {
            addedUsers.add(userids[i]);
        }
    } else {
        toField = new String();
        Iterator<String> iter = addedUsers.iterator();
        boolean first = true;
        while (iter.hasNext()) {
            if (first) {
                first = false;
            } else {
                toField += ",";
            }
            toField += iter.next();
        }
    }

    ArrayList<String> addedUsersIds = new ArrayList<String>();
    Iterator<String> it = addedUsers.iterator();
    while (it.hasNext()) {
        addedUsersIds.add((String) it.next());
    }

    SortUtil.sort(defUsers, new UserInfoComparator(locale));
    SortUtil.sort(possibleUsers, new UserInfoComparator(locale));
    SortUtil.sort(addedUsersIds, new StringComparator(locale));

    request.setAttribute("toField", toField);
    request.setAttribute("addedUsersIds", addedUsersIds);
    request.setAttribute("possibleUsers", possibleUsers);
    sessionMgr.setAttribute("defUsers", defUsers);

    setTableNavigation(request, session, defUsers, new UserInfoComparator(locale), 10, "numPerPage", "numPages",
            "defUsers", "sorting", "reverseSort", "pageNum", "lastPageNum", "listSize");
}

From source file:jinex.JarMetadataLoader.java

public void load(Transaction tx) throws Exception {

    String jarRow = "jar:" + jarInfo.getHash();

    if (tx.get(jarRow, new Column("count", "classes")) == null) {
        // have never seen this jar before
        tx.set(jarRow, new Column("count", "classes"), jarInfo.getClasses().size() + "");

        Map<String, Integer> pkgRefCounts = new DefaultedMap(new Integer(0));

        for (ClassMetadata classInfo : jarInfo.getClasses()) {
            String classRow = "class:" + classInfo.getName();

            if (tx.get(classRow, new Column(classInfo.getHash(), "deps")) == null) {
                // have never seen this class before, so add its dependencies
                tx.set(classRow, new Column(classInfo.getHash(), "deps"),
                        classInfo.getClassDependencies().size() + "");

                Set<String> deps = new HashSet<String>(classInfo.getClassDependencies());

                //remove existing deps
                RowIterator depIter = tx
                        .get(new ScannerConfiguration().setRange(Range.exact(classRow, "deps")));
                if (depIter.hasNext()) {
                    ColumnIterator colIter = depIter.next().getValue();
                    while (colIter.hasNext()) {
                        String existingDep = colIter.next().getKey().getQualifier().toString();
                        deps.remove(existingDep);
                    }/*from w  ww.ja  v  a 2 s  . c om*/
                }

                String packageName = getParent(classInfo.getName());

                //new dependencies for this class
                for (String dep : deps) {
                    tx.set(classRow, new Column("deps", dep), "");
                    if (packageName != null) {
                        String pkgRefCountRow = "prc:" + packageName + ":" + dep;
                        int pkgRefCount = pkgRefCounts.get(pkgRefCountRow);
                        pkgRefCounts.put(pkgRefCountRow, pkgRefCount + 1);
                    }
                }

            }

        }

        for (Entry<String, Integer> entry : pkgRefCounts.entrySet()) {
            String pkgRefCountRow = entry.getKey();
            ByteSequence currCountBS = tx.get(pkgRefCountRow, new Column("prcount", "update"));
            int pkgRefCount = entry.getValue();
            if (currCountBS != null)
                pkgRefCount += Integer.parseInt(currCountBS.toString());
            tx.set(pkgRefCountRow, new Column("prcount", "update"), pkgRefCount + "");
        }
    }

    // is this jar name known?
    if (tx.get(jarRow, new Column("names", jarInfo.getName())) == null) {
        tx.set(jarRow, new Column("names", jarInfo.getName()), "");
    }

}

From source file:de.cubeisland.engine.core.webapi.ApiServer.java

public void unsubscribe(WebSocketRequestHandler handler) {
    expectNotNull(handler, "The event name must not be null!");

    Iterator<Map.Entry<String, Set<WebSocketRequestHandler>>> iter = this.subscriptions.entrySet().iterator();

    Set<WebSocketRequestHandler> handlers;
    while (iter.hasNext()) {
        handlers = iter.next().getValue();
        handlers.remove(handler);
        if (handlers.isEmpty()) {
            iter.remove();//from  w w  w.j  av a 2  s.  com
        }
    }
}

From source file:de.cubeisland.engine.core.webapi.ApiServer.java

public void unsubscribe(String event, WebSocketRequestHandler requestHandler) {
    expectNotNull(event, "The event name must not be null!");
    expectNotNull(requestHandler, "The request handler must not be null!");
    event = event.toLowerCase(ENGLISH);/*from  w  w w.j  av a2 s .  com*/

    Set<WebSocketRequestHandler> subscribedHandlers = this.subscriptions.get(event);
    if (subscribedHandlers != null) {
        subscribedHandlers.remove(requestHandler);
        if (subscribedHandlers.isEmpty()) {
            this.subscriptions.remove(event);
        }
    }
}

From source file:com.googlecode.ehcache.annotations.impl.ExpiredElementEvictor.java

/**
 * @return Get the set of caches to do eviction for based on the full array of cache names in the cache manager
 *//*from ww w  .  ja  v a 2s  .c  o  m*/
protected Set<String> calculateEvictableCacheNames(final String[] cacheManagerCacheNames) {
    Set<String> result = new HashSet<String>();
    // from the list of matchers, calculate the cacheNames set
    for (String cacheManagerCacheName : cacheManagerCacheNames) {
        Vote vote = null;
        for (CacheNameMatcher matcher : this.cacheNameMatchers) {
            vote = matcher.matches(cacheManagerCacheName);
            if (Vote.ABSTAIN.equals(vote)) {
                continue;
            } else if (Vote.YEA.equals(vote)) {
                result.add(cacheManagerCacheName);
            } else {
                result.remove(cacheManagerCacheName);
            }
        }
    }

    return result;
}

From source file:cc.kune.core.server.content.ContentManagerDefault.java

private boolean delParticipants(final User user, final Content content, final String... participants) {
    if (content.isWave()) {
        // The author cannot be removed (by now)
        final String author = getContentAuthor(content);
        final Set<String> participantsSet = participantUtils.toSet(participants);
        participantsSet.remove(author);
        final WaveRef waveRef = KuneWaveServerUtils.getWaveRef(content);
        return kuneWaveManager.delParticipants(waveRef, user.getShortName(), participantsSet);
    }/*from   w w  w . j ava 2  s .c  om*/
    return false;
}

From source file:com.zb.app.websocket.server.WebSocketServerHandler.java

/**
 * ?WebSocketSession,Session//from  w  w  w  . j a v  a2s. c  om
 * 
 * @param session Session
 */
public void removeSession(WebSocketSession session) {
    SessionWrapper sw = getSessionInfo(session);
    if (sw == null || StringUtils.isEmpty(sw.getId())) {
        return;
    }
    ClientWrapper clientInfo = sw.getClientInfo();
    String sessionId = sw.getId();
    String ip = clientInfo.getIp();
    Long mId = clientInfo.getmId();
    try {
        session.close(CloseStatus.NORMAL);
        logger.error("WebSocketServerHandler removeSession() successfull! mid={},sessionId={},ip={}", mId,
                sessionId, ip);
    } catch (Exception e) {
        if (session != null && !session.isOpen()) {
            logger.error(
                    "WebSocketServerHandler removeSession() is Normally closed!  mid={},sessionId={},ip={}",
                    mId, sessionId, ip);
        } else {
            logger.error("WebSocketServerHandler removeSession() faild!  mid={},sessionId={},ip={}", mId,
                    sessionId, ip);
        }
    } finally {
        Set<SessionWrapper> set = sessionCacheMap.get(clientInfo);
        set.remove(sw);
        if (Argument.isEmpty(set)) {
            sessionCacheMap.remove(clientInfo);
        }
    }
}

From source file:com.pinterest.deployservice.handler.EnvironHandler.java

/**
 * UI should check the host exist and can be added first;
 * Make sure UI warn if cause env conflict with existing group capacity
 */// ww  w.  j a v a 2 s  .  co m
public void updateHosts(EnvironBean envBean, List<String> hosts, String operator) throws Exception {
    List<String> oldHostList = groupDAO.getCapacityHosts(envBean.getEnv_id());
    Set<String> oldHosts = new HashSet<>();
    oldHosts.addAll(oldHostList);
    for (String host : hosts) {
        if (!oldHosts.contains(host)) {
            groupDAO.addHostCapacity(envBean.getEnv_id(), host);
        } else {
            oldHosts.remove(host);
        }
    }
    for (String host : oldHosts) {
        groupDAO.removeHostCapacity(envBean.getEnv_id(), host);
    }
}

From source file:argendata.web.controller.AdminController.java

private void updateAppReferenced(List<String> appsId, String oldTitle, Dataset newDataset) {

    for (String aid : appsId) {
        App app = this.appService.getApprovedAppByName(aid);
        App oldApp = this.appService.getApprovedAppByName(aid);
        Set<String> datasets = app.getDataset();
        datasets.remove(oldTitle);
        datasets.add(newDataset.getTitle());
        app.setDataset(datasets);/*from w  w w  . j av  a 2 s  . c o m*/
        try {
            appService.approvedAppUpdate(oldApp, app);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

}

From source file:azkaban.app.JobManager.java

/**
 * Get all the JobDescriptors that are not dependencies for any other job.
 * /*  w ww  .j  a v  a 2  s.c  o  m*/
 * @return The set of all root JobDescriptors
 */
public Set<JobDescriptor> getRootJobDescriptors(Map<String, JobDescriptor> jobDescriptors) {
    Set<JobDescriptor> s = new HashSet<JobDescriptor>();
    s.addAll(jobDescriptors.values());
    for (JobDescriptor desc : jobDescriptors.values())
        for (JobDescriptor dep : desc.getDependencies())
            s.remove(dep);
    return s;
}