List of usage examples for com.google.common.collect Sets intersection
public static <E> SetView<E> intersection(final Set<E> set1, final Set<?> set2)
From source file:org.opendaylight.nic.compiler.Transform.java
public Collection<Policy> resolve(Policy p1, Policy p2) throws IntentCompilerException { Collection<Policy> policies = new LinkedList<>(); Sets.SetView<Endpoint> src; Sets.SetView<Endpoint> dst; // All the possible cases below src = Sets.difference(p1.src(), p2.src()); if (!src.isEmpty()) { // Case: S1 and not S2 , D1 and not D2 dst = Sets.difference(p1.dst(), p2.dst()); if (!dst.isEmpty()) { policies.add(new PolicyImpl(src, dst, p1.action())); }// w w w . j av a 2s . c o m // Case: S1 and not S2 , D1 and D2 dst = Sets.intersection(p1.dst(), p2.dst()); if (!dst.isEmpty()) { policies.add(new PolicyImpl(src, dst, p1.action())); } } src = Sets.intersection(p1.src(), p2.src()); if (!src.isEmpty()) { // Case: S1 and S2 , D1 and D2 dst = Sets.intersection(p1.dst(), p2.dst()); if (!dst.isEmpty()) { Set<Action> mergedActions = merge(p1.action(), p2.action()); if (mergedActions == null) { throw new IntentCompilerException("Unable to merge exclusive actions", Arrays.asList(p1, p2)); } policies.add(new PolicyImpl(src, dst, mergedActions)); } // Case: S1 and S2 , D1 and not D2 dst = Sets.difference(p1.dst(), p2.dst()); if (!dst.isEmpty()) { policies.add(new PolicyImpl(src, dst, p1.action())); } // Case: S1 and S2 , D2 and not D1 dst = Sets.difference(p2.dst(), p1.dst()); if (!dst.isEmpty()) { policies.add(new PolicyImpl(src, dst, p2.action())); } } src = Sets.difference(p2.src(), p1.src()); if (!src.isEmpty()) { // Case: S2 and not S1 , D1 and D2 dst = Sets.intersection(p1.dst(), p2.dst()); if (!dst.isEmpty()) { policies.add(new PolicyImpl(src, dst, p2.action())); } // Case: S2 and not S1 , D2 and not D1 dst = Sets.difference(p2.dst(), p1.dst()); if (!dst.isEmpty()) { policies.add(new PolicyImpl(src, dst, p2.action())); } } return policies; }
From source file:com.facebook.buck.apple.MultiarchFileInfos.java
/** * Inspect the given build target and return information about it if its a fat binary. * * @return non-empty when the target represents a fat binary. * @throws com.facebook.buck.util.HumanReadableException * when the target is a fat binary but has incompatible flavors. *//*from www . j a v a 2 s . c om*/ public static Optional<MultiarchFileInfo> create(final FlavorDomain<AppleCxxPlatform> appleCxxPlatforms, BuildTarget target) { ImmutableList<ImmutableSortedSet<Flavor>> thinFlavorSets = generateThinFlavors( appleCxxPlatforms.getFlavors(), target.getFlavors()); if (thinFlavorSets.size() <= 1) { // Actually a thin binary return Optional.empty(); } if (!Sets.intersection(target.getFlavors(), FORBIDDEN_BUILD_ACTIONS).isEmpty()) { throw new HumanReadableException("%s: Fat binaries is only supported when building an actual binary.", target); } AppleCxxPlatform representativePlatform = null; AppleSdk sdk = null; for (SortedSet<Flavor> flavorSet : thinFlavorSets) { AppleCxxPlatform platform = Preconditions .checkNotNull(appleCxxPlatforms.getValue(flavorSet).orElse(null)); if (sdk == null) { sdk = platform.getAppleSdk(); representativePlatform = platform; } else if (sdk != platform.getAppleSdk()) { throw new HumanReadableException( "%s: Fat binaries can only be generated from binaries compiled for the same SDK.", target); } } MultiarchFileInfo.Builder builder = MultiarchFileInfo.builder().setFatTarget(target) .setRepresentativePlatform(Preconditions.checkNotNull(representativePlatform)); BuildTarget platformFreeTarget = target.withoutFlavors(appleCxxPlatforms.getFlavors()); for (SortedSet<Flavor> flavorSet : thinFlavorSets) { builder.addThinTargets(platformFreeTarget.withFlavors(flavorSet)); } return Optional.of(builder.build()); }
From source file:com.facebook.buck.cxx.CxxBinaryFlavored.java
@Override public boolean hasFlavors(ImmutableSet<Flavor> inputFlavors) { Set<Flavor> flavors = inputFlavors; Set<Flavor> platformFlavors = Sets.intersection(flavors, Sets.union(getCxxPlatformsProvider().getUnresolvedCxxPlatforms().getFlavors(), cxxBuckConfig.getDeclaredPlatforms())); if (platformFlavors.size() > 1) { return false; }/*w w w . j a va2 s .c o m*/ flavors = Sets.difference(flavors, platformFlavors); flavors = Sets.difference(flavors, ImmutableSet.of(CxxDescriptionEnhancer.CXX_LINK_MAP_FLAVOR, CxxDescriptionEnhancer.HEADER_SYMLINK_TREE_FLAVOR, CxxCompilationDatabase.COMPILATION_DATABASE, CxxCompilationDatabase.UBER_COMPILATION_DATABASE, CxxInferEnhancer.InferFlavors.INFER.getFlavor(), CxxInferEnhancer.InferFlavors.INFER_ANALYZE.getFlavor(), CxxInferEnhancer.InferFlavors.INFER_CAPTURE_ALL.getFlavor(), StripStyle.ALL_SYMBOLS.getFlavor(), StripStyle.DEBUGGING_SYMBOLS.getFlavor(), StripStyle.NON_GLOBAL_SYMBOLS.getFlavor(), LinkerMapMode.NO_LINKER_MAP.getFlavor())); return flavors.isEmpty(); }
From source file:org.eclipse.sirius.business.internal.movida.registry.monitoring.AbstractViewpointResourceMonitor.java
/** * {@inheritDoc}/*from w ww.j ava 2 s . c om*/ */ protected synchronized void notifyResourcesEvents(Set<URI> removed, Set<URI> added, Set<URI> changed) { Preconditions.checkNotNull(removed); Preconditions.checkNotNull(added); Preconditions.checkNotNull(changed); assert Sets.intersection(removed, added).isEmpty() && Sets.intersection(added, changed).isEmpty() && Sets.intersection(changed, removed).isEmpty(); if (listener != null && !(removed.isEmpty() && added.isEmpty() && changed.isEmpty())) { listener.resourceEvent(this, removed, added, changed); } }
From source file:org.caleydo.view.domino.api.model.typed.TypedGroups.java
/** * @param a//from ww w . j a v a 2 s . com * @param b * @return */ public static TypedGroupSet intersect(ITypedGroupCollection a, ITypedGroupCollection b) { IIDTypeMapper<Integer, Integer> mapper = MappingCaches.findMapper(b.getIdType(), a.getIdType()); if (mapper == null) return TypedGroupSet.createUngrouped(TypedCollections.empty(a.getIdType())); Set<Integer> others = mapper.apply(b); List<TypedSetGroup> groups = new ArrayList<>(); for (ITypedGroup g : a.getGroups()) { Set<Integer> ids = ImmutableSet.copyOf(Sets.intersection(g.asSet(), others)); if (ids.isEmpty()) continue; groups.add(new TypedSetGroup(ids, a.getIdType(), g.getLabel(), g.getColor())); } return asSet(groups, a.getIdType()); }
From source file:com.jgaap.distances.AltIntersectionDistance.java
/** * Returns intersection distance between event sets es1 and es2. * /* w ww .jav a 2s.c om*/ * @param unknownHistogram * The first EventMap * @param knownHistogram * The second EventMap * @return the intersection distance between them */ @Override public double distance(Histogram unknownHistogram, Histogram knownHistogram) { double intersectioncount = Sets.intersection(unknownHistogram.uniqueEvents(), knownHistogram.uniqueEvents()) .size(); return 1 / (intersectioncount + 1); }
From source file:com.facebook.buck.model.FlavorDomain.java
public boolean containsAnyOf(Set<Flavor> flavors) { return !Sets.intersection(translation.keySet(), flavors).isEmpty(); }
From source file:keywhiz.generators.SecretGeneratorModule.java
public SecretGeneratorModule(Map<String, SecretGeneratorFactory<?>> secretGeneratorFactories, Map<String, SecretGenerator<?>> secretGenerators) { checkArgument(Sets.intersection(secretGeneratorFactories.keySet(), secretGenerators.keySet()).isEmpty(), "SecretGeneratorFactories and SecretGenerators cannot share names."); this.secretGeneratorFactories = secretGeneratorFactories; this.secretGenerators = secretGenerators; }
From source file:net.sourceforge.ganttproject.task.dependency.TaskDependencySliceImpl.java
@Override public TaskDependency getDependency(Task target) { TaskDependencySlice targetDepSlice = myTargetDepSliceFxn.apply(target); SetView<TaskDependency> intersection = Sets.intersection(Sets.newHashSet(toArray()), Sets.newHashSet(targetDepSlice.toArray())); assert intersection .size() <= 1 : "Intersection of dependency sets between two tasks can't contain more than 1 dependency. But we get:" + intersection;//from w ww . j av a 2s. c o m return intersection.isEmpty() ? null : intersection.iterator().next(); }
From source file:org.simmetrics.metrics.Math.java
static <T> Set<T> intersection(Set<T> a, Set<T> b) { // Smaller set first for performance improvement. // See: MathCaliper and note at Sets.intersection if (a.size() < b.size()) { return Sets.intersection(a, b); }//from ww w . j a va2s. c o m return Sets.intersection(b, a); }