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:org.springframework.xd.distributed.util.ServerProcessUtils.java

/**
 * Block the executing thread until all of the indicated process IDs
 * have been identified in the list of runtime containers as indicated
 * by the admin server. If an empty list is provided, the executing
 * thread will block until there are no containers running.
 *
 * @param template REST template used to communicate with the admin server
 * @param pids     set of process IDs for the expected containers
 * @return map of process id to container id
 * @throws InterruptedException            if the executing thread is interrupted
 * @throws java.lang.IllegalStateException if the number of containers identified
 *         does not match the number of PIDs provided
 *///from w w  w. j ava 2  s  .co  m
public static Map<Long, String> waitForContainers(SpringXDTemplate template, Set<Long> pids)
        throws InterruptedException, IllegalStateException {
    int pidCount = pids.size();
    Map<Long, String> mapPidUuid = getRunningContainers(template);
    long expiry = System.currentTimeMillis() + 3 * 60000;

    while (mapPidUuid.size() != pidCount && System.currentTimeMillis() < expiry) {
        Thread.sleep(500);
        mapPidUuid = getRunningContainers(template);
    }

    if (mapPidUuid.size() == pidCount && mapPidUuid.keySet().containsAll(pids)) {
        return mapPidUuid;
    }

    Set<Long> missingPids = new HashSet<Long>(pids);
    missingPids.removeAll(mapPidUuid.keySet());

    Set<Long> unexpectedPids = new HashSet<Long>(mapPidUuid.keySet());
    unexpectedPids.removeAll(pids);

    StringBuilder builder = new StringBuilder();
    if (!missingPids.isEmpty()) {
        builder.append("Admin server did not find the following container PIDs:").append(missingPids);
    }
    if (!unexpectedPids.isEmpty()) {
        if (builder.length() > 0) {
            builder.append("; ");
        }
        builder.append("Admin server found the following unexpected container PIDs:").append(unexpectedPids);
    }

    throw new IllegalStateException(builder.toString());
}

From source file:com.haulmont.cuba.gui.components.filter.UserSetHelper.java

public static String removeIds(Set<String> current, Collection entities) {
    Set<String> convertedSet = new HashSet<>();
    for (Object entity : entities) {
        convertedSet.add(((BaseUuidEntity) entity).getId().toString());
    }//from  w w  w.j a  va  2 s.c o m
    current.removeAll(convertedSet);
    if (current.isEmpty()) {
        return "NULL";
    }
    StringBuilder listOfId = new StringBuilder();
    Iterator it = current.iterator();
    while (it.hasNext()) {
        listOfId.append(it.next());
        if (it.hasNext()) {
            listOfId.append(',');
        }
    }
    return listOfId.toString();
}

From source file:com.net2plan.utils.CollectionUtils.java

/**
 * Checks whether all elements of a collection are present in another one.
 *
 * @param <A> Key type/*from  w w w  . j a  v a  2  s  . c o m*/
 * @param container Container collection
 * @param collection Collection with elements to be checked
 * @return {@code true} if all elements in {@code collection} are present in {@code container}, and {@code false} otherwise. If {@code container} is empty, it will return {@code false}
 */
public static <A> boolean containsAll(Collection<A> container, Collection<A> collection) {
    if (container.isEmpty())
        return false;

    Set<A> set = new LinkedHashSet<A>(container);
    set.removeAll(collection);

    return set.isEmpty();
}

From source file:com.erudika.para.core.CoreUtils.java

/**
 * Removes a tag from the set of tags./*from   w  ww.ja v  a  2s  .c  o  m*/
 * @param tag a tag, must not be null or empty
 * @param objectTags the object
 * @return a new list of tags
 */
public static List<String> removeTags(List<String> objectTags, String... tag) {
    if (objectTags != null && tag != null && tag.length > 0) {
        Set<String> tagz = new HashSet<String>(objectTags);
        tagz.removeAll(Arrays.asList(tag));
        return new ArrayList<String>(tagz);
    }
    return objectTags;
}

From source file:com.mirth.connect.util.ChannelDependencyUtil.java

/**
 * Given a set of channel IDs and a dependency graph, this method splits the IDs into a set of
 * unordered IDs (that have no dependents or dependencies), and a list of multiple sets of
 * ordered IDs. The list is ordered such that the IDs in any given set are not interdependent on
 * each other, but all the IDs in the set are individually dependent on one or more IDs in one
 * of the subsequent sets.//from w w  w  .j a va  2 s.  c om
 */
public static OrderedChannels getOrderedChannels(Set<String> channelIds, ChannelDependencyGraph graph) {
    Set<String> unorderedIds = new HashSet<String>(channelIds);
    List<Set<String>> orderedIds = new ArrayList<Set<String>>();

    for (Set<String> set : graph.getOrderedElements()) {
        // Only include IDs in the set passed in
        set.retainAll(channelIds);

        if (!set.isEmpty()) {
            orderedIds.add(set);
            unorderedIds.removeAll(set);
        }
    }

    return new OrderedChannels(unorderedIds, orderedIds);
}

From source file:Main.java

/**
 * @param elements//  www .j  a v a 2 s  .com
 * @param maxNumber
 * @return the maxNumber of elements in ids and rest are skipped
 */
public static <T> Set<T> getElementsOfMaxSize(Set<T> elements, int maxNumber) {
    // The returned set should maintain the same order as the input elements
    Set<T> maxIds = new LinkedHashSet<T>();

    if (maxNumber <= 0) {
        return maxIds;
    }

    for (T id : elements) {
        maxIds.add(id);

        maxNumber--;

        if (maxNumber <= 0) {
            break;
        }

    }

    elements.removeAll(maxIds);

    return maxIds;
}

