List of usage examples for java.util Collection containsAll
boolean containsAll(Collection<?> c);
From source file:org.apache.hadoop.hbase.regionserver.compactions.TestStripeCompactionPolicy.java
private void verifyCollectionsEqual(Collection<StoreFile> sfs, Collection<StoreFile> scr) { // Dumb./*from w ww . j a va2 s. com*/ assertEquals(sfs.size(), scr.size()); assertTrue(scr.containsAll(sfs)); }
From source file:org.sparkcommerce.admin.server.service.AdminCatalogServiceImpl.java
protected boolean isSamePermutation(List<ProductOptionValue> perm1, List<ProductOptionValue> perm2) { if (perm1.size() == perm2.size()) { Collection<Long> perm1Ids = SCCollectionUtils.collect(perm1, new TypedTransformer<Long>() { @Override//w w w. j a v a2 s. c om public Long transform(Object input) { return ((ProductOptionValue) input).getId(); } }); Collection<Long> perm2Ids = SCCollectionUtils.collect(perm2, new TypedTransformer<Long>() { @Override public Long transform(Object input) { return ((ProductOptionValue) input).getId(); } }); return perm1Ids.containsAll(perm2Ids); } return false; }
From source file:org.broadleafcommerce.admin.server.service.AdminCatalogServiceImpl.java
protected boolean isSamePermutation(List<ProductOptionValue> perm1, List<ProductOptionValue> perm2) { if (perm1.size() == perm2.size()) { Collection<Long> perm1Ids = BLCCollectionUtils.collect(perm1, new TypedTransformer<Long>() { @Override//from w w w. ja va 2s . c om public Long transform(Object input) { return ((ProductOptionValue) input).getId(); } }); Collection<Long> perm2Ids = BLCCollectionUtils.collect(perm2, new TypedTransformer<Long>() { @Override public Long transform(Object input) { return ((ProductOptionValue) input).getId(); } }); return perm1Ids.containsAll(perm2Ids); } return false; }
From source file:org.opengrok.suggest.SuggesterProjectData.java
private void initFields(final Set<String> fields) throws IOException { try (IndexReader indexReader = DirectoryReader.open(indexDir)) { Collection<String> indexedFields = MultiFields.getIndexedFields(indexReader); if (fields == null) { this.fields = new HashSet<>(indexedFields); } else if (!indexedFields.containsAll(fields)) { Set<String> copy = new HashSet<>(fields); copy.removeAll(indexedFields); logger.log(Level.WARNING, "Fields {0} will be ignored because they were not found in index directory {1}", new Object[] { copy, indexDir }); copy = new HashSet<>(fields); copy.retainAll(indexedFields); this.fields = copy; } else {//from ww w . j a v a2 s .c om this.fields = new HashSet<>(fields); } } }
From source file:org.apache.stanbol.enhancer.nlp.model.AnalysedTextTest.java
@Test public void testAnalysedTextaddSpanMethods() { Collection<Span> spans = new HashSet<Span>(); //add some span of different types spans.add(at.addToken(4, 11));/*from w w w .j a va2 s. c o m*/ spans.add(at.addChunk(4, 19)); spans.add(at.addSentence(0, 91)); Set<Span> atSpans = AnalysedTextUtils.asSet(at.getEnclosed(EnumSet.allOf(SpanTypeEnum.class))); Assert.assertTrue(spans.containsAll(atSpans)); Assert.assertTrue(atSpans.containsAll(spans)); }
From source file:org.apache.ranger.plugin.policyresourcematcher.RangerDefaultPolicyResourceMatcher.java
@Override public boolean isMatch(Map<String, RangerPolicyResource> resources, Map<String, Object> evalContext) { if (LOG.isDebugEnabled()) { LOG.debug("==> RangerDefaultPolicyResourceMatcher.isMatch(" + resources + ", " + evalContext + ")"); }//from www.j a va2 s .c o m boolean ret = false; if (serviceDef != null && serviceDef.getResources() != null) { Collection<String> resourceKeys = resources == null ? null : resources.keySet(); Collection<String> policyKeys = matchers == null ? null : matchers.keySet(); boolean keysMatch = CollectionUtils.isEmpty(resourceKeys) || (policyKeys != null && policyKeys.containsAll(resourceKeys)); if (keysMatch) { for (RangerResourceDef resourceDef : serviceDef.getResources()) { String resourceName = resourceDef.getName(); RangerPolicyResource resourceValues = resources == null ? null : resources.get(resourceName); RangerResourceMatcher matcher = matchers == null ? null : matchers.get(resourceName); // when no value exists for a resourceName, consider it a match only if: policy doesn't have a matcher OR matcher allows no-value resource if (resourceValues == null || CollectionUtils.isEmpty(resourceValues.getValues())) { ret = matcher == null || matcher.isMatch(null, null); } else if (matcher != null) { for (String resourceValue : resourceValues.getValues()) { ret = matcher.isMatch(resourceValue, evalContext); if (!ret) { break; } } } if (!ret) { break; } } } else { if (LOG.isDebugEnabled()) { LOG.debug("isMatch(): keysMatch=false. resourceKeys=" + resourceKeys + "; policyKeys=" + policyKeys); } } } if (LOG.isDebugEnabled()) { LOG.debug("<== RangerDefaultPolicyResourceMatcher.isMatch(" + resources + ", " + evalContext + "): " + ret); } return ret; }
From source file:org.springframework.integration.x.kafka.KafkaPartitionAllocator.java
@Override public synchronized Partition[] getObject() throws Exception { if (log.isDebugEnabled()) { log.debug("Module name is " + moduleName); log.debug("Stream name is " + streamName); log.debug("Cardinality is " + count); log.debug("Sequence is " + sequence); log.debug("Client is " + client); }//from ww w . j av a 2 s . c o m if (partitions == null) { if (STARTED.equals(client.getState())) { try { partitionDataMutex.acquire(); byte[] partitionData = client.getData().forPath(partitionDataPath); if (partitionData == null || partitionData.length == 0) { Collection<Partition> existingPartitions = connectionFactory.getPartitions(topic); Collection<Partition> listenedPartitions = !StringUtils.hasText(partitionList) ? existingPartitions : Arrays.asList(toPartitions(parseNumberList(partitionList))); if (existingPartitions != listenedPartitions && !existingPartitions.containsAll(listenedPartitions)) { Collection<Partition> partitionsNotFound = new ArrayList<Partition>(listenedPartitions); partitionsNotFound.removeAll(existingPartitions); throw new BeanInitializationException( "Configuration contains partitions that do not exist on the topic" + " or have unavailable leaders: " + StringUtils.collectionToCommaDelimitedString(partitionsNotFound)); } final Map<Partition, BrokerAddress> leaders = connectionFactory .getLeaders(listenedPartitions); ArrayList<Partition> sortedPartitions = new ArrayList<Partition>(listenedPartitions); Collections.sort(sortedPartitions, new Comparator<Partition>() { @Override public int compare(Partition o1, Partition o2) { int i = leaders.get(o1).toString().compareTo(leaders.get(o2).toString()); if (i != 0) { return i; } else return o1.getId() - o2.getId(); } }); if (log.isDebugEnabled()) { log.debug("Partitions: " + StringUtils.collectionToCommaDelimitedString(sortedPartitions)); } // calculate the minimum size of a partition group. int minimumSize = sortedPartitions.size() / count; int remainder = sortedPartitions.size() % count; List<List<Integer>> partitionGroups = new ArrayList<List<Integer>>(); int cursor = 0; for (int i = 0; i < count; i++) { // first partitions will get an extra element int partitionGroupSize = i < remainder ? minimumSize + 1 : minimumSize; ArrayList<Integer> partitionGroup = new ArrayList<Integer>(); for (int j = 0; j < partitionGroupSize; j++) { partitionGroup.add(sortedPartitions.get(cursor++).getId()); } if (log.isDebugEnabled()) { log.debug("Partitions for " + (i + 1) + " : " + StringUtils.collectionToCommaDelimitedString(partitionGroup)); } partitionGroups.add(partitionGroup); } byte[] dataAsBytes = objectMapper.writer().writeValueAsBytes(partitionGroups); if (log.isDebugEnabled()) { log.debug(new String(dataAsBytes)); } client.setData().forPath(partitionDataPath, dataAsBytes); // the partition mapping is stored 0-based but sequence/count are 1-based if (log.isDebugEnabled()) { log.debug("Listening to: " + StringUtils .collectionToCommaDelimitedString(partitionGroups.get(sequence - 1))); } partitions = toPartitions(partitionGroups.get(sequence - 1)); } else { if (log.isDebugEnabled()) { log.debug(new String(partitionData)); } @SuppressWarnings("unchecked") List<List<Integer>> partitionGroups = objectMapper.reader(List.class) .readValue(partitionData); // the partition mapping is stored 0-based but sequence/count are 1-based if (log.isDebugEnabled()) { log.debug("Listening to: " + StringUtils .collectionToCommaDelimitedString(partitionGroups.get(sequence - 1))); } partitions = toPartitions(partitionGroups.get(sequence - 1)); } return partitions; } finally { if (partitionDataMutex.isAcquiredInThisProcess()) { partitionDataMutex.release(); } } } else { throw new BeanInitializationException( "Cannot connect to ZooKeeper, client state is " + client.getState()); } } else { return partitions; } }
From source file:mitm.djigzo.web.common.security.Authorizer.java
/** * @return false as the default. Returns true if all non-null role expressions are * satisfied. Typically, only one will be used, but if more than one are used, then * the conditions are effectively AND'd *//*from www .j a v a 2 s .c o m*/ @SuppressWarnings("unchecked") public boolean isAuthorized() { if (((null == ifAllGranted) || "".equals(ifAllGranted)) && ((null == ifAnyGranted) || "".equals(ifAnyGranted)) && ((null == role) || "".equals(role)) && ((null == ifNotGranted) || "".equals(ifNotGranted))) { return false; } final Collection granted = getPrincipalAuthorities(); if ((null != role) && !"".equals(role)) { Set grantedCopy = retainAll(granted, parseAuthoritiesString(role)); if (grantedCopy.isEmpty()) { return false; } } if ((null != ifNotGranted) && !"".equals(ifNotGranted)) { Set grantedCopy = retainAll(granted, parseAuthoritiesString(ifNotGranted)); if (!grantedCopy.isEmpty()) { return false; } } if ((null != ifAllGranted) && !"".equals(ifAllGranted)) { if (!granted.containsAll(parseAuthoritiesString(ifAllGranted))) { return false; } } if ((null != ifAnyGranted) && !"".equals(ifAnyGranted)) { Set grantedCopy = retainAll(granted, parseAuthoritiesString(ifAnyGranted)); if (grantedCopy.isEmpty()) { return false; } } return true; }
From source file:ch.astina.hesperid.web.components.security.IfRole.java
/** * @return false as the default. Returns true if all non-null role expressions are * satisfied. Typically, only one will be used, but if more than one are used, then * the conditions are effectively AND'd *///ww w . ja va 2s . c o m @SuppressWarnings("unchecked") private boolean checkPermission() { if (((null == ifAllGranted) || "".equals(ifAllGranted)) && ((null == ifAnyGranted) || "".equals(ifAnyGranted)) && ((null == role) || "".equals(role)) && ((null == ifNotGranted) || "".equals(ifNotGranted))) { return false; } final Collection granted = getPrincipalAuthorities(); if ((null != role) && !"".equals(role)) { Set grantedCopy = retainAll(granted, parseAuthoritiesString(role)); if (grantedCopy.isEmpty()) { return false; } } if ((null != ifNotGranted) && !"".equals(ifNotGranted)) { Set grantedCopy = retainAll(granted, parseAuthoritiesString(ifNotGranted)); if (!grantedCopy.isEmpty()) { return false; } } if ((null != ifAllGranted) && !"".equals(ifAllGranted)) { if (!granted.containsAll(parseAuthoritiesString(ifAllGranted))) { return false; } } if ((null != ifAnyGranted) && !"".equals(ifAnyGranted)) { Set grantedCopy = retainAll(granted, parseAuthoritiesString(ifAnyGranted)); if (grantedCopy.isEmpty()) { return false; } } return true; }
From source file:de.topicmapslab.couchtm.core.NameImpl.java
@Override public Variant createVariant(String value, Locator datatype, Collection<Topic> scope) { if (!loaded)/*from w w w. j a va 2 s . c om*/ load(); if (mergedIn != null) return mergedIn.createVariant(value, datatype, scope); Check.valueNotNull(this, value, datatype); if (this.scope.containsAll(scope) && scope.containsAll(this.scope)) throw new ModelConstraintException(this, "The Variant's scope has to be a true subset of the Name's scope"); Check.scopeNotNull(this, scope); Set<ITopic> _scope = CollectionFactory.createSet(); for (Topic topic : scope) _scope.add((ITopic) topic); IVariant variant = MergeCheck.createCheckVariant(value, datatype, _scope, this, tm); if (variant == null) { variant = new VariantImpl(tm.getSystem().getNewId(), tm, this, value, datatype, _scope); tmom.saveConstruct(variant); variants.add(variant); tmom.saveConstruct(this); } return variant; }