Example usage for com.google.common.collect Sets symmetricDifference

List of usage examples for com.google.common.collect Sets symmetricDifference

Introduction

In this page you can find the example usage for com.google.common.collect Sets symmetricDifference.

Prototype

public static <E> SetView<E> symmetricDifference(final Set<? extends E> set1, final Set<? extends E> set2) 

Source Link

Document

Returns an unmodifiable view of the symmetric difference of two sets.

Usage

From source file:se.sics.caracaldb.View.java

/**
 * Two Views are equivalent if they have the same members. (But not
 * necessarily the same id.)//w w  w.ja  v a2 s.co  m
 *
 * @param that
 * @return true if this is equivalent to that
 */
public boolean equivalentTo(View that) {
    return Sets.symmetricDifference(this.members, that.members).isEmpty();
}

From source file:se.sics.ktoolbox.election.aggregation.LeaderHistoryPacket.java

public void append(Pair<Identifier, Set<Identifier>> newLeader) {
    if (newLeader == null && currentLeader != null) {
        pastLeaders.add(currentLeader);//w w  w .  j a  va  2s . com
    } else if (newLeader != null && currentLeader != null) {
        if (!currentLeader.getValue0().equals(newLeader.getValue0())
                || !Sets.symmetricDifference(currentLeader.getValue1(), newLeader.getValue1()).isEmpty()) {
            pastLeaders.add(currentLeader);
        }
    }
    currentLeader = newLeader;
}

From source file:tech.beshu.ror.acl.blocks.rules.impl.ZeroKnowledgeMatchFilter.java

static public Set<String> alterIndicesIfNecessary(Set<String> indices, MatcherWithWildcards matcher) {

    boolean shouldReplace = false;

    indices = Sets.newHashSet(indices);//w  ww . j av  a  2  s .  c  o m
    if (indices.contains("_all")) {
        indices.remove("_all");
        indices.add("*");
    }
    if (indices.size() == 0) {
        indices.add("*");
    }

    if (indices.contains("*")) {

        if (indices.size() == 1) {
            return matcher.getMatchers().stream().collect(Collectors.toSet());
        } else {
            shouldReplace = true;
            indices.remove("*");
            indices.addAll(matcher.getMatchers().stream().collect(Collectors.toSet()));
        }
    }

    Set<String> newIndices = Sets.newHashSet();
    for (String i : indices) {
        if (matcher.match(i)) {
            newIndices.add(i);
            continue;
        }

        MatcherWithWildcards revMatcher = new MatcherWithWildcards(Sets.newHashSet(i));
        Set<String> matched = revMatcher.filter(matcher.getMatchers());

        if (!matched.isEmpty()) {
            newIndices.addAll(matched);
            shouldReplace = true;
        }
    }
    if (shouldReplace || !Sets.symmetricDifference(newIndices, indices).isEmpty()) {
        return newIndices;
    } else {
        // This means you don't need to replace at all.
        return null;
    }
}

From source file:springfox.documentation.RequestHandlerKey.java

@Override
public boolean equals(Object o) {
    if (this == o) {
        return true;
    }//  ww w  . j av a 2s.  co  m
    if (o == null || getClass() != o.getClass()) {
        return false;
    }
    RequestHandlerKey that = (RequestHandlerKey) o;
    return Sets.symmetricDifference(pathMappings, that.pathMappings).isEmpty()
            && Sets.symmetricDifference(supportedMethods, that.supportedMethods).isEmpty()
            && Sets.symmetricDifference(supportedMediaTypes, that.supportedMediaTypes).isEmpty()
            && Sets.symmetricDifference(producibleMediaTypes, that.producibleMediaTypes).isEmpty();
}

From source file:org.onosproject.cluster.PartitionDiff.java

/**
 * Returns if there are differences between the two values.
 * @return {@code true} if yes; {@code false} otherwise
 *///from ww  w  .j  a  v  a2  s.  co  m
public boolean hasChanged() {
    return !Sets.symmetricDifference(currentMembers, newMembers).isEmpty();
}

From source file:com.streamsets.datacollector.classpath.CollisionWhitelist.java

/**
 * Compare expected versions with given versions to see if they are the same or not.
 *
 * @param expectedVersions Versions that are expected (and thus whitelisted)
 * @param versions Versions that were detected on the classpath.
 * @return True if and only if those two "sets" equals
 *///from w w w.  j  a v  a2 s  . c o  m
private static boolean versionsMatch(String expectedVersions, Set<String> versions) {
    Set<String> expectedSet = Sets.newHashSet(expectedVersions.split(","));
    return Sets.symmetricDifference(expectedSet, versions).isEmpty();
}

From source file:org.onosproject.cluster.DefaultPartition.java

@Override
public boolean equals(Object other) {
    if (!(other instanceof DefaultPartition)) {
        return false;
    }//w w w  . j  av a2s. com
    DefaultPartition that = (DefaultPartition) other;
    return this.getId().equals(that.getId())
            && Sets.symmetricDifference(Sets.newHashSet(this.members), Sets.newHashSet(that.members)).isEmpty();
}

From source file:org.onosproject.cluster.Partition.java

@Override
public boolean equals(Object other) {
    if (this == other) {
        return true;
    }/*www  . j  av  a2s  . c  o  m*/

    if (other == null || !Partition.class.isInstance(other)) {
        return false;
    }

    Partition that = (Partition) other;

    if (!this.name.equals(that.name) || (this.members == null && that.members != null)
            || (this.members != null && that.members == null) || this.members.size() != that.members.size()) {
        return false;
    }

    return Sets.symmetricDifference(this.members, that.members).isEmpty();
}

From source file:pt.ist.fenixedu.quc.domain.RegentInquiryTemplate.java

public static Collection<ExecutionCourse> getExecutionCoursesWithRegentInquiriesToAnswer(Person person) {
    final Set<ExecutionCourse> result = new HashSet<ExecutionCourse>();
    final Set<ExecutionCourse> allExecutionCourses = new HashSet<ExecutionCourse>();
    final RegentInquiryTemplate currentTemplate = getCurrentTemplate();
    if (currentTemplate != null) {
        for (final Professorship professorship : person
                .getProfessorships(currentTemplate.getExecutionPeriod())) {
            final boolean isToAnswer = hasToAnswerRegentInquiry(professorship);
            if (isToAnswer) {
                allExecutionCourses.add(professorship.getExecutionCourse());
                if (professorship.getInquiryRegentAnswer() == null
                        || professorship.getInquiryRegentAnswer().hasRequiredQuestionsToAnswer(currentTemplate)
                        || InquiryResultComment.hasMandatoryCommentsToMakeAsResponsible(professorship)) {
                    result.add(professorship.getExecutionCourse());
                }//from  ww w  .j  a  v  a 2s . c  o m
            }
        }
        final Collection<ExecutionCourse> disjunctionEC = Sets.symmetricDifference(result, allExecutionCourses);
        for (final ExecutionCourse executionCourse : disjunctionEC) {
            if (InquiryResultComment.hasMandatoryCommentsToMakeAsRegentInUC(person, executionCourse)) {
                result.add(executionCourse);
            }
        }
    }
    return result;
}

From source file:org.fenixedu.academic.domain.accessControl.PersistentAcademicOperationGroup.java

private static boolean collectionEquals(Set<?> one, Set<?> another) {
    //This could be made more efficient once issue #187 is fixed.
    if (one == null) {
        one = Collections.emptySet();
    }//w  w w  . ja va2s.c o m
    if (another == null) {
        another = Collections.emptySet();
    }
    return Sets.symmetricDifference(one, another).isEmpty();
}