Example usage for java.util Set removeAll

List of usage examples for java.util Set removeAll

Introduction

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

Prototype

boolean removeAll(Collection<?> c);

Source Link

Document

Removes from this set all of its elements that are contained in the specified collection (optional operation).

Usage

From source file:com.qmetry.qaf.automation.step.client.AbstractScenarioFileParser.java

/**
 * To apply groups and enabled filter/*from  w  w  w  .  j  a  v  a 2 s.  c  o  m*/
 * 
 * @param includeGroups
 * @param excludeGroups
 * @param metadata
 * @return
 */
@SuppressWarnings("unchecked")
protected boolean include(List<String> includeGroups, List<String> excludeGroups,
        Map<String, Object> metadata) {
    // check for enabled
    if (metadata.containsKey("enabled") && !((Boolean) metadata.get("enabled")))
        return false;

    Set<Object> groups = new HashSet<Object>(
            metadata.containsKey(ScenarioFactory.GROUPS) ? (List<String>) metadata.get(ScenarioFactory.GROUPS)
                    : new ArrayList<String>());
    if (!includeGroups.isEmpty()) {
        groups.retainAll(includeGroups);
    }
    groups.removeAll(excludeGroups);
    return (!groups.isEmpty() || (includeGroups.isEmpty() && excludeGroups.isEmpty()));
}

From source file:edu.umass.cs.reconfiguration.reconfigurationutils.ConsistentReconfigurableNodeConfig.java

private synchronized boolean refreshActives() {
    Set<NodeIDType> curActives = this.nodeConfig.getActiveReplicas();
    // remove those slated for removal for CH ring purposes
    curActives.removeAll(this.activesSlatedForRemoval);
    if (curActives.equals(this.getLastActives()))
        return false;
    this.setLastActives(curActives);
    this.CH_AR.refresh(curActives);
    return true;/* ww  w.ja va2 s. c  o  m*/
}

From source file:org.modeshape.web.jcr.rest.handler.ItemHandlerImpl.java

private Set<String> updateMixins(Node node, Object mixinsJsonValue) throws RepositoryException {
    Object valuesObject = convertToJcrValues(node, mixinsJsonValue, false);
    Value[] values = null;// w w  w .  j  a v a 2s  .co  m
    if (valuesObject == null) {
        values = new Value[0];
    } else if (valuesObject instanceof Value[]) {
        values = (Value[]) valuesObject;
    } else {
        values = new Value[] { (Value) valuesObject };
    }

    Set<String> jsonMixins = new HashSet<String>(values.length);
    for (Value theValue : values) {
        jsonMixins.add(theValue.getString());
    }

    Set<String> mixinsToRemove = new HashSet<String>();
    for (NodeType nodeType : node.getMixinNodeTypes()) {
        mixinsToRemove.add(nodeType.getName());
    }

    Set<String> mixinsToAdd = new HashSet<String>(jsonMixins);
    mixinsToAdd.removeAll(mixinsToRemove);
    mixinsToRemove.removeAll(jsonMixins);

    for (String nodeType : mixinsToAdd) {
        node.addMixin(nodeType);
    }

    // return the list of mixins to be removed, as that needs to be processed last due to type validation
    return mixinsToRemove;
}

From source file:com.googlecode.noweco.webmail.lotus.LotusWebmailConnection.java

public Set<String> delete(final Set<String> messageUids) throws IOException {
    Set<String> deleted = new HashSet<String>();
    // deleted in first but not deleted in second
    deleted.addAll(tryDelete(messageUids));
    // second time because deleting a deleted lotus message restore it
    // message deleted on second time may or may be not deleted so keep in cache
    deleted.removeAll(tryDelete(messageUids));
    return deleted;
}

From source file:org.cloudfoundry.identity.uaa.scim.endpoints.ScimUserEndpoints.java

private ScimUser syncGroups(ScimUser user) {
    if (user == null) {
        return user;
    }// w w w . ja  v  a 2 s  . c  om

    Set<ScimGroup> directGroups = membershipManager.getGroupsWithMember(user.getId(), false);
    Set<ScimGroup> indirectGroups = membershipManager.getGroupsWithMember(user.getId(), true);
    indirectGroups.removeAll(directGroups);
    Set<ScimUser.Group> groups = new HashSet<ScimUser.Group>();
    for (ScimGroup group : directGroups) {
        groups.add(new ScimUser.Group(group.getId(), group.getDisplayName(), ScimUser.Group.Type.DIRECT));
    }
    for (ScimGroup group : indirectGroups) {
        groups.add(new ScimUser.Group(group.getId(), group.getDisplayName(), ScimUser.Group.Type.INDIRECT));
    }

    user.setGroups(groups);
    return user;
}

From source file:edu.umass.cs.reconfiguration.reconfigurationutils.ConsistentReconfigurableNodeConfig.java

