Java Code Examples for com.google.common.collect.Sets#symmetricDifference()
The following examples show how to use
com.google.common.collect.Sets#symmetricDifference() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestDownloadHeaders.java From occurrence with Apache License 2.0 | 6 votes |
@Test public void testTermsConsistency(){ Set<Term> interpretedFromTermUtils = Sets.newHashSet(TermUtils.interpretedTerms()); Set<Term> interpretedFromTerms = Sets.newHashSet(Terms.interpretedTerms()); Set<Term> diff = Sets.symmetricDifference(interpretedFromTermUtils, interpretedFromTerms); assertEquals("TermUtils.interpretedTerms() and Terms.interpretedTerms() must use the same terms. Difference(s): " + diff, 0, diff.size()); Set<Term> hdfsTerms = DownloadTerms.DOWNLOAD_INTERPRETED_TERMS_HDFS; diff = Sets.newHashSet(Sets.symmetricDifference(interpretedFromTermUtils, hdfsTerms)); diff.remove(GbifTerm.gbifID); diff.remove(GbifTerm.mediaType); diff.remove(GbifTerm.numberOfOccurrences); diff.remove(GbifTerm.verbatimScientificName); assertEquals("TermUtils.interpretedTerms() and DownloadTerms.DOWNLOAD_INTERPRETED_TERMS_HDFS must use the same terms. Difference(s): " + diff, 0, diff.size()); }
Example 2
Source File: SequencedSkyframeExecutor.java From bazel with Apache License 2.0 | 6 votes |
/** * Sets the packages that should be treated as deleted and ignored. */ @Override @VisibleForTesting // productionVisibility = Visibility.PRIVATE public void setDeletedPackages(Iterable<PackageIdentifier> pkgs) { ImmutableSet<PackageIdentifier> newDeletedPackagesSet = ImmutableSet.copyOf(pkgs); Set<PackageIdentifier> newlyDeletedOrNotDeletedPackages = Sets.symmetricDifference(deletedPackages.get(), newDeletedPackagesSet); if (!newlyDeletedOrNotDeletedPackages.isEmpty()) { // PackageLookupValue is a HERMETIC node type, so we can't invalidate it. memoizingEvaluator.delete( k -> PackageLookupValue.appliesToKey(k, newlyDeletedOrNotDeletedPackages::contains)); } deletedPackages.set(newDeletedPackagesSet); }
Example 3
Source File: ModelRefreshTests.java From google-cloud-eclipse with Apache License 2.0 | 6 votes |
/** * None of our {@link AppEngineResourceElement#reload()} currently return a different instance, so * a configuration file change should not result in a change. */ @Test public void testChildElementPreservedOnChange() throws AppEngineException { List<IFile> files = new ArrayList<>(); IProject project = projectCreator.getProject(); files.add(ConfigurationFileUtils.createEmptyCronXml(project)); files.add(ConfigurationFileUtils.createEmptyDatastoreIndexesXml(project)); files.add(ConfigurationFileUtils.createEmptyDispatchXml(project)); files.add(ConfigurationFileUtils.createEmptyDosXml(project)); files.add(ConfigurationFileUtils.createEmptyQueueXml(project)); AppEngineProjectElement projectElement = AppEngineProjectElement.create(project); files.add(projectElement.getDescriptorFile()); AppEngineResourceElement[] subElements = projectElement.getConfigurations(); for (IFile file : files) { boolean changed = projectElement.resourcesChanged(Collections.singleton(file)); assertTrue(changed); AppEngineResourceElement[] newSubElements = projectElement.getConfigurations(); Set<Object> difference = Sets.symmetricDifference(Sets.newHashSet(subElements), Sets.newHashSet(newSubElements)); assertThat("all elements should have been preserved", difference, Matchers.hasSize(0)); } }
Example 4
Source File: CollectionCompareTests.java From java_in_examples with Apache License 2.0 | 6 votes |
private static void testSymmetricDifference() { Collection<String> collection1 = Lists.newArrayList("a2", "a3"); Collection<String> collection2 = Lists.newArrayList("a8", "a3", "a5"); Set<String> set1 = Sets.newHashSet("a2", "a3"); Set<String> set2 = Sets.newHashSet("a8", "a3", "a5"); MutableSet<String> mutableSet1 = UnifiedSet.newSetWith("a2", "a3"); MutableSet<String> mutableSet2 = UnifiedSet.newSetWith("a8", "a3", "a5"); // Find symmetric difference (elements that are contained in either one collection or other but not in both Set<String> intersect = new HashSet<>(set1); // using JDK intersect.retainAll(set2); Set<String> jdk = new HashSet<>(set1); jdk.addAll(set2); jdk.removeAll(intersect); Set<String> guava = Sets.symmetricDifference(set1, set2); // using guava Collection<String> apache = CollectionUtils.disjunction(collection1, collection2); // using Apache Set<String> gs = mutableSet1.symmetricDifference(mutableSet2); // using GS System.out.println("symmetricDifference = " + jdk + ":" + guava + ":" + apache + ":" + gs); // print symmetricDifference = [a2, a5, a8]:[a2, a5, a8]:[a2, a5, a8]:[a2, a5, a8] }
Example 5
Source File: CollectionCompareTests.java From java_in_examples with Apache License 2.0 | 6 votes |
private static void testSymmetricDifference() { Collection<String> collection1 = Lists.newArrayList("a2", "a3"); Collection<String> collection2 = Lists.newArrayList("a8", "a3", "a5"); Set<String> set1 = Sets.newHashSet("a2", "a3"); Set<String> set2 = Sets.newHashSet("a8", "a3", "a5"); MutableSet<String> mutableSet1 = UnifiedSet.newSetWith("a2", "a3"); MutableSet<String> mutableSet2 = UnifiedSet.newSetWith("a8", "a3", "a5"); // Найти все различные элементы (symmetric difference) у двух коллекций Set<String> intersect = new HashSet<>(set1); // c помощью JDK intersect.retainAll(set2); Set<String> jdk = new HashSet<>(set1); jdk.addAll(set2); jdk.removeAll(intersect); Set<String> guava = Sets.symmetricDifference(set1, set2); // с помощью guava Collection<String> apache = CollectionUtils.disjunction(collection1, collection2); // c помощью Apache Set<String> gs = mutableSet1.symmetricDifference(mutableSet2); // c помощью GS System.out.println("symmetricDifference = " + jdk + ":" + guava + ":" + apache + ":" + gs); // напечатает symmetricDifference = [a2, a5, a8]:[a2, a5, a8]:[a2, a5, a8]:[a2, a5, a8] }
Example 6
Source File: DeleteOrphanedStateTransformer.java From brooklyn-server with Apache License 2.0 | 6 votes |
public static void warnOfDifferences(ReferencedState s1, ReferencedState s2) { Set<String> locDiffs = Sets.symmetricDifference(s1.locations, s2.locations); Set<String> enricherDiffs = Sets.symmetricDifference(s1.enrichers, s2.enrichers); Set<String> policyDiffs = Sets.symmetricDifference(s1.policies, s2.policies); Set<String> feedDiffs = Sets.symmetricDifference(s1.feeds, s2.feeds); if (locDiffs.size() > 0) { LOG.warn("Deletion of orphan state found unusually referenced locations (keeping): " + locDiffs); } if (enricherDiffs.size() > 0) { LOG.warn("Deletion of orphan state found unusually referenced enrichers (keeping): " + enricherDiffs); } if (policyDiffs.size() > 0) { LOG.warn("Deletion of orphan state found unusually referenced policies (keeping): " + policyDiffs); } if (feedDiffs.size() > 0) { LOG.warn("Deletion of orphan state found unusually referenced feeds (keeping): " + feedDiffs); } }
Example 7
Source File: SystemOutputStore2016.java From tac-kbp-eal with MIT License | 6 votes |
static SystemOutputStore2016 open(File dir, final AssessmentSpecFormats.Format format) throws IOException { final Symbol systemID = Symbol.from(dir.getName()); final File argumentsDir = new File(dir, "arguments"); final File linkingDir = new File(dir, "linking"); final File corpusLinkingFile = new File(new File(dir, "corpusLinking"), "corpusLinking"); corpusLinkingFile.getParentFile().mkdirs(); final ArgumentStore argStore = AssessmentSpecFormats.openSystemOutputStore(argumentsDir, format); final LinkingStore linkingStore = LinkingStoreSource.createFor2016().openLinkingStore(linkingDir); if (argStore.docIDs().equals(linkingStore.docIDs())) { return new SystemOutputStore2016(systemID, argStore, linkingStore, corpusLinkingFile); } else { throw new RuntimeException("Argument and linking store docIDs do not match, missing " + Sets .symmetricDifference(argStore.docIDs(), linkingStore.docIDs())); } }
Example 8
Source File: SystemOutputStore2016.java From tac-kbp-eal with MIT License | 6 votes |
static SystemOutputStore2016 openOrCreate(File dir, final AssessmentSpecFormats.Format format) throws IOException { final Symbol systemID = Symbol.from(dir.getName()); final File argumentsDir = new File(dir, "arguments"); final File linkingDir = new File(dir, "linking"); final File corpusLinkingFile = new File(new File(dir, "corpusLinking"), "corpusLinking"); corpusLinkingFile.getParentFile().mkdirs(); final ArgumentStore argStore = AssessmentSpecFormats.openOrCreateSystemOutputStore(argumentsDir, format); final LinkingStore linkingStore = LinkingStoreSource.createFor2016().openOrCreateLinkingStore(linkingDir); if (argStore.docIDs().equals(linkingStore.docIDs())) { return new SystemOutputStore2016(systemID, argStore, linkingStore, corpusLinkingFile); } else { throw new RuntimeException("Argument and linking store docIDs do not match, missing " + Sets .symmetricDifference(argStore.docIDs(), linkingStore.docIDs())); } }
Example 9
Source File: SystemOutputStore2017.java From tac-kbp-eal with MIT License | 6 votes |
public static SystemOutputStore2017 open(File dir) throws IOException { final Symbol systemID = Symbol.from(dir.getName()); final File argumentsDir = new File(dir, "arguments"); final File linkingDir = new File(dir, "linking"); final File corpusLinkingFile = new File(new File(dir, "corpusLinking"), "corpusLinking"); corpusLinkingFile.getParentFile().mkdirs(); final ArgumentStore argStore = AssessmentSpecFormats.openSystemOutputStore(argumentsDir, AssessmentSpecFormats.Format.KBP2017); final LinkingStore linkingStore = LinkingStoreSource.createFor2016().openLinkingStore(linkingDir); if (argStore.docIDs().equals(linkingStore.docIDs())) { return new SystemOutputStore2017(systemID, argStore, linkingStore, corpusLinkingFile); } else { throw new RuntimeException("Argument and linking store docIDs do not match, missing " + Sets .symmetricDifference(argStore.docIDs(), linkingStore.docIDs())); } }
Example 10
Source File: SystemOutputStore2017.java From tac-kbp-eal with MIT License | 6 votes |
static SystemOutputStore2017 openOrCreate(File dir, final AssessmentSpecFormats.Format format) throws IOException { final Symbol systemID = Symbol.from(dir.getName()); final File argumentsDir = new File(dir, "arguments"); final File linkingDir = new File(dir, "linking"); final File corpusLinkingFile = new File(new File(dir, "corpusLinking"), "corpusLinking"); corpusLinkingFile.getParentFile().mkdirs(); final ArgumentStore argStore = AssessmentSpecFormats.openOrCreateSystemOutputStore(argumentsDir, format); final LinkingStore linkingStore = LinkingStoreSource.createFor2016().openOrCreateLinkingStore(linkingDir); if (argStore.docIDs().equals(linkingStore.docIDs())) { return new SystemOutputStore2017(systemID, argStore, linkingStore, corpusLinkingFile); } else { throw new RuntimeException("Argument and linking store docIDs do not match, missing " + Sets .symmetricDifference(argStore.docIDs(), linkingStore.docIDs())); } }
Example 11
Source File: InputStreamTestMocks.java From BUbiNG with Apache License 2.0 | 5 votes |
public static List<Set<String>> diff(HeaderGroup expected, HeaderGroup actual) { Set<String> expecetdKeys = keys(expected); Set<String> actualKeys = keys(actual); Set<String> common = Sets.intersection(expecetdKeys, actualKeys); Set<String> symdiff = Sets.symmetricDifference(expecetdKeys, actualKeys); Set<String> diffval = new HashSet<>(); for (String s : common) if (! expected.getCondensedHeader(s).getValue().equals(actual.getCondensedHeader(s).getValue())) diffval.add(s); return Arrays.asList(diffval, symdiff); }
Example 12
Source File: SymmetricDifferenceFilter.java From jinjava with Apache License 2.0 | 5 votes |
@Override public Object filter( Object var, JinjavaInterpreter interpreter, Object[] args, Map<String, Object> kwargs ) { return new ArrayList<>( Sets.symmetricDifference( objectToSet(var), objectToSet(parseArgs(interpreter, args)) ) ); }
Example 13
Source File: YangInstanceIdentifier.java From yangtools with Eclipse Public License 1.0 | 5 votes |
@Override @SuppressWarnings("checkstyle:parameterName") public int compareTo(final PathArgument o) { if (!(o instanceof AugmentationIdentifier)) { return -1; } AugmentationIdentifier other = (AugmentationIdentifier) o; Set<QName> otherChildNames = other.getPossibleChildNames(); int thisSize = childNames.size(); int otherSize = otherChildNames.size(); if (thisSize == otherSize) { // Quick Set-based comparison if (childNames.equals(otherChildNames)) { return 0; } // We already know the sets are not equal, but have equal size, hence the sets differ in their elements, // but potentially share a common set of elements. The most consistent way of comparing them is using // total ordering defined by QName's compareTo. Hence convert both sets to lists ordered // by QName.compareTo() and decide on the first differing element. final List<QName> diff = new ArrayList<>(Sets.symmetricDifference(childNames, otherChildNames)); verify(!diff.isEmpty(), "Augmentation identifiers %s and %s report no difference", this, o); diff.sort(QName::compareTo); return childNames.contains(diff.get(0)) ? -1 : 1; } else if (thisSize < otherSize) { return 1; } else { return -1; } }
Example 14
Source File: TermsTest.java From occurrence with Apache License 2.0 | 5 votes |
private void testDifferenceAndOrder(List<Term> fromTermUtils, List<Term> fromTerms) { Set<Term> fromTermUtilsSet = Sets.newHashSet(fromTermUtils); Set<Term> fromTermsSet = Sets.newHashSet(fromTerms); Set<Term> diff = Sets.symmetricDifference(fromTermUtilsSet, fromTermsSet); assertEquals("fromTerms and fromTermUtils must use the same terms. Difference(s): " + diff, 0, diff.size()); int i = 0; for (; i < fromTermUtils.size(); i++) { assertEquals("Order is different at position "+i, fromTermUtils.get(i), fromTerms.get(i)); } }
Example 15
Source File: SymmetricDifferenceOfTwoSets.java From levelup-java-examples with Apache License 2.0 | 4 votes |
@Test public void symmetric_set_difference_guava () { Set<String> yourFriendsOrMyFriends = Sets.symmetricDifference(yourFriends, myFriends); assertEquals(12, yourFriendsOrMyFriends.size()); }
Example 16
Source File: ConfigCheckBase.java From das with Apache License 2.0 | 4 votes |
private static boolean isListEquals(List<String> alist, List<String> blist) { Set<String> differenceSet = Sets.symmetricDifference(Sets.newHashSet(alist), Sets.newHashSet(blist)); return CollectionUtils.isEmpty(differenceSet); }
Example 17
Source File: Guava.java From spotbugs with GNU Lesser General Public License v2.1 | 4 votes |
@ExpectWarning(value="GC", num=3) public static void testSets(Set<String> s1, Set<Integer> s2) { Sets.intersection(s1, s2); Sets.difference(s1, s2); Sets.symmetricDifference(s1, s2); }
Example 18
Source File: AstyanaxTableDAO.java From emodb with Apache License 2.0 | 4 votes |
@Inject public AstyanaxTableDAO(LifeCycleRegistry lifeCycle, @SystemTableNamespace String systemTableNamespace, @SystemTablePlacement String systemTablePlacement, @ShardsPerTable int defaultNumShards, @BootstrapTables Map<String, Long> bootstrapTables, PlacementFactory placementFactory, PlacementCache placementCache, @CurrentDataCenter String selfDataCenter, @Maintenance RateLimiterCache rateLimiterCache, DataCopyDAO dataCopyDAO, DataPurgeDAO dataPurgeDAO, FullConsistencyTimeProvider fullConsistencyTimeProvider, @TableChangesEnabled ValueStore<Boolean> tableChangesEnabled, @CachingTableDAORegistry CacheRegistry cacheRegistry, @PlacementsUnderMove Map<String, String> placementsUnderMove, ObjectMapper objectMapper, @Nullable Clock clock) { _systemTablePlacement = checkNotNull(systemTablePlacement, "systemTablePlacement"); _bootstrapTables = HashBiMap.create(checkNotNull(bootstrapTables, "bootstrapTables")); _reservedUuids = _bootstrapTables.inverse().keySet(); _placementFactory = checkNotNull(placementFactory); _placementCache = checkNotNull(placementCache, "placementCache"); _selfDataCenter = checkNotNull(selfDataCenter, "selfDataCenter"); _defaultShardsLog2 = RowKeyUtils.computeShardsLog2(defaultNumShards, "default"); _rateLimiterCache = checkNotNull(rateLimiterCache, "rateLimiterCache"); _dataCopyDAO = checkNotNull(dataCopyDAO, "copyDataDAO"); _dataPurgeDAO = checkNotNull(dataPurgeDAO, "purgeDataDAO"); _fullConsistencyTimeProvider = checkNotNull(fullConsistencyTimeProvider, "fullConsistencyTimeProvider"); _tableChangesEnabled = checkNotNull(tableChangesEnabled, "tableChangesEnabled"); _tableCacheHandle = cacheRegistry.lookup("tables", true); _placementsUnderMove = checkNotNull(placementsUnderMove, "placementsUnderMove"); _objectMapper = requireNonNull(objectMapper); _clock = clock != null ? clock : Clock.systemUTC(); // There are two tables used to store metadata about all the other tables. checkNotNull(systemTableNamespace, "systemTableNamespace"); _systemTable = systemTableNamespace + ":table"; _systemTableUuid = systemTableNamespace + ":table_uuid"; String systemDataCenterTable = systemTableNamespace + ":data_center"; _systemTableUnPublishedDatabusEvents = systemTableNamespace + ":table_unpublished_databus_events"; _systemTableEventRegistry = systemTableNamespace + ":table_event_registry"; // If this table DAO uses itself to store its table metadata (ie. it requires bootstrap tables) then make sure // the right bootstrap tables are specified. This happens when "_dataStore" uses "this" for table metadata. if (!_bootstrapTables.isEmpty()) { Set<String> expectedTables = ImmutableSet.of(_systemTable, _systemTableUuid, systemDataCenterTable, _systemTableUnPublishedDatabusEvents, _systemTableEventRegistry); Set<String> diff = Sets.symmetricDifference(expectedTables, bootstrapTables.keySet()); checkState(diff.isEmpty(), "Bootstrap tables map is missing tables or has extra tables: %s", diff); } lifeCycle.manage(this); }
Example 19
Source File: SetUtil.java From j360-dubbo-app-all with Apache License 2.0 | 2 votes |
/** * set1, set2的补集(在set1或set2中,但不在交集中的对象,又叫反交集)的只读view,不复制产生新的Set对象. * * 如果尝试写入该View会抛出UnsupportedOperationException */ public static <E> Set<E> disjointView(final Set<? extends E> set1, final Set<? extends E> set2) { return Sets.symmetricDifference(set1, set2); }
Example 20
Source File: SetUtil.java From vjtools with Apache License 2.0 | 2 votes |
/** * set1, set2的补集(在set1或set2中,但不在交集中的对象,又叫反交集)的只读view,不复制产生新的Set对象. * * 如果尝试写入该View会抛出UnsupportedOperationException */ public static <E> Set<E> disjointView(final Set<? extends E> set1, final Set<? extends E> set2) { return Sets.symmetricDifference(set1, set2); }