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.caleydo.view.relationshipexplorer.ui.collection.AEntityCollection.java
@Override public Set<Object> getBroadcastingIDsFromElementIDs(Set<Object> elementIDs) { Set<Object> myElementIDs = new HashSet<>(Sets.intersection(elementIDs, allElementIDs)); Set<Object> broadcastIDs = new HashSet<>(); for (Object elementID : myElementIDs) { broadcastIDs.addAll(getBroadcastingIDsFromElementID(elementID)); }//from w ww . ja v a2s. co m return broadcastIDs; }
From source file:com.facebook.buck.model.BuildTargets.java
public static Predicate<BuildTarget> containsFlavors(final FlavorDomain<?> domain) { return input -> { ImmutableSet<Flavor> flavorSet = Sets.intersection(domain.getFlavors(), input.getFlavors()) .immutableCopy();/* www . j a va 2 s . co m*/ return !flavorSet.isEmpty(); }; }
From source file:org.eclipse.sw360.portal.tags.CompareAttachments.java
private void renderAttachments(JspWriter jspWriter, Set<Attachment> currentAttachments, Set<Attachment> addedAttachments, Set<Attachment> deletedAttachments, String contextType, String contextId) throws JspException, IOException { Map<String, Attachment> currentAttachmentsById = getAttachmentsById(currentAttachments); Map<String, Attachment> addedAttachmentsById = getAttachmentsById(addedAttachments); Map<String, Attachment> deletedAttachmentsById = getAttachmentsById(deletedAttachments); Set<String> currentAttachmentIds = currentAttachmentsById.keySet(); Set<String> addedAttachmentIds = addedAttachmentsById.keySet(); Set<String> deletedAttachmentIds = deletedAttachmentsById.keySet(); Set<String> commonAttachmentIds = Sets.intersection(deletedAttachmentIds, addedAttachmentIds); addedAttachmentIds = Sets.difference(addedAttachmentIds, commonAttachmentIds); deletedAttachmentIds = Sets.difference(deletedAttachmentIds, commonAttachmentIds); deletedAttachmentIds = Sets.intersection(deletedAttachmentIds, currentAttachmentIds);//remove what was deleted already in the database renderAttachmentList(jspWriter, currentAttachmentsById, deletedAttachmentIds, "Deleted", contextType, contextId);/*from w w w. j a v a 2s . c om*/ renderAttachmentList(jspWriter, addedAttachmentsById, addedAttachmentIds, "Added", contextType, contextId); renderAttachmentComparison(jspWriter, currentAttachmentsById, deletedAttachmentsById, addedAttachmentsById, commonAttachmentIds); }
From source file:fr.inria.maestro.lga.clustering.analysis.impl.PrecisionQuantity.java
public Pair<Double, Double> getPrecisionRecall(final ClusteringPreprocessor analysisClustering) { final Set<String> expertClusterNames = Sets.newHashSet(); final Set<String> expertClusterEntries = Sets.newHashSet(); for (final ICluster cluster : expertFormingClustering.getClustering().getClusters()) { expertClusterNames.add(cluster.getName()); expertClusterEntries.addAll(cluster.getEntriesNames()); final ICluster judgementCluster = analysisClustering.getClusterByName(cluster.getName()); if (judgementCluster == null) { throw new IllegalArgumentException("can't find analog for cluster: " + cluster.getName()); }/* w w w. j a v a 2 s .c o m*/ } int tp = 0; int fp = 0; int fn = 0; for (final ICluster cluster : expertFormingClustering.getClustering().getClusters()) { final Set<String> expertDocuments = cluster.getEntriesNames(); final ICluster analysisCluster = analysisClustering.getClusterByName(cluster.getName()); if (analysisCluster == null) { throw new IllegalArgumentException("can't find analog for cluster: " + cluster.getName()); } final Set<String> analysisDocuments = Sets.intersection(analysisCluster.getEntriesNames(), expertClusterEntries); tp += Sets.intersection(analysisDocuments, expertDocuments).size(); fp += Sets.difference(analysisDocuments, expertDocuments).size(); fn += Sets.difference(expertDocuments, analysisDocuments).size(); } return Pair.create(tp / (1. * (tp + fp)), tp / (1. * (tp + fn))); }
From source file:com.opengamma.engine.view.calc.CompositeMarketDataSnapshot.java
/** * Initializes the underlying snapshots. * @param requirements the values required in the snapshot, not null * @param timeout the maximum time to wait for the required values * @param unit the timeout unit, not null *//* w w w .j a va 2 s.co m*/ @Override public void init(Set<ValueRequirement> requirements, long timeout, TimeUnit unit) { ArgumentChecker.notNull(requirements, "requirements"); ArgumentChecker.notNull(unit, "unit"); List<Set<ValueRequirement>> subscriptions = _subscriptionSupplier.get(); for (int i = 0; i < _snapshots.size(); i++) { MarketDataSnapshot snapshot = _snapshots.get(i); Set<ValueRequirement> snapshotSubscriptions = subscriptions.get(i); // TODO whole timeout? or divide timeout between all delegate snapshots and keep track of how much is left? // the combined snapshot does this but that seems broken to me Set<ValueRequirement> snapshotRequirements = Sets.intersection(snapshotSubscriptions, requirements); if (snapshotRequirements.isEmpty()) { snapshot.init(); } else { snapshot.init(snapshotSubscriptions, timeout, unit); } } }
From source file:org.projectbuendia.client.diagnostics.BuendiaApiHealthCheck.java
protected int getCheckPeriodMillis() { return Sets.intersection(FAST_CHECK_ISSUES, mActiveIssues).isEmpty() ? CHECK_PERIOD_MS : FAST_CHECK_PERIOD_MS; }
From source file:org.tensorics.core.tensor.Shapes.java
/** * Extracts those dimensions, which are contained in both shapes. * /* ww w . j a va 2 s . c o m*/ * @param left the first shape for which to look at the dimensions * @param right the second shape where to look at the dimensions. * @return all the dimensions which are present in both shapes */ public static Set<Class<?>> dimensionalIntersection(Shape left, Shape right) { checkLeftRightNotNull(left, right); return Sets.intersection(left.dimensionSet(), right.dimensionSet()); }
From source file:com.abiquo.model.enumerator.HypervisorType.java
/** * Performs the intersection between the hypervisor's {@link #compatibleFormats} and the set of * {@link DiskFormatType} passed. Returns true if the intersection is not empty, then some of * the passed {@link DiskFormatType} are compatible with the hypervisor. * /*from ww w .j a v a2s .c o m*/ * @param types The set of {@link DiskFormatType} to consider. * @return True if some of the passed {@link DiskFormatType} are compatible with the hypervisor. */ public boolean isCompatible(final Set<DiskFormatType> types) { return !Sets.intersection(compatibleFormats, types).isEmpty(); }
From source file:edu.cmu.lti.oaqa.baseqa.answer.collective_score.scorers.TypeCoercionCollectiveAnswerScorer.java
@Override public void prepare(JCas jcas) { answers = TypeUtil.getRankedAnswers(jcas); // create offset to concept types index SetMultimap<String, String> offset2ctypes = HashMultimap.create(); for (Concept concept : TypeUtil.getConcepts(jcas)) { for (ConceptMention cmention : TypeUtil.getConceptMentions(concept)) { Set<String> ctypes = TypeUtil.getConceptTypes(cmention.getConcept()).stream() .map(ConceptType::getAbbreviation).collect(toSet()); offset2ctypes.putAll(TypeUtil.annotationOffset(cmention), ctypes); }/*from w w w .j a va 2s.c o m*/ } // create answer to concepty types index SetMultimap<Answer, String> answer2ctypes = HashMultimap.create(); for (Answer answer : answers) { for (CandidateAnswerVariant cav : TypeUtil.getCandidateAnswerVariants(answer)) { for (CandidateAnswerOccurrence cao : TypeUtil.getCandidateAnswerOccurrences(cav)) { Set<String> ctypes = offset2ctypes.get(TypeUtil.annotationOffset(cao)); answer2ctypes.putAll(answer, ctypes); } } } // build pariwise similarity matrices typecors = HashBasedTable.create(); ntypecors = HashBasedTable.create(); types = HashBasedTable.create(); ImmutableSet<Answer> answerSet = ImmutableSet.copyOf(answers); for (List<Answer> pair : Sets.cartesianProduct(answerSet, answerSet)) { Answer a1 = pair.get(0); Answer a2 = pair.get(1); if (a1.equals(a2)) continue; Set<String> overlapTypes = Sets.intersection(answer2ctypes.get(a1), answer2ctypes.get(a2)); if (overlapTypes.size() > 0) { typecors.put(a1, a2, (double) overlapTypes.size()); ntypecors.put(a1, a2, (double) overlapTypes.size() / answer2ctypes.get(a1).size()); types.put(a1, a2, overlapTypes); } } }
From source file:com.cognifide.aet.job.common.datafilters.removelines.RemoveLinesDataModifier.java
private String modify(String data, Set<Integer> indexesToRemove) { List<String> lines = Arrays.asList(StringUtils.split(data, NEWLINE)); Set<Integer> dataIndexes = ContiguousSet.create(Range.closed(1, lines.size()), DiscreteDomain.integers()); if (!dataIndexes.containsAll(indexesToRemove)) { LOGGER.warn("Some of defined ranges exceed source lenght. Source length is: " + lines.size()); }//from w w w . j a v a 2 s.c o m Set<Integer> filtereedIndexesToRemove = Sets.intersection(dataIndexes, indexesToRemove); List<String> modifiedLines = new ArrayList<String>(lines.size() - filtereedIndexesToRemove.size()); for (int i = 0; i < lines.size(); i++) { if (!filtereedIndexesToRemove.contains(i + 1)) { modifiedLines.add(lines.get(i)); } } return StringUtils.join(modifiedLines, NEWLINE); }