private synchronized boolean refreshReconfigurators() {
    Set<NodeIDType> curReconfigurators = this.nodeConfig.getReconfigurators();
    // remove those slated for removal for CH ring purposes
    curReconfigurators.removeAll(this.reconfiguratorsSlatedForRemoval);
    if (curReconfigurators.equals(this.getLastReconfigurators()))
        return false;
    this.setLastReconfigurators(curReconfigurators);
    this.CH_RC.refresh(curReconfigurators);
    return true;/*from   ww  w  .ja va2s. c om*/
}

From source file:net.longfalcon.newsj.FetchBinaries.java

@Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.READ_COMMITTED)
public long scan(NewsClient nntpClient, Group group, long firstArticle, long lastArticle, String type,
        boolean compressedHeaders) throws IOException {
    // this is a hack - tx is not working ATM
    TransactionStatus transaction = transactionManager
            .getTransaction(new DefaultTransactionDefinition(TransactionDefinition.PROPAGATION_REQUIRED));

    long startHeadersTime = System.currentTimeMillis();

    long maxNum = 0;
    Map<String, Message> messages = new LinkedHashMap<>(MESSAGE_BUFFER + 1);

    Iterable<NewsArticle> articlesIterable = null;
    try {//from  w ww .java 2  s . c o  m
        if (compressedHeaders) {
            _log.warn("Compressed Headers setting not currently functional");
            articlesIterable = nntpClient.iterateArticleInfo(firstArticle, lastArticle);
        } else {
            articlesIterable = nntpClient.iterateArticleInfo(firstArticle, lastArticle);
        }
    } catch (IOException e) {
        _log.error(e.toString());
        if (nntpClient.getReplyCode() == 400) {
            _log.info("NNTP connection timed out. Reconnecting...");
            nntpClient = nntpConnectionFactory.getNntpClient();
            nntpClient.selectNewsgroup(group.getName());
            articlesIterable = nntpClient.iterateArticleInfo(firstArticle, lastArticle);
        }
    }

    Period headersTime = new Period(startHeadersTime, System.currentTimeMillis());

    Set<Long> rangeRequested = ArrayUtil.rangeSet(firstArticle, lastArticle);
    Set<Long> messagesReceived = new HashSet<>();
    Set<Long> messagesBlacklisted = new HashSet<>();
    Set<Long> messagesIgnored = new HashSet<>();
    Set<Long> messagesInserted = new HashSet<>();
    Set<Long> messagesNotInserted = new HashSet<>();

    // check error codes?

    long startUpdateTime = System.currentTimeMillis();

    if (articlesIterable != null) {
        for (NewsArticle article : articlesIterable) {
            long articleNumber = article.getArticleNumberLong();

            if (articleNumber == 0) {
                continue;
            }

            messagesReceived.add(articleNumber);

            Pattern pattern = Defaults.PARTS_SUBJECT_REGEX;
            String subject = article.getSubject();
            Matcher matcher = pattern.matcher(subject);
            if (ValidatorUtil.isNull(subject) || !matcher.find()) {
                // not a binary post most likely.. continue
                messagesIgnored.add(articleNumber);
                if (_log.isDebugEnabled()) {
                    _log.debug(String.format("Skipping message no# %s : %s", articleNumber, subject));
                }
                continue;
            }

            //Filter binaries based on black/white list
            if (isBlacklisted(article, group)) {
                messagesBlacklisted.add(articleNumber);
                continue;
            }
            String group1 = matcher.group(1);
            String group2 = matcher.group(2);
            if (ValidatorUtil.isNumeric(group1) && ValidatorUtil.isNumeric(group2)) {
                int currentPart = Integer.parseInt(group1);
                int maxParts = Integer.parseInt(group2);
                subject = (matcher.replaceAll("")).trim();

                if (!messages.containsKey(subject)) {
                    messages.put(subject, new Message(article, currentPart, maxParts));
                } else if (currentPart > 0) {
                    Message message = messages.get(subject);
                    String articleId = article.getArticleId();
                    String messageId = articleId.substring(1, articleId.length() - 1);
                    int size = article.getSize();
                    message.addPart(currentPart, messageId, articleNumber, size);
                    messages.put(subject, message);
                }
            }
        }

        long count = 0;
        long updateCount = 0;
        long partCount = 0;
        maxNum = lastArticle;

        // add all the requested then remove the ones we did receive.
        Set<Long> rangeNotRecieved = new HashSet<>();
        rangeNotRecieved.addAll(rangeRequested);
        rangeNotRecieved.removeAll(messagesReceived);

        if (!type.equals("partrepair")) {
            _log.info(String.format("Received %d articles of %d requested, %d blacklisted, %d not binaries",
                    messagesReceived.size(), lastArticle - firstArticle + 1, messagesBlacklisted.size(),
                    messagesIgnored.size()));
        }

        if (rangeNotRecieved.size() > 0) {
            switch (type) {
            case "backfill":
                // don't add missing articles
                break;
            case "partrepair":
            case "update":
            default:
                addMissingParts(rangeNotRecieved, group);
                break;
            }
            _log.info("Server did not return article numbers " + ArrayUtil.stringify(rangeNotRecieved));
        }

        if (!messages.isEmpty()) {

            long dbUpdateTime = 0;
            maxNum = firstArticle;
            //insert binaries and parts into database. when binary already exists; only insert new parts
            for (Map.Entry<String, Message> entry : messages.entrySet()) {
                String subject = entry.getKey();
                Message message = entry.getValue();

                Map<Integer, MessagePart> partsMap = message.getPartsMap();
                if (!ValidatorUtil.isNull(subject) && !partsMap.isEmpty()) {
                    String binaryHash = EncodingUtil
                            .md5Hash(subject + message.getFrom() + String.valueOf(group.getId()));
                    Binary binary = binaryDAO.findByBinaryHash(binaryHash);
                    if (binary == null) {
                        long startDbUpdateTime = System.currentTimeMillis();
                        binary = new Binary();
                        binary.setName(subject);
                        binary.setFromName(message.getFrom());
                        binary.setDate(message.getDate().toDate());
                        binary.setXref(message.getxRef());
                        binary.setTotalParts(message.getMaxParts());
                        binary.setGroupId(group.getId());
                        binary.setBinaryHash(binaryHash);
                        binary.setDateAdded(new Date());
                        binaryDAO.updateBinary(binary);
                        dbUpdateTime += (System.currentTimeMillis() - startDbUpdateTime);
                        count++;
                        if (count % 500 == 0) {
                            _log.info(String.format("%s bin adds...", count));
                        }
                    } else {
                        updateCount++;
                        if (updateCount % 500 == 0) {
                            _log.info(String.format("%s bin updates...", updateCount));
                        }
                    }

                    long binaryId = binary.getId();
                    if (binaryId == 0) {
                        throw new RuntimeException("ID for binary wasnt set.");
                    }

                    for (MessagePart messagePart : message.getPartsMap().values()) {
                        long articleNumber = messagePart.getArticleNumber();
                        maxNum = (articleNumber > maxNum) ? articleNumber : maxNum;
                        partCount++;
                        // create part - its possible some bugs are happening here.
                        Part part = new Part();
                        part.setBinaryId(binaryId);
                        part.setMessageId(messagePart.getMessageId());
                        part.setNumber(messagePart.getArticleNumber());
                        part.setPartNumber(messagePart.getPartNumber());
                        part.setSize(messagePart.getSize());
                        part.setDateAdded(new Date());
                        try {
                            long startDbUpdateTime = System.currentTimeMillis();
                            partDAO.updatePart(part);
                            dbUpdateTime += (System.currentTimeMillis() - startDbUpdateTime);
                            messagesInserted.add(messagePart.getArticleNumber());
                        } catch (Exception e) {
                            _log.error(e.toString());
                            messagesNotInserted.add(messagePart.getArticleNumber());
                        }

                    }
                }
            }
            //TODO: determine whether to add to missing articles if insert failed
            if (messagesNotInserted.size() > 0) {
                _log.warn("WARNING: Parts failed to insert");
                addMissingParts(messagesNotInserted, group);
            }
            Period dbUpdatePeriod = new Period(dbUpdateTime);
            _log.info("Spent " + _periodFormatter.print(dbUpdatePeriod) + " updating the db");
        }
        Period updateTime = new Period(startUpdateTime, System.currentTimeMillis());

        if (!type.equals("partrepair")) {
            _log.info(count + " new, " + updateCount + " updated, " + partCount + " parts.");
            _log.info(" " + _periodFormatter.print(headersTime) + " headers, "
                    + _periodFormatter.print(updateTime) + " update.");
        }
        transactionManager.commit(transaction);
        return maxNum;
    } else {
        _log.error("Error: Can't get parts from server (msgs not array)\n Skipping group");
        return 0;
    }

}

From source file:de.blizzy.backup.settings.SettingsDialog.java

private void removeFolder() {
    @SuppressWarnings("unchecked")
    List<String> selectedFolders = ((IStructuredSelection) foldersViewer.getSelection()).toList();
    @SuppressWarnings("unchecked")
    Set<ILocation> folders = (Set<ILocation>) foldersViewer.getInput();
    folders.removeAll(selectedFolders);
    foldersViewer.remove(selectedFolders.toArray(new ILocation[0]));
}

From source file:com.conwet.silbops.model.Subscription.java

/**
 * A {@linkplain Subscription} matches an advertise if its attributes are a subset
 * of advertise ones./*  w ww.  j  av a  2 s  .  c o  m*/
 * 
 * @param advertise the {@linkplain Advertise} to match
 * @return true if match the given advertise, false otherwise.
 */
public boolean match(Advertise advertise) {

    Set<Attribute> subscriptionAttributes = new HashSet<>(constraints.keySet());
    subscriptionAttributes.removeAll(advertise.getAttributes());

    return subscriptionAttributes.isEmpty();
}