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.moviejukebox.reader.MovieNFOReader.java

/**
 * Parse the FileInfo section//from  w w  w . j  ava 2s  .c o m
 *
 * @param movie
 * @param eFileInfo
 */
private static void parseFileInfo(Movie movie, Element eFileInfo) {
    if (eFileInfo == null) {
        return;
    }

    if (OverrideTools.checkOverwriteContainer(movie, NFO_PLUGIN_ID)) {
        String container = DOMHelper.getValueFromElement(eFileInfo, "container");
        movie.setContainer(container, NFO_PLUGIN_ID);
    }

    Element eStreamDetails = DOMHelper.getElementByName(eFileInfo, "streamdetails");

    if (eStreamDetails == null) {
        return;
    }

    // Video
    NodeList nlStreams = eStreamDetails.getElementsByTagName("video");
    Node nStreams;
    for (int looper = 0; looper < nlStreams.getLength(); looper++) {
        nStreams = nlStreams.item(looper);
        if (nStreams.getNodeType() == Node.ELEMENT_NODE) {
            Element eStreams = (Element) nStreams;

            String temp = DOMHelper.getValueFromElement(eStreams, "codec");
            if (isValidString(temp)) {
                Codec videoCodec = new Codec(CodecType.VIDEO);
                videoCodec.setCodecSource(CodecSource.NFO);
                videoCodec.setCodec(temp);
                movie.addCodec(videoCodec);
            }

            if (OverrideTools.checkOverwriteAspectRatio(movie, NFO_PLUGIN_ID)) {
                temp = DOMHelper.getValueFromElement(eStreams, "aspect");
                movie.setAspectRatio(ASPECT_TOOLS.cleanAspectRatio(temp), NFO_PLUGIN_ID);
            }

            if (OverrideTools.checkOverwriteResolution(movie, NFO_PLUGIN_ID)) {
                movie.setResolution(DOMHelper.getValueFromElement(eStreams, "width"),
                        DOMHelper.getValueFromElement(eStreams, "height"), NFO_PLUGIN_ID);
            }
        }
    } // End of VIDEO

    // Audio
    nlStreams = eStreamDetails.getElementsByTagName("audio");

    for (int looper = 0; looper < nlStreams.getLength(); looper++) {
        nStreams = nlStreams.item(looper);
        if (nStreams.getNodeType() == Node.ELEMENT_NODE) {
            Element eStreams = (Element) nStreams;

            String aCodec = DOMHelper.getValueFromElement(eStreams, "codec").trim();
            String aLanguage = DOMHelper.getValueFromElement(eStreams, "language");
            String aChannels = DOMHelper.getValueFromElement(eStreams, "channels");

            // If the codec is lowercase, covert it to uppercase, otherwise leave it alone
            if (StringUtils.isAllLowerCase(aCodec)) {
                aCodec = aCodec.toUpperCase();
            }

            if (StringTools.isValidString(aLanguage)) {
                aLanguage = MovieFilenameScanner.determineLanguage(aLanguage);
            }

            Codec audioCodec = new Codec(CodecType.AUDIO, aCodec);
            audioCodec.setCodecSource(CodecSource.NFO);
            audioCodec.setCodecLanguage(aLanguage);
            audioCodec.setCodecChannels(aChannels);
            movie.addCodec(audioCodec);
        }
    } // End of AUDIO

    // Update the language
    if (OverrideTools.checkOverwriteLanguage(movie, NFO_PLUGIN_ID)) {
        Set<String> langs = new HashSet<>();
        // Process the languages and remove any duplicates
        for (Codec codec : movie.getCodecs()) {
            if (codec.getCodecType() == CodecType.AUDIO) {
                langs.add(codec.getCodecLanguage());
            }
        }

        // Remove UNKNOWN if it is NOT the only entry
        if (langs.contains(Movie.UNKNOWN) && langs.size() > 1) {
            langs.remove(Movie.UNKNOWN);
        } else if (langs.isEmpty()) {
            // Add the language as UNKNOWN by default.
            langs.add(Movie.UNKNOWN);
        }

        // Build the language string
        StringBuilder movieLanguage = new StringBuilder();
        for (String lang : langs) {
            if (movieLanguage.length() > 0) {
                movieLanguage.append(LANGUAGE_DELIMITER);
            }
            movieLanguage.append(lang);
        }
        movie.setLanguage(movieLanguage.toString(), NFO_PLUGIN_ID);
    }

    // Subtitles
    List<String> subtitles = new ArrayList<>();
    nlStreams = eStreamDetails.getElementsByTagName("subtitle");
    for (int looper = 0; looper < nlStreams.getLength(); looper++) {
        nStreams = nlStreams.item(looper);
        if (nStreams.getNodeType() == Node.ELEMENT_NODE) {
            Element eStreams = (Element) nStreams;
            subtitles.add(DOMHelper.getValueFromElement(eStreams, "language"));
        }
    }
    SubtitleTools.setMovieSubtitles(movie, subtitles);
}

