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.gradle.api.internal.artifacts.ivyservice.resolveengine.graph.conflicts.ConflictContainer.java
private Conflict registerConflict(Collection<K> targets, K replacedBy) { assert !targets.isEmpty(); //replacement candidates are the only important candidates Collection<? extends T> candidates = elements.get(replacedBy); assert candidates != null; Set<K> participants = new LinkedHashSet<K>(); participants.addAll(targets);/*from w ww . j a va 2 s .c o m*/ participants.add(replacedBy); //We need to ensure that the conflict is orderly injected to the list of conflicts //Brand new conflict goes to the end //If we find any matching conflict we have to hook up with it //Find an existing matching conflict for (Conflict c : conflicts) { if (!Sets.intersection(participants, c.participants).isEmpty()) { //there is already registered conflict with at least one matching participant, hook up to this conflict c.candidates = candidates; c.participants.addAll(participants); return c; } } //No conflict with matching participants found, create new Conflict c = new Conflict(participants, candidates); conflicts.add(c); return c; }
From source file:org.caleydo.view.enroute.correlation.CellSelectionValidators.java
/** * Creates a validator that only permits cells that have an overlap in samples with the specified * {@link DataCellInfo}.// w w w. java 2 s . co m * * @param sourceInfo * @return */ public static Predicate<DataCellInfo> overlappingSamplesValidator(final DataCellInfo sourceInfo) { return new Predicate<DataCellInfo>() { @Override public boolean apply(DataCellInfo info) { sourceInfo.columnPerspective.getVirtualArray(); IDMappingManager mappingManager = IDMappingManagerRegistry.get() .getIDMappingManager(sourceInfo.columnPerspective.getIdType()); IIDTypeMapper<Object, Object> mapper = mappingManager.getIDTypeMapper( sourceInfo.columnPerspective.getIdType(), info.columnPerspective.getIdType()); Set<Object> mappedIDs = mapper .apply(new HashSet<Object>(sourceInfo.columnPerspective.getVirtualArray().getIDs())); if (mappedIDs == null) return false; Set<Object> intersection = Sets.intersection(mappedIDs, new HashSet<Object>(info.columnPerspective.getVirtualArray().getIDs())); return !intersection.isEmpty(); } }; }
From source file:ivorius.ivtoolkit.maze.components.MazeComponents.java
public static boolean overlap(MazeComponent<?> left, MazeComponent<?> right) { return Sets.intersection(left.rooms(), right.rooms()).size() > 0; }
From source file:com.foundationdb.server.types.service.TCastResolver.java
/** * Returns the common of the two types. For either argument, a <tt>null</tt> value is interpreted as any type. At * least one of the input TClasses must be non-<tt>null</tt>. If one of the inputs is null, the result is always * the other input./* w ww. j a v a 2s . com*/ * @param tClass1 the first type class * @param tClass2 the other type class * @return the common class, or <tt>null</tt> if none were found * @throws IllegalArgumentException if both inputs are <tt>null</tt> */ public TClass commonTClass(TClass tClass1, TClass tClass2) { // NOTE: // This method shares some concepts with #reduceToMinimalCastGroups, but the two methods seem different enough // that they're best implemented without much common code. But this could be an opportunity for refactoring. // handle easy cases where one or the other is null if (tClass1 == null) { if (tClass2 == null) throw new IllegalArgumentException("both inputs can't be null"); return tClass2.widestComparable(); } if (tClass2 == null) return tClass1.widestComparable(); // If they're the same class, this is a really easy question to answer. if (tClass1.equals(tClass2)) return tClass1; // Alright, neither is null and they're both different. Try the hard way. Set<? extends TClass> t1Targets = stronglyCastableFrom(tClass1); Set<? extends TClass> t2Targets = stronglyCastableFrom(tClass2); // TODO: The following is not very efficient -- opportunity for optimization? // Sets.intersection works best when the first arg is smaller, so do that. Set<? extends TClass> set1, set2; if (t1Targets.size() < t2Targets.size()) { set1 = t1Targets; set2 = t2Targets; } else { set1 = t2Targets; set2 = t1Targets; } Set<? extends TClass> castGroup = Sets.intersection(set1, set2); // N^2 operation number 1 // The cast group is the set of type classes such that for each element C of castGroup, both tClass1 and tClass2 // can be strongly cast to C. castGroup is thus the set of common types for { tClass1, tClass2 }. We now need // to find the MOST SPECIFIC cast M such that any element of castGroup which is not M can be strongly castable // from M. if (castGroup.isEmpty()) throw new NoSuchCastException(tClass1, tClass2); // N^2 operation number 2... TClass mostSpecific = null; for (TClass candidate : castGroup) { if (isMostSpecific(candidate, castGroup)) { if (mostSpecific == null) mostSpecific = candidate; else return null; } } return mostSpecific; }
From source file:com.cognifide.aet.job.common.comparators.cookie.CookieComparator.java
@SuppressWarnings("unchecked") private ComparatorStepResult compareCookies(Set<Cookie> cookies) throws IOException { final Set<Cookie> cookiesPattern = artifactsDAO.getJsonFormatArtifact(properties, properties.getPatternId(), COOKIES_SET_TYPE);/*from w w w .j av a2s . c om*/ final Set<String> collectedCookiesNames = FluentIterable.from(cookies).transform(COOKIE_STRING_FUNCTION) .toSet(); final Set<String> patternCookiesNames = FluentIterable.from(cookiesPattern) .transform(COOKIE_STRING_FUNCTION).toSet(); Set<String> additionalCookies = Sets.difference(collectedCookiesNames, patternCookiesNames); Set<String> notFoundCookies = Sets.difference(patternCookiesNames, collectedCookiesNames); Set<String> foundCookies = Collections.emptySet(); if (showMatched) { foundCookies = Sets.intersection(patternCookiesNames, collectedCookiesNames); } boolean compareResult = additionalCookies.isEmpty() && notFoundCookies.isEmpty(); CookieCompareComparatorResult result = new CookieCompareComparatorResult(compareAction, cookies, notFoundCookies, additionalCookies, foundCookies); final String artifactId = artifactsDAO.saveArtifactInJsonFormat(properties, result); return new ComparatorStepResult(artifactId, compareResult ? ComparatorStepResult.Status.PASSED : ComparatorStepResult.Status.FAILED, !compareResult); }
From source file:org.sonatype.nexus.repository.storage.DefaultContentValidator.java
@Nonnull @Override//from ww w .j a v a 2 s . c o m public String determineContentType(boolean strictContentTypeValidation, Supplier<InputStream> contentSupplier, @Nullable MimeRulesSource mimeRulesSource, @Nullable String contentName, @Nullable String declaredContentType) throws IOException { checkNotNull(contentSupplier); final String declaredBaseContentType = mediaTypeWithoutParameters(declaredContentType); final LinkedHashSet<String> contentDetectedMimeTypes = new LinkedHashSet<>(); try (InputStream is = contentSupplier.get()) { contentDetectedMimeTypes.addAll(mimeSupport.detectMimeTypes(is, contentName)); } adjustIfHtml(contentDetectedMimeTypes); log.debug("Mime support detects {} as {}", contentName, contentDetectedMimeTypes); if (strictContentTypeValidation && isUnknown(contentDetectedMimeTypes)) { throw new InvalidContentException("Content type could not be determined: " + contentName); } final LinkedHashSet<String> nameAssumedMimeTypes = new LinkedHashSet<>(); if (contentName != null) { nameAssumedMimeTypes.addAll(mimeSupport.guessMimeTypesListFromPath(contentName, mimeRulesSource != null ? mimeRulesSource : MimeRulesSource.NOOP)); adjustIfHtml(nameAssumedMimeTypes); log.debug("Mime support assumes {} as {}", contentName, nameAssumedMimeTypes); if (!isUnknown(nameAssumedMimeTypes)) { Set<String> intersection = Sets.intersection(contentDetectedMimeTypes, nameAssumedMimeTypes); log.debug("content/name types intersection {}", intersection); if (strictContentTypeValidation && intersection.isEmpty()) { throw new InvalidContentException(String.format("Detected content type %s, but expected %s: %s", contentDetectedMimeTypes, nameAssumedMimeTypes, contentName)); } } } String finalContentType; if (!isUnknown(nameAssumedMimeTypes)) { // format implied type or known extension finalContentType = nameAssumedMimeTypes.iterator().next(); } else if (!isUnknown(contentDetectedMimeTypes)) { // use the content based one finalContentType = contentDetectedMimeTypes.iterator().next(); } else if (!Strings.isNullOrEmpty(declaredBaseContentType)) { // use the declared if declared at all finalContentType = declaredBaseContentType; } else { // give up finalContentType = ContentTypes.APPLICATION_OCTET_STREAM; } log.debug("Content {} declared as {}, determined as {}", contentName, declaredContentType, finalContentType); return finalContentType; }
From source file:org.eclipse.sirius.common.ui.tools.internal.interpreter.FeatureProposalProvider.java
@Override public List<ContentProposal> getProposals(IInterpreter interpreter, ContentContext context) { final List<ContentProposal> proposals; if (context == null || !(interpreter instanceof FeatureInterpreter)) { proposals = Collections.emptyList(); } else if (context.getContents() == null || context.getContents().length() == 0) { proposals = Collections.singletonList(getNewEmtpyExpression()); } else {/*from www . j a v a 2 s.c om*/ Set<ContentProposal> intersectingProposals = null; IInterpreterContext interpreterContext = context.getInterpreterContext(); for (TypeName type : interpreterContext.getTargetType().getPossibleTypes()) { for (EClass possibleEClass : Iterables .filter(type.search(interpreterContext.getAvailableEPackages()), EClass.class)) { Set<ContentProposal> proposalsForThisType = Sets.newLinkedHashSet( getProposals(context.getContents(), context.getPosition(), possibleEClass)); if (intersectingProposals == null) { intersectingProposals = proposalsForThisType; } else { intersectingProposals = Sets.intersection(intersectingProposals, proposalsForThisType); } } } if (intersectingProposals != null) { proposals = Lists.newArrayList(intersectingProposals); } else { proposals = Collections.<ContentProposal>emptyList(); } } return proposals; }
From source file:org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy.java
private List<SSTableReader> getNextBackgroundSSTables(final int gcBefore) { // make local copies so they can't be changed out from under us mid-method int minThreshold = cfs.getMinimumCompactionThreshold(); int maxThreshold = cfs.getMaximumCompactionThreshold(); Iterable<SSTableReader> candidates = filterSuspectSSTables( Sets.intersection(cfs.getUncompactingSSTables(), sstables)); List<List<SSTableReader>> buckets = getBuckets(createSSTableAndLengthPairs(candidates), sizeTieredOptions.bucketHigh, sizeTieredOptions.bucketLow, sizeTieredOptions.minSSTableSize); logger.trace("Compaction buckets are {}", buckets); updateEstimatedCompactionsByTasks(buckets); List<SSTableReader> mostInteresting = mostInterestingBucket(buckets, minThreshold, maxThreshold); if (!mostInteresting.isEmpty()) return mostInteresting; // if there is no sstable to compact in standard way, try compacting single sstable whose droppable tombstone // ratio is greater than threshold. List<SSTableReader> sstablesWithTombstones = new ArrayList<>(); for (SSTableReader sstable : candidates) { if (worthDroppingTombstones(sstable, gcBefore)) sstablesWithTombstones.add(sstable); }/* ww w . j a v a2 s . c om*/ if (sstablesWithTombstones.isEmpty()) return Collections.emptyList(); Collections.sort(sstablesWithTombstones, new SSTableReader.SizeComparator()); return Collections.singletonList(sstablesWithTombstones.get(0)); }
From source file:com.zimbra.cs.session.WaitSetSession.java
@Override public void notifyPendingChanges(PendingModifications pns, int changeId, Session source) { boolean trace = ZimbraLog.session.isTraceEnabled(); if (trace)//w ww .jav a2s . co m ZimbraLog.session.trace("Notifying WaitSetSession: change id=" + changeId + ", highest change id=" + mHighestChangeId + ", sync token=" + mSyncToken); if (changeId > mHighestChangeId) { mHighestChangeId = changeId; } if (mSyncToken != null && mSyncToken.after(mHighestChangeId)) { if (trace) ZimbraLog.session.trace("Not signaling waitset; sync token is later than highest change id"); return; // don't signal, sync token stopped us } if (!Sets.intersection(interest, pns.changedTypes).isEmpty()) { if (trace) ZimbraLog.session.trace("Signaling waitset"); mWs.signalDataReady(this); } else { if (trace) ZimbraLog.session.trace("Not signaling waitset; waitset is not interested in change type"); } if (trace) ZimbraLog.session.trace("WaitSetSession.notifyPendingChanges done"); }
From source file:org.fenixedu.bennu.core.groups.UserGroup.java
@Override public Group and(Group group) { if (group instanceof UserGroup) { return UserGroup.of(Sets.intersection(members(), ((UserGroup) group).members())); }// w w w . j a va 2s.c om return super.and(group); }