From source file:com.gst.infrastructure.core.api.ApiParameterHelper.java

public static void excludeAssociationsForResponseIfProvided(final MultivaluedMap<String, String> queryParams,
        Set<String> fields) {
    String commaSerperatedParameters = "";
    if (queryParams.getFirst("exclude") != null) {
        commaSerperatedParameters = queryParams.getFirst("exclude");
        if (StringUtils.isNotBlank(commaSerperatedParameters)) {
            fields.removeAll(new HashSet<>(Arrays.asList(commaSerperatedParameters.split("\\s*,\\s*"))));
        }/*www . j a  v a  2  s . c o m*/
    }
}

From source file:de.citec.sc.matoll.utils.visualizeSPARQL.java

private static String findRoot(List<List<String>> relations) {
    String head = "";
    Set<String> subj_list = new HashSet<>();
    Set<String> obj_list = new HashSet<>();
    relations.stream().map((list) -> {
        subj_list.add(list.get(0));/*from  w ww. j a v  a2 s . c o  m*/
        return list;
    }).forEach((list) -> {
        obj_list.add(list.get(1));
    });
    obj_list.removeAll(subj_list);
    if (obj_list.size() == 1) {
        return obj_list.toString().replace("[", "").replace("]", "");
    } else {
        return null;
    }
}

From source file:com.github.checkstyle.NotesBuilder.java

/**
 * Forms release notes as a map.//from w w w. ja  va2s  . c  o m
 * @param remoteRepo git remote repository object.
 * @param localRepoPath path to local git repository.
 * @param startRef start reference.
 * @param endRef end reference.
 * @return a map which represents release notes.
 * @throws IOException if an I/O error occurs.
 * @throws GitAPIException if an error occurs when accessing Git API.
 */
private static Result buildResult(GHRepository remoteRepo, String localRepoPath, String startRef, String endRef)
        throws IOException, GitAPIException {

    final Result result = new Result();

    final Set<Integer> processedIssueNumbers = new HashSet<>();
    final Set<RevCommit> commitsForRelease = getCommitsBetweenReferences(localRepoPath, startRef, endRef);
    commitsForRelease.removeAll(getIgnoredCommits(commitsForRelease));

    for (RevCommit commit : commitsForRelease) {
        String commitMessage = commit.getFullMessage();
        if (isRevertCommit(commitMessage)) {
            final int firstQuoteIndex = commitMessage.indexOf('"');
            final int lastQuoteIndex = commitMessage.lastIndexOf('"');
            commitMessage = commitMessage.substring(firstQuoteIndex, lastQuoteIndex);
        }
        if (isIssueOrPull(commitMessage)) {
            final int issueNo = getIssueNumberFrom(commitMessage);
            if (processedIssueNumbers.contains(issueNo)) {
                continue;
            }
            processedIssueNumbers.add(issueNo);

            final GHIssue issue = remoteRepo.getIssue(issueNo);
            if (issue.getState() != GHIssueState.CLOSED) {
                result.addWarning(
                        String.format("[WARN] Issue #%d \"%s\" is not closed!", issueNo, issue.getTitle()));
            }

            final String issueLabel = getIssueLabelFrom(issue);
            if (issueLabel.isEmpty()) {
                final String error = String.format("[ERROR] Issue #%d does not have %s label!", issueNo,
                        Joiner.on(SEPARATOR).join(Constants.ISSUE_LABELS));
                result.addError(error);
            }
            final Set<RevCommit> issueCommits = getCommitsForIssue(commitsForRelease, issueNo);
            final String authors = getAuthorsOf(issueCommits);
            final ReleaseNotesMessage releaseNotesMessage = new ReleaseNotesMessage(issue, authors);
            result.putReleaseNotesMessage(issueLabel, releaseNotesMessage);
        } else {
            // Commits that have messages which do not contain issue or pull number
            final String commitShortMessage = commit.getShortMessage();
            final String author = commit.getAuthorIdent().getName();
            final ReleaseNotesMessage releaseNotesMessage = new ReleaseNotesMessage(commitShortMessage, author);
            result.putReleaseNotesMessage(Constants.MISCELLANEOUS_LABEL, releaseNotesMessage);
        }
    }
    return result;
}

From source file:main.java.repartition.SimpleTr.java

static double getIncidentSpan(Transaction j, MigrationPlan m) {
    // Construct A -- for target transaction i
    Set<Integer> delta_i_A = new HashSet<Integer>();
    for (Integer s : m.fromSet)
        delta_i_A.addAll(m.serverDataSet.get(s));

    // Construct b -- for incident transaction j
    Set<Integer> delta_j_A = new HashSet<Integer>();
    for (Integer s : m.fromSet)
        if (j.getTr_serverSet().containsKey(s))
            delta_j_A.addAll(j.getTr_serverSet().get(s));

    // Set difference, delta = delta_j_A \ delta_i_A
    Set<Integer> delta = new HashSet<Integer>(delta_j_A);
    delta.removeAll(delta_i_A);

    HashSet<Integer> psi_delta = new HashSet<Integer>();
    for (Entry<Integer, HashSet<Integer>> entry : j.getTr_serverSet().entrySet())
        if (!Collections.disjoint(delta, entry.getValue())) // Returns true if the two specified collections have no elements in common.
            psi_delta.add(entry.getKey());

    // Calculate net span improvement for incident transaction j
    int incident_span = m.fromSet.size() - psi_delta.size();

    if (!j.getTr_serverSet().containsKey(m.to))
        incident_span -= 1;//from w  w  w. j  a v  a  2  s  . c o m

    return (double) (incident_span) * (1 / j.getTr_period());
}