From source file:com.skelril.skree.content.zone.group.jungleraid.JungleRaidInstance.java

public void playerLost(Player player) {
    participants.remove(player);/*from  ww  w .j  a va 2 s.com*/

    Set<Player> teamPlayers = teamMapping.remove(player);
    if (teamPlayers != null) {
        teamPlayers.remove(player);

        player.getInventory().clear();
    }
}

From source file:com.spotify.heroic.cluster.CoreClusterManager.java

/**
 * Operation that takes the existing list of clients, compares it to a collection of resolved
 * URIs and determines which nodes should be updated, and which should be removed.
 *
 * @param id id of the operation/*w w w. j ava  2s  .  c om*/
 * @return a lazy transform
 */
LazyTransform<Collection<List<URI>>, Void> refreshSweep(final String id) {
    return uriLists -> {
        final List<URI> uris = ImmutableList.copyOf(Iterables.concat(uriLists));

        final List<AsyncFuture<Update>> updated = new ArrayList<>();
        final List<RemovedNode> removedNodes = new ArrayList<>();

        final Map<URI, ClusterNode> oldClients = this.clients.get();

        if (oldClients == null) {
            log.warn("{}: Aborting refresh, shutting down", id);
            return async.resolved();
        }

        final Set<URI> removedUris = new HashSet<>(oldClients.keySet());

        for (final URI uri : uris) {
            final ClusterNode node = oldClients.get(uri);
            removedUris.remove(uri);

            if (node == null) {
                /* first time URI has been seen, resolve new node */
                updated.add(createClusterNode(id, uri));
                continue;
            }

            /* re-query metadata for nodes already known and make sure it matches.
             * if it does not match, create a new cluster node and close the old one.
             * otherwise, re-use the existing node */
            updated.add(node.fetchMetadata().lazyTransform(m -> {
                if (!node.metadata().equals(m)) {
                    /* add to removedNodes list to make sure it is being closed */
                    removedNodes.add(new RemovedNode(uri, node));
                    return createClusterNode(id, uri);
                }

                return async.resolved(new SuccessfulUpdate(uri, false, node));
            }).catchFailed(Update.error(uri)));
        }

        /* all the nodes that have not been seen in the updates list of uris have been removed
         * and should be closed */
        for (final URI uri : removedUris) {
            final ClusterNode remove = oldClients.get(uri);

            if (remove != null) {
                removedNodes.add(new RemovedNode(uri, remove));
            }
        }

        return async.collect(updated).lazyTransform(refreshLogAndPrepare(id, removedNodes, oldClients));
    };
}

From source file:edu.wisc.my.portlets.bookmarks.domain.Folder.java

/**
 * @see java.lang.Object#toString()//from w w  w  .  j  a  v  a2 s  .c  o m
 */
public String toString() {
    final Set<Integer> visited = toStringVisitedFolder.getSet();
    final int identityHash = System.identityHashCode(this);
    try {
        if (!visited.add(identityHash)) {
            visited.clear();
            throw new IllegalStateException("A loop exists in the Folder tree.");
        }

        return new ToStringBuilder(this).appendSuper(super.toString()).append("children", this.children)
                .append("minimized", this.minimized).toString();
    } finally {
        visited.remove(identityHash);
    }
}

From source file:org.alfresco.mobile.android.api.services.impl.onpremise.OnPremiseDocumentFolderServiceImpl.java

