List of usage examples for java.util Set containsAll
boolean containsAll(Collection<?> c);
From source file:edu.uci.ics.hyracks.algebricks.rewriter.rules.PushSubplanIntoGroupByRule.java
@Override public boolean rewritePre(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException { ILogicalOperator parentOperator = opRef.getValue(); if (context.checkIfInDontApplySet(this, parentOperator)) { return false; }//from w w w . ja v a 2 s .c om context.addToDontApplySet(this, parentOperator); VariableUtilities.getUsedVariables(parentOperator, usedVarsSoFar); if (parentOperator.getInputs().size() <= 0) { return false; } boolean changed = false; GroupByOperator gby = null; for (Mutable<ILogicalOperator> ref : parentOperator.getInputs()) { AbstractLogicalOperator op = (AbstractLogicalOperator) ref.getValue(); /** Only processes subplan operator. */ List<SubplanOperator> subplans = new ArrayList<SubplanOperator>(); if (op.getOperatorTag() == LogicalOperatorTag.SUBPLAN) { while (op.getOperatorTag() == LogicalOperatorTag.SUBPLAN) { SubplanOperator currentSubplan = (SubplanOperator) op; subplans.add(currentSubplan); op = (AbstractLogicalOperator) op.getInputs().get(0).getValue(); } /** Only processes the case a group-by operator is the input of the subplan operators. */ if (op.getOperatorTag() == LogicalOperatorTag.GROUP) { gby = (GroupByOperator) op; List<ILogicalPlan> newGbyNestedPlans = new ArrayList<ILogicalPlan>(); for (SubplanOperator subplan : subplans) { List<ILogicalPlan> subplanNestedPlans = subplan.getNestedPlans(); List<ILogicalPlan> gbyNestedPlans = gby.getNestedPlans(); List<ILogicalPlan> subplanNestedPlansToRemove = new ArrayList<ILogicalPlan>(); for (ILogicalPlan subplanNestedPlan : subplanNestedPlans) { List<Mutable<ILogicalOperator>> rootOpRefs = subplanNestedPlan.getRoots(); List<Mutable<ILogicalOperator>> rootOpRefsToRemove = new ArrayList<Mutable<ILogicalOperator>>(); for (Mutable<ILogicalOperator> rootOpRef : rootOpRefs) { /** Gets free variables in the root operator of a nested plan and its descent. */ Set<LogicalVariable> freeVars = new ListSet<LogicalVariable>(); VariableUtilities.getUsedVariablesInDescendantsAndSelf(rootOpRef.getValue(), freeVars); Set<LogicalVariable> producedVars = new ListSet<LogicalVariable>(); VariableUtilities.getProducedVariablesInDescendantsAndSelf(rootOpRef.getValue(), producedVars); freeVars.removeAll(producedVars); /** * Checks whether the above freeVars are all contained in live variables * of one nested plan inside the group-by operator. * If yes, then the subplan can be pushed into the nested plan of the group-by. */ for (ILogicalPlan gbyNestedPlanOriginal : gbyNestedPlans) { // add a subplan in the original gby if (!newGbyNestedPlans.contains(gbyNestedPlanOriginal)) { newGbyNestedPlans.add(gbyNestedPlanOriginal); } // add a pushed subplan ILogicalPlan gbyNestedPlan = OperatorManipulationUtil .deepCopy(gbyNestedPlanOriginal, context); List<Mutable<ILogicalOperator>> gbyRootOpRefs = gbyNestedPlan.getRoots(); for (int rootIndex = 0; rootIndex < gbyRootOpRefs.size(); rootIndex++) { //set the nts for a original subplan Mutable<ILogicalOperator> originalGbyRootOpRef = gbyNestedPlanOriginal .getRoots().get(rootIndex); Mutable<ILogicalOperator> originalGbyNtsRef = downToNts( originalGbyRootOpRef); NestedTupleSourceOperator originalNts = (NestedTupleSourceOperator) originalGbyNtsRef .getValue(); originalNts .setDataSourceReference(new MutableObject<ILogicalOperator>(gby)); //push a new subplan if possible Mutable<ILogicalOperator> gbyRootOpRef = gbyRootOpRefs.get(rootIndex); Set<LogicalVariable> liveVars = new ListSet<LogicalVariable>(); VariableUtilities.getLiveVariables(gbyRootOpRef.getValue(), liveVars); if (liveVars.containsAll(freeVars)) { /** Does the actual push. */ Mutable<ILogicalOperator> ntsRef = downToNts(rootOpRef); ntsRef.setValue(gbyRootOpRef.getValue()); // Removes unused vars. AggregateOperator aggOp = (AggregateOperator) gbyRootOpRef.getValue(); for (int varIndex = aggOp.getVariables().size() - 1; varIndex >= 0; varIndex--) { if (!freeVars.contains(aggOp.getVariables().get(varIndex))) { aggOp.getVariables().remove(varIndex); aggOp.getExpressions().remove(varIndex); } } gbyRootOpRef.setValue(rootOpRef.getValue()); rootOpRefsToRemove.add(rootOpRef); // Sets the nts for a new pushed plan. Mutable<ILogicalOperator> oldGbyNtsRef = downToNts(gbyRootOpRef); NestedTupleSourceOperator nts = (NestedTupleSourceOperator) oldGbyNtsRef .getValue(); nts.setDataSourceReference(new MutableObject<ILogicalOperator>(gby)); newGbyNestedPlans.add(gbyNestedPlan); changed = true; continue; } } } } rootOpRefs.removeAll(rootOpRefsToRemove); if (rootOpRefs.size() == 0) { subplanNestedPlansToRemove.add(subplanNestedPlan); } } subplanNestedPlans.removeAll(subplanNestedPlansToRemove); } if (changed) { ref.setValue(gby); gby.getNestedPlans().clear(); gby.getNestedPlans().addAll(newGbyNestedPlans); } } } } if (changed) { cleanup(gby); } return changed; }
From source file:org.matonto.platform.config.impl.state.SimpleStateManager.java
@Override public Map<Resource, Model> getStates(String username, String applicationId, Set<Resource> subjects) throws MatOntoException { User user = engineManager.retrieveUser(RdfEngine.COMPONENT_NAME, username) .orElseThrow(() -> new MatOntoException("User not found")); Optional<Application> app = applicationManager.getApplication(applicationId); Map<Resource, Model> states = new HashMap<>(); try (RepositoryConnection conn = repository.getConnection()) { TupleQuery statesQuery = app.isPresent() ? conn.prepareTupleQuery(GET_APPLICATION_STATES_QUERY) : conn.prepareTupleQuery(GET_STATES_QUERY); app.ifPresent(application -> statesQuery.setBinding(APPLICATION_BINDING, application.getResource())); statesQuery.setBinding(USER_BINDING, user.getResource()); TupleQueryResult results = statesQuery.evaluate(); BindingSet bindings;// w w w . ja v a2 s.co m while (results.hasNext() && (bindings = results.next()).getBindingNames().contains(STATE_ID_BINDING)) { Resource stateId = Bindings.requiredResource(bindings, STATE_ID_BINDING); bindings.getBinding(RESOURCES_BINDING).ifPresent(binding -> { Set<Resource> resources = Arrays .stream(StringUtils.split(binding.getValue().stringValue(), ",")) .map(factory::createIRI).collect(Collectors.toSet()); if (subjects.isEmpty() || resources.containsAll(subjects)) { Model stateModel = modelFactory.createModel(); resources.forEach( resource -> conn.getStatements(resource, null, null).forEach(stateModel::add)); states.put(stateId, stateModel); } }); } } return states; }
From source file:com.thoughtworks.go.plugin.access.secrets.SecretsExtension.java
public List<Secret> lookupSecrets(String pluginId, SecretConfig secretConfig, Set<String> keys) { final List<Secret> secrets = getVersionedSecretsExtension(pluginId).lookupSecrets(pluginId, secretConfig, keys);//www . j av a 2 s . com final Set<String> resolvedSecrets = secrets.stream().map(Secret::getKey).collect(Collectors.toSet()); final Set<String> additionalSecretsInResponse = SetUtils.difference(resolvedSecrets, keys).toSet(); if (!additionalSecretsInResponse.isEmpty()) { throw SecretResolutionFailureException.withUnwantedSecretParams(secretConfig.getId(), keys, additionalSecretsInResponse); } if (resolvedSecrets.containsAll(keys)) { return secrets; } final Set<String> missingSecrets = SetUtils.disjunction(resolvedSecrets, keys).toSet(); throw SecretResolutionFailureException.withMissingSecretParams(secretConfig.getId(), keys, missingSecrets); }
From source file:org.deri.iris.queryrewriting.RewritingUtils.java
public static boolean covers(final ILiteral a, final ILiteral b, final Map<Pair<IPosition, IPosition>, Set<List<IRule>>> deps, final IRule q) { // Check whether is in cache. rep.incrementValue(RewMetric.COVER_CHECK_COUNT); if (CoveringCache.inCache(a, b, CacheType.NOT_COVERING)) { rep.incrementValue(RewMetric.NON_COVERING_CACHE_HITS); return false; }//from ww w. j a v a 2s . c o m if (CoveringCache.inCache(a, b, CacheType.COVERING)) { rep.incrementValue(RewMetric.COVERING_CACHE_HITS); rep.incrementValue(RewMetric.ELIM_ATOM_COUNT); return true; } final Set<ITerm> coveredTerms = new LinkedHashSet<ITerm>(); int i = 0; for (final ITerm tb : b.getAtom().getTuple()) { i++; final IPosition tbPosInB = new Position(b.getAtom().getPredicate().getPredicateSymbol(), i); final Set<IPosition> tbPossInA = getTermPositionsInLiteral(tb, a); for (final IPosition tbPosInA : tbPossInA) { final Pair<IPosition, IPosition> dep = Pair.of(tbPosInA, tbPosInB); // check that a cover dependency exists. if (deps.containsKey(dep)) { coveredTerms.add(tb); } } } if (coveredTerms.containsAll(b.getAtom().getTuple())) { // add the pair of literals to the covering cache. CoveringCache.cache(a, b, CacheType.COVERING); rep.incrementValue(RewMetric.ELIM_ATOM_COUNT); return true; } else { CoveringCache.cache(a, b, CacheType.NOT_COVERING); return false; } }
From source file:org.wso2.carbon.identity.consent.mgt.services.ConsentUtilityService.java
/** * Validate a given receipt with with respective purposes. * * @param receiptInput User given receipt. * @param purposes Configured purposes. * @throws ConsentUtilityServiceException ConsentUtilityServiceException. *//* w w w.ja v a 2 s. c o m*/ public void validateReceiptPIIs(ReceiptInput receiptInput, List<Purpose> purposes) throws ConsentUtilityServiceException { if (purposes == null || receiptInput == null) { throw new IllegalArgumentException("Receipt Input and purposes should not be null"); } if (log.isDebugEnabled()) { log.debug("Validating receipt against purposes."); } List<ReceiptServiceInput> services = receiptInput.getServices(); for (Purpose purpose : purposes) { purpose = fillPurpose(purpose); boolean purposeConsented = false; Set<Integer> mandatoryPIIs = getMandatoryPIIs(purpose); if (log.isDebugEnabled()) { log.debug("Mandatory PIIs for purpose : " + purpose.getName() + " : " + Arrays.toString(mandatoryPIIs.toArray())); } for (ReceiptServiceInput service : services) { List<ReceiptPurposeInput> consentPurposes = service.getPurposes(); for (ReceiptPurposeInput consentPurpose : consentPurposes) { if (consentPurpose.getPurposeId() == purpose.getId()) { purposeConsented = true; List<PIICategoryValidity> pIICategories = consentPurpose.getPiiCategory(); Set<Integer> consentedPIIs = getPIIs(pIICategories); if (log.isDebugEnabled()) { log.debug("Consented PIIs: " + Arrays.toString(consentedPIIs.toArray())); } if (!consentedPIIs.containsAll(mandatoryPIIs)) { throw new ConsentUtilityServiceException( "One or more mandatory attributes are missing in " + "the given receipt"); } } } if (!purposeConsented && !mandatoryPIIs.isEmpty()) { throw new ConsentUtilityServiceException( "Consent receipt does not contain consent for " + "purpose " + purpose.getName() + " with ID: " + purpose.getId() + ", which has " + "mandatory PIIs"); } } } }
From source file:com.hybris.backoffice.cockpitng.dataaccess.facades.DefaultPlatformPermissionFacadeStrategyTest.java
@Test public void testGetReadableLocalesForInstanceAsAdmin() { final Set<Locale> locales = new HashSet<Locale>(); locales.add(Locale.ENGLISH);/* ww w .j av a 2 s .c o m*/ locales.add(Locale.GERMAN); locales.add(Locale.JAPAN); final DefaultPlatformPermissionFacadeStrategy permissionFacade = new DefaultPlatformPermissionFacadeStrategy() { @Override public Set<Locale> getAllReadableLocalesForCurrentUser() { return locales; } @Override public Set<Locale> getAllWritableLocalesForCurrentUser() { return locales; } }; permissionFacade.setCatalogTypeService(catalogTypeService); permissionFacade.setCommonI18NService(commonI18NService); permissionFacade.setUserService(userService); Mockito.when(userService.isAdmin(user)).thenReturn(true); LanguageModel german = new LanguageModel(); german.setIsocode(GERMAN_ISO_CODE); catalog.setLanguages(Collections.singletonList(german)); final Set<Locale> readableLocalesForInstance = permissionFacade.getReadableLocalesForInstance(product); //Even though catalog is restricted for geramn language only - in case of admin, facade returns all readable languages of the admin user - all defined. In this test - English Assert.assertTrue(readableLocalesForInstance.containsAll(locales)); }
From source file:net.sf.jabref.logic.groups.KeywordGroup.java
@Override public boolean contains(BibEntry entry) { if (regExp) { Optional<String> content = entry.getFieldOptional(searchField); return content.map(value -> pattern.matcher(value).find()).orElse(false); }/*from w w w .j a v a 2 s . c om*/ Set<String> words = entry.getFieldAsWords(searchField); if (words.isEmpty()) { return false; } if (caseSensitive) { return words.containsAll(searchWords); } return containsCaseInsensitive(searchWords, words); }
From source file:org.apache.jackrabbit.oak.plugins.document.SharedBlobStoreGCTest.java
@Test // GC should fail public void testOnly1ClusterMark() throws Exception { log.debug("Running testOnly1ClusterMark()"); // Only run the mark phase on one cluster cluster1.gc.collectGarbage(true);// w ww . j a va 2s.com // Execute the gc with sweep cluster1.gc.collectGarbage(false); Set<String> existing = cluster1.getExistingBlobIds(); log.debug("Existing blobs {}", existing); Assert.assertTrue((cluster1.getInitBlobs().size() + cluster2.getInitBlobs().size()) <= existing.size()); Assert.assertTrue(existing.containsAll(cluster2.getInitBlobs())); Assert.assertTrue(existing.containsAll(cluster1.getInitBlobs())); }
From source file:uniol.apt.analysis.processmining.InvariantsMapper.java
/** * Define an invariant mapper over the given alphabet with the given words being invariant. All {@link * ParikhVector}s that should later be mapped must be over the given alphabet. For example, with the only * invariant being "a","b", the words "c" and "a","c","b" will be mapped to the equal results. * @param alphabet The alphabet over which Parikh vectors will be given. * @param invariantWords A collection of words which should be invariant. *///from www. j a v a 2 s .c o m public InvariantsMapper(Set<String> alphabet, Collection<List<String>> invariantWords) { alphabetList = new ArrayList<>(alphabet); if (alphabetList.isEmpty()) return; Set<ParikhVector> invariants = new HashSet<>(); for (List<String> word : invariantWords) { ParikhVector wordPV = new ParikhVector(word); invariants.add(wordPV); if (!alphabet.containsAll(wordPV.getLabels())) throw new IllegalArgumentException(); } Matrix transformation; List<Integer> diagonals; if (invariants.isEmpty()) { // This would need a matrix with dimension zero. Instead, give the result explicitly. debug("No invariants giving, using identity mapping"); transformation = ArrayMatrix.createIdentityMatrix(alphabetList.size(), alphabetList.size()); diagonals = Collections.emptyList(); } else { // Turn the invariants into a matrix where each column is the Parikh vector of an invariant Matrix matrix = ArrayMatrix.createIdentityMatrix(alphabetList.size(), invariants.size()); int invariantNumber = 0; for (ParikhVector invariant : invariants) { int eventNumber = 0; for (String event : alphabetList) { matrix.set(eventNumber, invariantNumber, invariant.get(event)); eventNumber++; } invariantNumber++; } // Calculate the Smith normal form of the above matrix SmithNormalForm nf = new SmithNormalForm(matrix); transformation = nf.getLeftHandMatrixInverse(); diagonals = nf.getDiagonalEntries(); debugFormat("Calculated smith normal form: %s*(%s)*%s", nf.getLeftHandMatrix(), diagonals, nf.getRightHandMatrix()); debugFormat("Inverse matrices are %s and %s", nf.getLeftHandMatrixInverse(), nf.getRightHandMatrixInverse()); } // Each non-zero diagonal entry corresponds to a "vanishing dimension", i.e. some new-event who will be // ignored in the following. Each zero diagonal entry produces a new event. for (int index = 0; index < alphabetList.size(); index++) { int diag = index < diagonals.size() ? diagonals.get(index) : 0; if (diag != 0) { // haven't reached the zero entries yet continue; } List<Integer> weights = new ArrayList<>(); int eventIndex = 0; for (String event : alphabetList) { weights.add(transformation.get(index, eventIndex)); eventIndex++; } newEventWeights.add(weights); debugFormat("New event e_%d has weights %s in %s", index, weights, alphabetList); } }
From source file:com.clustercontrol.poller.impl.Snmp4jPollerImpl.java
private boolean isProcessOidList(Set<String> oids) { return oids.size() == processOidList.size() && oids.containsAll(processOidList); }