List of usage examples for com.google.common.collect Sets symmetricDifference
public static <E> SetView<E> symmetricDifference(final Set<? extends E> set1, final Set<? extends E> set2)
From source file:org.debian.dependency.builders.EmbeddedAntBuilder.java
private float jarSimilarity(final File jarFile1, final File jarFile2) throws IOException { Set<String> files1 = createFileList(jarFile1); Set<String> files2 = createFileList(jarFile2); Set<String> union = Sets.union(files1, files2); Set<String> difference = Sets.symmetricDifference(files1, files2); return (union.size() - difference.size()) / union.size(); }
From source file:org.onosproject.cluster.ClusterMetadata.java
@Override public boolean equals(Object object) { if (!ClusterMetadata.class.isInstance(object)) { return false; }//from www.ja va 2s.c o m ClusterMetadata that = (ClusterMetadata) object; if (!this.name.equals(that.name) || this.nodes.size() != that.nodes.size() || this.partitions.size() != that.partitions.size()) { return false; } return Sets.symmetricDifference(this.nodes, that.nodes).isEmpty() && Sets.symmetricDifference(this.partitions, that.partitions).isEmpty(); }
From source file:org.apache.metron.enrichment.bolt.JoinBolt.java
@SuppressWarnings("unchecked") @Override//from www. j a v a2 s . c o m public void execute(Tuple tuple) { String streamId = tuple.getSourceStreamId(); String key = (String) keyGetStrategy.get(tuple); String subgroup = (String) subgroupGetStrategy.get(tuple); streamId = Joiner.on(":").join("" + streamId, subgroup == null ? "" : subgroup); V message = (V) messageGetStrategy.get(tuple); try { Map<String, V> streamMessageMap = cache.get(key); if (streamMessageMap.containsKey(streamId)) { LOG.warn(String.format("Received key %s twice for " + "stream %s", key, streamId)); } streamMessageMap.put(streamId, message); Set<String> streamIds = getStreamIds(message); Set<String> streamMessageKeys = streamMessageMap.keySet(); if (streamMessageKeys.size() == streamIds.size() && Sets.symmetricDifference(streamMessageKeys, streamIds).isEmpty()) { collector.emit("message", tuple, new Values(key, joinMessages(streamMessageMap))); cache.invalidate(key); collector.ack(tuple); LOG.trace("Emitted message for key: {}", key); } else { cache.put(key, streamMessageMap); if (LOG.isDebugEnabled()) { LOG.debug(getClass().getSimpleName() + ": Missed joining portions for " + key + ". Expected " + Joiner.on(",").join(streamIds) + " != " + Joiner.on(",").join(streamMessageKeys)); } } } catch (Exception e) { LOG.error("[Metron] Unable to join messages: " + message, e); MetronError error = new MetronError().withErrorType(Constants.ErrorType.ENRICHMENT_ERROR) .withMessage("Joining problem: " + message).withThrowable(e).addRawMessage(message); ErrorUtils.handleError(collector, error); collector.ack(tuple); } }
From source file:com.google.errorprone.bugpatterns.RedundantOverride.java
@Override public Description matchMethod(MethodTree tree, VisitorState state) { MethodSymbol methodSymbol = getSymbol(tree); if (methodSymbol == null) { return NO_MATCH; }//from w w w . j a v a 2 s. c o m Optional<MethodSymbol> maybeSuperMethod = findSuperMethod(methodSymbol, state.getTypes()); if (!maybeSuperMethod.isPresent()) { return NO_MATCH; } MethodSymbol superMethod = maybeSuperMethod.get(); if (tree.getBody() == null || tree.getBody().getStatements().size() != 1) { return NO_MATCH; } StatementTree statement = tree.getBody().getStatements().get(0); ExpressionTree expression = getSingleInvocation(statement); if (expression == null) { return NO_MATCH; } MethodInvocationTree methodInvocationTree = (MethodInvocationTree) expression; if (!getSymbol(methodInvocationTree).equals(superMethod)) { return NO_MATCH; } ExpressionTree receiver = getReceiver(methodInvocationTree); if (!(receiver instanceof IdentifierTree)) { return NO_MATCH; } if (!((IdentifierTree) receiver).getName().contentEquals("super")) { return NO_MATCH; } // Exempt Javadocs; the override might be here to add documentation. DocCommentTree docCommentTree = JavacTrees.instance(state.context).getDocCommentTree(state.getPath()); if (docCommentTree != null) { return NO_MATCH; } // Exempt broadening of visibility. if (!methodSymbol.getModifiers().equals(superMethod.getModifiers())) { return NO_MATCH; } // Overriding a protected member in another package broadens the visibility to the new package. if (methodSymbol.getModifiers().contains(Modifier.PROTECTED) && !Objects.equals(superMethod.packge(), methodSymbol.packge())) { return NO_MATCH; } // Exempt any change in annotations (aside from @Override). ImmutableSet<Symbol> superAnnotations = getAnnotations(superMethod); ImmutableSet<Symbol> methodAnnotations = getAnnotations(methodSymbol); if (!Sets.difference(Sets.symmetricDifference(superAnnotations, methodAnnotations), ImmutableSet.of(state.getSymtab().overrideType.tsym)).isEmpty()) { return NO_MATCH; } for (int i = 0; i < tree.getParameters().size(); ++i) { if (!(methodInvocationTree.getArguments().get(i) instanceof IdentifierTree)) { return NO_MATCH; } if (!getSymbol(tree.getParameters().get(i)) .equals(getSymbol(methodInvocationTree.getArguments().get(i)))) { return NO_MATCH; } } // Exempt if there are comments within the body. (Do this last, as it's expensive.) if (ErrorProneTokens.getTokens(state.getSourceForNode(tree.getBody()), state.context).stream() .anyMatch(t -> !t.comments().isEmpty())) { return NO_MATCH; } return describeMatch(tree, SuggestedFix.delete(tree)); }
From source file:org.caleydo.view.enroute.correlation.wilcoxon.WilcoxonUtil.java
public static List<WilcoxonResult> calcAllWilcoxonCombinations(DataCellInfo sourceInfo, DataCellInfo targetInfo) {//from w w w . ja v a 2s .c om List<WilcoxonResult> results = new ArrayList<>(); Object description = sourceInfo.dataDomain.getDataClassSpecificDescription(sourceInfo.rowIDType, sourceInfo.rowID, sourceInfo.columnPerspective.getIdType(), sourceInfo.columnPerspective.getVirtualArray().get(0)); if (description == null || description instanceof NumericalProperties) { List<Double> values = getSampleValues(sourceInfo, new HashSet<Object>(sourceInfo.columnPerspective.getVirtualArray().getIDs())); Collections.sort(values); for (Double threshold : values) { NumericalDataClassifier classifier = new NumericalDataClassifier(threshold.floatValue(), WilcoxonRankSumTestWizard.CLASSIFICATION_COLORS_1.getFirst(), WilcoxonRankSumTestWizard.CLASSIFICATION_COLORS_1.getSecond(), Character.toString((char) 0x2264) + " " + threshold, "> " + threshold); WilcoxonResult result = calcWilcoxonRankSumTest(sourceInfo, classifier, targetInfo); if (result != null) { results.add(result); } } } else { CategoricalClassDescription<?> classDesc = (CategoricalClassDescription<?>) description; Set<Object> allCategories = new LinkedHashSet<>(classDesc.size()); for (CategoryProperty<?> property : classDesc.getCategoryProperties()) { allCategories.add(property.getCategory()); } Set<Set<Object>> combinations = new HashSet<>(); calcCategoryCombinations(combinations, new HashSet<>(), allCategories); Set<Set<Object>> usedClass1s = new HashSet<>(); for (Set<Object> class1 : combinations) { Set<Object> class2 = Sets.symmetricDifference(class1, allCategories); if (!class2.isEmpty() && !containsSet(usedClass1s, class2)) { usedClass1s.add(class1); CategoricalDataClassifier classifier = new CategoricalDataClassifier(class1, class2, WilcoxonRankSumTestWizard.CLASSIFICATION_COLORS_1.getFirst(), WilcoxonRankSumTestWizard.CLASSIFICATION_COLORS_1.getSecond(), getCategoryName(class1, classDesc), getCategoryName(class2, classDesc), classDesc); WilcoxonResult result = calcWilcoxonRankSumTest(sourceInfo, classifier, targetInfo); if (result != null) { results.add(result); } } } } return results; }
From source file:org.codice.ddf.catalog.ui.security.ShareableMetacardImpl.java
/** * Compute the symmetric difference between the access individuals * * @param metacard - metacard to diff against *//*from w w w .j a v a 2 s. c o m*/ public Set<String> diffSharingAccessIndividuals(Metacard metacard) { return Sets.symmetricDifference(getAccessIndividuals(), createOrThrow(metacard).getAccessIndividuals()); }
From source file:notification.Notification.java
/** * This method compares the list futureNotifications with the list provided * as parameter. It then extracts elements unique for one of those two lists. * //from ww w . ja va 2 s . c o m * @param unseenNotifications the list to be compared with futureNotifications * @return an ArrayList containing unique elements */ private ArrayList<HashMap> getUniqueNotification(ArrayList<HashMap> unseenNotifications) { Set newSet = new HashSet(unseenNotifications); Set oldSet = new HashSet(this.futureNotifications); // returns a SetView that only contains the elements that are unique for one Set. SetView setView = Sets.symmetricDifference(newSet, oldSet); ArrayList<HashMap> uniqueElements = new ArrayList(setView); return uniqueElements; }
From source file:org.codice.ddf.catalog.ui.security.ShareableMetacardImpl.java
/** * Compute the symmetric difference between the access groups * * @param metacard - metacard to diff against *///w w w . j a v a 2s .c om public Set<String> diffSharingAccessGroups(Metacard metacard) { return Sets.symmetricDifference(getAccessGroups(), createOrThrow(metacard).getAccessGroups()); }
From source file:eu.itesla_project.modules.topo.UniqueTopologyChecker.java
public void check() { int errors = 0; // create a test state String topoCheckStateId = "topocheck"; String oldState = network.getStateManager().getWorkingStateId(); network.getStateManager().cloneState(oldState, topoCheckStateId); network.getStateManager().setWorkingState(topoCheckStateId); try {/* w w w .j a va2 s .c o m*/ // try to apply all possible configurations to the unique topology and check it is equal to the corresponding // historical nodal topology for (TopologyChoice topologyChoice : topologyHistory.getTopologyChoices()) { for (PossibleTopology possibleTopology : topologyChoice.getPossibleTopologies()) { for (PossibleTopology.Substation possibleSubstation : possibleTopology.getMetaSubstation() .getSubstations()) { VoltageLevel vl = network.getVoltageLevel(possibleSubstation.getId()); if (vl == null) { continue; } for (Map.Entry<String, Boolean> entry : possibleSubstation.getSwitches().entrySet()) { String switchId = entry.getKey(); boolean open = entry.getValue(); Switch s = vl.getBusBreakerView().getSwitch(switchId); if (s == null) { throw new AssertionError(); } s.setOpen(open); } Set<Set<String>> topoSet = toTopoSet(possibleSubstation, dict); Set<Set<String>> topoSet2 = toTopoSet(vl, dict); if (!topoSet.equals(topoSet2)) { LOGGER.error("Inconsistent unique topology of substation {}", possibleSubstation.getId()); LOGGER.error(" history topo set {}: {}", possibleTopology.getTopoHash(), topoSet); LOGGER.error(" network topo set: {}", topoSet2); LOGGER.error(" topo set diff : {}", Sets.symmetricDifference(topoSet, topoSet2)); LOGGER.error(" possible topo:"); possibleSubstation.print(System.out, 0, dict); LOGGER.error(" unique topo:"); uniqueTopos.get(possibleSubstation.getId()).print(System.out, dict); vl.printTopology(System.out, dict); errors++; } } } } } finally { network.getStateManager().removeState(topoCheckStateId); network.getStateManager().setWorkingState(oldState); } if (errors > 0) { throw new RuntimeException("Check failed for " + errors + " substations"); } }
From source file:org.n52.movingcode.runtime.coderepository.PackageInventory.java
/** * Two instances of {@link PackageInventory} are identical if they * contain the same set packages.// ww w . j a v a 2 s .c om */ @Override public boolean equals(Object obj) { if (!(obj instanceof PackageInventory)) { return false; } PackageInventory ref = (PackageInventory) obj; // comparison of the PIDs is sufficient SetView<PID> symmDiff; // synchronized access to the underlying maps synchronized (packagesByIdMap) { synchronized (ref.packagesByIdMap) { symmDiff = Sets.symmetricDifference(ref.packagesByIdMap.keySet(), this.packagesByIdMap.keySet()); } } return symmDiff.isEmpty(); }