private void favoriteNode(Node node, boolean addFavorite) {
    if (isObjectNull(node)) {
        throw new IllegalArgumentException(
                String.format(Messagesl18n.getString("ErrorCodeRegistry.GENERAL_INVALID_ARG_NULL"), "node"));
    }// ww  w.  java 2  s . c  om

    try {
        String cleanIdentifier = NodeRefUtils.getCleanIdentifier(node.getIdentifier());
        String joined = cleanIdentifier;

        String link = OnPremiseUrlRegistry.getUserPreferenceUrl(session, session.getPersonIdentifier());
        UrlBuilder url = new UrlBuilder(link);

        List<String> favoriteIdentifier = null;
        String filter = OnPremiseUrlRegistry.PREFERENCE_FAVOURITES_DOCUMENTS;
        if (node.isFolder()) {
            filter = OnPremiseUrlRegistry.PREFERENCE_FAVOURITES_FOLDERS;
        }

        String[] favs = parsePreferenceResponse(session, session.getPersonIdentifier(), filter);
        if (favs != null) {
            favoriteIdentifier = new ArrayList<String>(Arrays.asList(favs));
            Set<String> index = new HashSet<String>(favoriteIdentifier);

            boolean hasIdentifier = index.contains(cleanIdentifier);

            if (addFavorite && !hasIdentifier) {
                favoriteIdentifier.add(cleanIdentifier);
                joined = TextUtils.join(",", favoriteIdentifier);
            } else if (!addFavorite && hasIdentifier) {
                index.remove(cleanIdentifier);
                joined = TextUtils.join(",", index.toArray(new String[0]));
            } else {
                // Throw exceptions ????
            }
        }

        // prepare json data
        String[] sitePrefence = filter.split("\\.");

        int length = sitePrefence.length - 1;

        JSONObject jroot = new JSONObject();
        JSONObject jt = null;
        JSONObject jp = jroot;
        for (int i = 0; i < length; i++) {
            jt = new JSONObject();
            jp.put(sitePrefence[i], jt);
            jp = jt;
        }

        jt.put(OnPremiseUrlRegistry.FAVOURITES, joined);

        final JsonDataWriter formDataM = new JsonDataWriter(jroot);

        // send
        post(url, formDataM.getContentType(), new Output() {
            public void write(OutputStream out) throws IOException {
                formDataM.write(out);
            }
        }, ErrorCodeRegistry.DOCFOLDER_GENERIC);
    } catch (Exception e) {
        convertException(e);
    }
}

From source file:com.idega.slide.authentication.AuthenticationBusinessBean.java

