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:com.opengamma.bbg.loader.hts.BloombergHistoricalTimeSeriesLoader.java
/** * Finds those time-series that are not in the master. * /*from w w w . j a va2 s . c o m*/ * @param externalIds the identifiers to lookup, not null * @param dataProvider the data provider, not null * @param dataField the data field, not null * @param result the result map of identifiers, updated if already in database, not null * @return the missing identifiers, not null */ protected Set<ExternalId> findTimeSeries(final Set<ExternalId> externalIds, final String dataProvider, final String dataField, final Map<ExternalId, UniqueId> result) { HistoricalTimeSeriesInfoSearchRequest searchRequest = new HistoricalTimeSeriesInfoSearchRequest(); searchRequest.addExternalIds(externalIds); searchRequest.setDataField(dataField); if (dataProvider == null) { searchRequest.setDataProvider(BloombergConstants.DEFAULT_DATA_PROVIDER); } else { searchRequest.setDataProvider(dataProvider); } searchRequest.setDataSource(BLOOMBERG_DATA_SOURCE_NAME); HistoricalTimeSeriesInfoSearchResult searchResult = _htsMaster.search(searchRequest); Set<ExternalId> missing = new HashSet<ExternalId>(externalIds); for (HistoricalTimeSeriesInfoDocument doc : searchResult.getDocuments()) { Set<ExternalId> intersection = Sets .intersection(doc.getInfo().getExternalIdBundle().toBundle().getExternalIds(), externalIds) .immutableCopy(); if (intersection.size() == 1) { ExternalId identifier = intersection.iterator().next(); missing.remove(identifier); result.put(identifier, doc.getUniqueId()); } else { throw new OpenGammaRuntimeException( "Unable to match single identifier: " + doc.getInfo().getExternalIdBundle()); } } return missing; }
From source file:at.sti2.spark.rete.beta.JoinNode.java
/** * Checks whether there are wme in index structure that match tests and token * @param token/*from w w w .j a v a 2 s.c om*/ * @param alphaMemory */ private void leftActivate(Token token, AlphaMemory alphaMemory) { if (tests.size() > 0) { Set<WorkingMemoryElement> resultSet = null; Set<WorkingMemoryElement> intermediateSet = null; for (JoinNodeTest test : tests) { Field arg1Field = test.getArg1Field(); Token parentToken = token.getParentTokenAtBetaMemory(test.getBetaMemory()); RDFValue testTokenValue = parentToken.getWme().getTriple().getRDFTriple() .getValueOfField(test.getArg2Field()); if (arg1Field == RDFTriple.Field.SUBJECT) { intermediateSet = alphaMemory.getIndexStructure().getElementsFromSubjectIndex(testTokenValue); } else if (arg1Field == RDFTriple.Field.PREDICATE) { intermediateSet = alphaMemory.getIndexStructure().getElementsFromPredicateIndex(testTokenValue); } else if (arg1Field == RDFTriple.Field.OBJECT) { intermediateSet = alphaMemory.getIndexStructure().getElementsFromObjectIndex(testTokenValue); } if (resultSet == null && intermediateSet != null) { resultSet = intermediateSet; } else if (intermediateSet != null) { resultSet = Sets.intersection(resultSet, intermediateSet); } } if (resultSet != null) { for (WorkingMemoryElement wme : resultSet) { // Check if the token and wme are falling into a window if (wme.getTriple().isPermanent() || performTimeWindowTest(token, wme)) { // All tests successful for (RETENode reteNode : children) reteNode.leftActivate(token, wme); } } } } else { ArrayList<WorkingMemoryElement> elementsFromTokenQueue = alphaMemory.getIndexStructure() .getElementsFromTokenQueue(); for (WorkingMemoryElement wme : elementsFromTokenQueue) { if (wme.getTriple().isPermanent() || performTimeWindowTest(token, wme)) { for (RETENode reteNode : children) { reteNode.leftActivate(token, wme); } } } } }
From source file:org.sosy_lab.cpachecker.cfa.postprocessing.function.CFunctionPointerResolver.java
public CFunctionPointerResolver(MutableCFA pCfa, List<Pair<ADeclaration, String>> pGlobalVars, Configuration config, LogManager pLogger) throws InvalidConfigurationException { cfa = pCfa;//from ww w .ja v a2 s.co m logger = pLogger; config.inject(this); matchingFunctionCall = getFunctionSetPredicate(functionSets); if (functionSets.contains(FunctionSet.USED_IN_CODE)) { CReferencedFunctionsCollector varCollector = new CReferencedFunctionsCollector(); for (CFANode node : cfa.getAllNodes()) { for (CFAEdge edge : leavingEdges(node)) { varCollector.visitEdge(edge); } } for (Pair<ADeclaration, String> decl : pGlobalVars) { if (decl.getFirst() instanceof CVariableDeclaration) { CVariableDeclaration varDecl = (CVariableDeclaration) decl.getFirst(); varCollector.visitDeclaration(varDecl); } } Set<String> addressedFunctions = varCollector.getCollectedFunctions(); candidateFunctions = from(Sets.intersection(addressedFunctions, cfa.getAllFunctionNames())) .transform(Functions.forMap(cfa.getAllFunctions())).toList(); if (logger.wouldBeLogged(Level.ALL)) { logger.log(Level.ALL, "Possible target functions of function pointers:\n", Joiner.on('\n').join(candidateFunctions)); } } else { candidateFunctions = cfa.getAllFunctionHeads(); } }
From source file:edu.mayo.qdm.executor.drools.DroolsUtil.java
public Map<SpecificOccurrenceId, Event> intersect(String preconditionId, Collection<Map<SpecificOccurrenceId, Event>> contexts) { Map<SpecificOccurrenceId, Event> returnMap = new HashMap<SpecificOccurrenceId, Event>(); Set<SpecificOccurrenceId> intersect = null; for (Map<SpecificOccurrenceId, Event> context : contexts) { if (intersect == null) { intersect = context.keySet(); } else {/* ww w.j a v a 2 s .com*/ intersect = Sets.intersection(intersect, context.keySet()); } } Map<SpecificOccurrenceId, Set<Event>> comboMap = new HashMap<SpecificOccurrenceId, Set<Event>>(); for (Map<SpecificOccurrenceId, Event> context : contexts) { for (Map.Entry<SpecificOccurrenceId, Event> entry : context.entrySet()) { if (!comboMap.containsKey(entry.getKey())) { comboMap.put(entry.getKey(), new HashSet<Event>()); } comboMap.get(entry.getKey()).add(entry.getValue()); } } for (Map.Entry<SpecificOccurrenceId, Set<Event>> entry : comboMap.entrySet()) { if (entry.getValue().size() > 1) { returnMap.put(entry.getKey(), null); } else { returnMap.put(entry.getKey(), entry.getValue().iterator().next()); } } return returnMap; }
From source file:org.openqa.selenium.remote.NewSessionPayload.java
private void validate() throws IOException { Map<String, Object> alwaysMatch = getAlwaysMatch(); if (alwaysMatch == null) { alwaysMatch = ImmutableMap.of(); }/*from ww w . j a v a 2 s .c o m*/ Map<String, Object> always = alwaysMatch; Collection<Map<String, Object>> firsts = getFirstMatches(); if (firsts == null) { firsts = ImmutableList.of(ImmutableMap.of()); } if (firsts.isEmpty()) { throw new IllegalArgumentException("First match w3c capabilities is zero length"); } firsts.stream().peek(map -> { Set<String> overlap = Sets.intersection(always.keySet(), map.keySet()); if (!overlap.isEmpty()) { throw new IllegalArgumentException( "Overlapping keys between w3c always and first match capabilities: " + overlap); } }).map(first -> { Map<String, Object> toReturn = new HashMap<>(); toReturn.putAll(always); toReturn.putAll(first); return toReturn; }).peek(map -> { ImmutableSortedSet<String> nullKeys = map.entrySet().stream().filter(entry -> entry.getValue() == null) .map(Map.Entry::getKey).collect(ImmutableSortedSet.toImmutableSortedSet(Ordering.natural())); if (!nullKeys.isEmpty()) { throw new IllegalArgumentException("Null values found in w3c capabilities. Keys are: " + nullKeys); } }).peek(map -> { ImmutableSortedSet<String> illegalKeys = map.entrySet().stream() .filter(entry -> !ACCEPTED_W3C_PATTERNS.test(entry.getKey())).map(Map.Entry::getKey) .collect(ImmutableSortedSet.toImmutableSortedSet(Ordering.natural())); if (!illegalKeys.isEmpty()) { throw new IllegalArgumentException("Illegal key values seen in w3c capabilities: " + illegalKeys); } }).forEach(map -> { }); }
From source file:com.google.gct.idea.samples.SampleImportTreeManager.java
/** * Filter through the samples based on a space separated set of keywords. * A list of Samples which have substring matches for ALL keywords in any of their * 1. title// w ww. j av a 2 s .c o m * 2. categories * 3. description * will be returned. */ @NotNull Set<Sample> filterSamples(@NotNull String query) { Set<Sample> filteredSamples = new HashSet<Sample>(mySamples.getItems()); Set<Sample> filterByWord = new HashSet<Sample>(); for (String keyword : query.split(" ")) { filterByWord.clear(); for (Sample sample : mySamples.getItems()) { if (hasKeyword(sample, keyword)) { filterByWord.add(sample); } } filteredSamples = Sets.intersection(filteredSamples, filterByWord).immutableCopy(); } return filteredSamples; }
From source file:org.apache.lens.server.query.save.SavedQueryDao.java
/** * Returns a list of saved queries/* www. j av a 2 s . co m*/ * * @param criteria a multivalued map that has the filter criteria * @param start Displacement from the start of the search result * @param count Count of number of records required * @return list of saved queries * @throws LensException */ public ListResponse getList(MultivaluedMap<String, String> criteria, long start, long count) throws LensException { final StringBuilder selectQueryBuilder = new StringBuilder("select * from " + SAVED_QUERY_TABLE_NAME); final Set<String> availableFilterKeys = FILTER_KEYS.keySet(); final Sets.SetView<String> intersection = Sets.intersection(availableFilterKeys, criteria.keySet()); if (intersection.size() > 0) { final StringBuilder whereClauseBuilder = new StringBuilder(" where "); final List<String> predicates = Lists.newArrayList(); for (String colName : intersection) { predicates .add(FILTER_KEYS.get(colName).resolveFilterExpression(colName, criteria.getFirst(colName))); } Joiner.on(" and ").skipNulls().appendTo(whereClauseBuilder, predicates); selectQueryBuilder.append(whereClauseBuilder.toString()); } final String listCountQuery = "select count(*) as " + VALUE_ALIAS + " from (" + selectQueryBuilder.toString() + ") tmp_table"; selectQueryBuilder.append(" limit ").append(start).append(", ").append(count); final String listQuery = selectQueryBuilder.toString(); try { return new ListResponse(start, runner.query(listCountQuery, new SingleValuedResultHandler()), runner.query(listQuery, new SavedQueryResultSetHandler())); } catch (SQLException e) { throw new LensException("List query failed!", e); } }
From source file:org.caleydo.view.domino.api.model.typed.TypedSet.java
private static int and(BitSetSet a, Set<Integer> b) { if (b instanceof BitSetSet) { BitSetSet s = BitSetSet.and(a, (BitSetSet) b); return s.size(); }//from w w w. ja v a 2 s . c o m return Sets.intersection(b, a).size(); // as the predicate is: in the second argument }
From source file:com.qcadoo.mes.technologies.tree.TechnologyTreeValidationServiceImpl.java
private boolean hasMoreThanOneCommonProduct(final Set<Long> parentInProdIds, final Set<Long> childInProdIds) { final Set<Long> prodIdsIntersect = Sets.intersection(parentInProdIds, childInProdIds); return prodIdsIntersect.size() > 1; }
From source file:no.ssb.vtl.script.operations.join.InnerJoinOperation.java
/** * Compute the predicate.//w ww. j a v a 2s. c o m * * @param requestedOrder the requested order. * @return order of the common identifiers only. */ private Order computePredicate(Order requestedOrder) { DataStructure structure = getDataStructure(); // We need to create a fake structure to allow the returned // Order to work with the result of the key extractors. ImmutableSet<Component> commonIdentifiers = getCommonIdentifiers(); DataStructure.Builder fakeStructure = DataStructure.builder(); for (Component component : commonIdentifiers) { fakeStructure.put(structure.getName(component), component); } Order.Builder predicateBuilder = Order.create(fakeStructure.build()); Sets.SetView<Component> filteredRequestedOrder = Sets.intersection(requestedOrder.keySet(), commonIdentifiers); for (Component component : filteredRequestedOrder) { predicateBuilder.put(component, requestedOrder.get(component)); } return predicateBuilder.build(); }