private void updateRoleMembershipForUser(WebdavResource role, String userURI, Set roleNamesForUser,
        Set userpathsOfAllLoggedOnUsers) throws HttpException, RemoteException, IOException {
    // System.out.println("[AuthenticationBusiness]: resouce "+role.getDisplayName()+" begins");
    boolean someChanges = false;
    try {/*from w w w. j  ava  2s .c  o m*/
        Enumeration e = role.propfindMethod(GROUP_MEMBER_SET);
        String propertyString = "";
        while (e.hasMoreElements()) {
            propertyString += (String) e.nextElement();
        }
        // System.out.println("\t[group-member-set1]: "+propertyString);

        Set userSet = parseGroupMemberSetPropertyString(propertyString);

        if (userpathsOfAllLoggedOnUsers != null) {
            String rootUser = getUserURI(SLIDE_DEFAULT_ROOT_USER);
            for (Iterator iter = userSet.iterator(); iter.hasNext();) {
                String token = (String) iter.next();
                if (!rootUser.equals(token) && !userpathsOfAllLoggedOnUsers.contains(token)) {
                    userSet.remove(token);
                    someChanges = true;
                }
            }
        }

        boolean userIsInRole = userSet.contains(userURI);
        boolean userShouldBeInRole = SLIDE_ROLE_NAME_USER.equals(role.getDisplayName())
                || roleNamesForUser.contains(role.getDisplayName());

        if (!userIsInRole && userShouldBeInRole) {
            userSet.add(userURI);
            someChanges = true;
        } else if (userIsInRole && !userShouldBeInRole) {
            userSet.remove(userURI);
            someChanges = true;
        }

        if (someChanges) {
            String newGroupMemberSet = encodeGroupMemberSetPropertyString(userSet);

            role.proppatchMethod(GROUP_MEMBER_SET_PROPERTY_NAME, newGroupMemberSet, true);

            // Enumeration e2 = role.propfindMethod(GROUP_MEMBER_SET);
            // if (e2.hasMoreElements()) {
            // String element2 = (String) e2.nextElement();
            // System.out.println("\t[group-member-set2]: "+element2);
            // }
        }
    } catch (HttpException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    // System.out.println("[AuthenticationBusiness]: resouce "+role.getDisplayName()+" ends");
}

From source file:io.kahu.hawaii.domain.FieldChecker.java

private Set<String> getFieldNames(Object bean) {
    Class<?> beanClass = bean.getClass();

    Set<String> fieldNames = new HashSet<String>();

    /*/*from  w ww  .ja  v  a  2 s .c o  m*/
     * Add all properties from this class.
     */
    PropertyDescriptor[] propertyDescriptors = PropertyUtils.getPropertyDescriptors(beanClass);
    for (PropertyDescriptor propertyDescriptor : propertyDescriptors) {
        fieldNames.add(propertyDescriptor.getName());
    }

    /*
     * Remove all properties from the interface 'ValueHolder'.
     */
    propertyDescriptors = PropertyUtils.getPropertyDescriptors(ValueHolder.class);
    for (PropertyDescriptor propertyDescriptor : propertyDescriptors) {
        fieldNames.remove(propertyDescriptor.getName());
    }
    /*
     * Remove all properties from the interface 'ValueHolder'.
     */
    propertyDescriptors = PropertyUtils.getPropertyDescriptors(ValidatableDomainObject.class);
    for (PropertyDescriptor propertyDescriptor : propertyDescriptors) {
        fieldNames.remove(propertyDescriptor.getName());
    }

    /*
     * Ignore class
     */
    fieldNames.remove("callbacks");
    fieldNames.remove("callback");
    fieldNames.remove("class");
    return fieldNames;
}

From source file:org.elasticsearch.client.RestClientMultipleHostsTests.java

public void testRoundRobinOkStatusCodes() throws IOException {
    int numIters = RandomNumbers.randomIntBetween(getRandom(), 1, 5);
    for (int i = 0; i < numIters; i++) {
        Set<HttpHost> hostsSet = new HashSet<>();
        Collections.addAll(hostsSet, httpHosts);
        for (int j = 0; j < httpHosts.length; j++) {
            int statusCode = randomOkStatusCode(getRandom());
            Response response = restClient.performRequest(randomHttpMethod(getRandom()), "/" + statusCode);
            assertEquals(statusCode, response.getStatusLine().getStatusCode());
            assertTrue("host not found: " + response.getHost(), hostsSet.remove(response.getHost()));
        }//ww  w.ja v a 2 s  . c om
        assertEquals("every host should have been used but some weren't: " + hostsSet, 0, hostsSet.size());
    }
    failureListener.assertNotCalled();
}

From source file:net.solarnetwork.central.dras.dao.ibatis.test.IbatisUserDaoTest.java

@Test
public void updateUserRoles() {
    setUserRoles();/*www  .ja  v a2s .  c  o m*/
    Set<UserRole> roles = userDao.getUserRoles(lastUserId);
    roles.remove(roles.iterator().next());
    Set<String> members = new HashSet<String>();
    for (UserRole role : roles) {
        members.add(role.getId());
    }
    userDao.assignUserRoles(lastUserId, members);

    Set<UserRole> found = userDao.getUserRoles(lastUserId);
    validateRoles(roles, found);
}

From source file:com.shenit.commons.utils.HttpUtils.java

/**
 * ?cookie//www. jav a 2s.  c  o  m
 * 
 * @param req
 *            
 * @param names
 *            cookie??
 */
public static void purgeCookies(HttpServletRequest req, HttpServletResponse resp, String... names) {
    Set<String> nameSet = ValidationUtils.isEmpty(names) ? null : new HashSet<String>(Arrays.asList(names));
    boolean removeAll = ValidationUtils.isEmpty(nameSet);
    for (Cookie cookie : req.getCookies()) {
        if (removeAll || nameSet.contains(cookie.getName())) {
            cookie.setMaxAge(0);
            cookie.setValue(null);
            resp.addCookie(cookie);
            if (!removeAll)
                nameSet.remove(cookie.getName());
            ;
        }
    }
}