List of usage examples for java.util.stream Collectors toCollection
public static <T, C extends Collection<T>> Collector<T, ?, C> toCollection(Supplier<C> collectionFactory)
From source file:org.codice.ddf.security.sts.claims.property.UsersAttributesFileClaimsHandlerTest.java
private static ClaimCollection getClaimCollectionForValidTestAttributesFile() { // all attribute names in resources/users.attributes final String[] attributeNames = { "Clearance", "CountryOfAffiliation", "classification", "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress", "ownerProducer", "releasableTo", "FineAccessControls", "disseminationControls", "reg" }; return Arrays.stream(attributeNames).map(attributeName -> { final Claim claim = new Claim(); claim.setClaimType(URI.create(attributeName)); return claim; }).collect(Collectors.toCollection(ClaimCollection::new)); }
From source file:it.unibo.alchemist.model.implementations.environments.AbstractEnvironment.java
private Queue<Operation> toQueue(final Node<T> center, final Neighborhood<T> oldNeighborhood, final Neighborhood<T> newNeighborhood) { return Stream .concat(lostNeighbors(center, oldNeighborhood, newNeighborhood), foundNeighbors(center, oldNeighborhood, newNeighborhood)) .collect(Collectors.toCollection(LinkedList::new)); }
From source file:com.joyent.manta.client.multipart.EncryptedJobsMultipartManagerIT.java
public void canListMultipartUploadsInProgress() throws IOException { final String[] objects = new String[] { testPathPrefix + uploadName("can-list-multipart-uploads-in-progress-1"), testPathPrefix + uploadName("can-list-multipart-uploads-in-progress-2"), testPathPrefix + uploadName("can-list-multipart-uploads-in-progress-3") }; final List<EncryptedMultipartUpload<JobsMultipartUpload>> uploads = new ArrayList<>(objects.length); for (String object : objects) { uploads.add(multipart.initiateUpload(object)); }/*from w w w . j a v a2 s . co m*/ final List<MantaMultipartUpload> list; try (Stream<MantaMultipartUpload> inProgress = multipart.listInProgress()) { list = inProgress.collect(Collectors.toCollection(ArrayList::new)); } try { assertFalse(list.isEmpty(), "List shouldn't be empty"); for (EncryptedMultipartUpload<JobsMultipartUpload> upload : uploads) { assertTrue(list.contains(upload.getWrapped()), "Upload wasn't present in results: " + upload); } } finally { for (MantaMultipartUpload upload : uploads) { if (upload instanceof EncryptedMultipartUpload) { @SuppressWarnings("unchecked") EncryptedMultipartUpload<JobsMultipartUpload> encryptedUpload = (EncryptedMultipartUpload<JobsMultipartUpload>) upload; multipart.abort(encryptedUpload); } } } }
From source file:com.evolveum.midpoint.common.refinery.CompositeRefinedObjectClassDefinitionImpl.java
@Override public Collection<? extends QName> getNamesOfAssociationsWithOutboundExpressions() { return getAssociationDefinitions().stream().filter(assocDef -> assocDef.getOutboundMappingType() != null) .map(a -> a.getName()).collect(Collectors.toCollection(HashSet::new)); }
From source file:com.adobe.acs.commons.mcp.impl.processes.PageRelocator.java
@SuppressWarnings("squid:S00112") private void movePage(ResourceResolver rr, String sourcePage) throws Exception { PageManager manager = pageManagerFactory.getPageManager(rr); Field replicatorField = FieldUtils.getDeclaredField(manager.getClass(), "replicator", true); FieldUtils.writeField(replicatorField, manager, replicatorQueue); String destination = convertSourceToDestination(sourcePage); String destinationParent = destination.substring(0, destination.lastIndexOf('/')); note(sourcePage, Report.target, destination); String beforeName = ""; final long start = System.currentTimeMillis(); String contentPath = sourcePage + "/jcr:content"; List<String> refs = new ArrayList<>(); List<String> publishRefs = new ArrayList<>(); if (maxReferences != 0 && resourceExists(rr, contentPath)) { ReferenceSearch refSearch = new ReferenceSearch(); refSearch.setExact(true);/*from w w w . java2 s . com*/ refSearch.setHollow(true); refSearch.setMaxReferencesPerPage(maxReferences); refSearch.setSearchRoot(referenceSearchRoot); refSearch.search(rr, sourcePath).values().stream().peek(p -> refs.add(p.getPagePath())) .filter(p -> isActivated(rr, p.getPagePath())).map(ReferenceSearch.Info::getPagePath) .collect(Collectors.toCollection(() -> publishRefs)); } note(sourcePage, Report.all_references, refs.size()); note(sourcePage, Report.published_references, publishRefs.size()); if (!dryRun) { Actions.retry(10, 500, res -> { waitUntilResourceFound(res, destinationParent); Resource source = rr.getResource(sourcePage); if (resourceExists(res, contentPath)) { manager.move(source, destination, beforeName, true, true, listToStringArray(refs), listToStringArray(publishRefs)); } else { Map<String, Object> props = new HashMap<>(); Resource parent = res.getResource(destinationParent); res.create(parent, source.getName(), source.getValueMap()); } res.commit(); res.refresh(); source = rr.getResource(sourcePage); if (source != null && source.hasChildren()) { for (Resource child : source.getChildren()) { res.move(child.getPath(), destination); } res.commit(); } }).accept(rr); } long end = System.currentTimeMillis(); note(sourcePage, Report.move_time, end - start); }
From source file:com.evolveum.midpoint.common.refinery.CompositeRefinedObjectClassDefinitionImpl.java
@Override public Collection<? extends QName> getNamesOfAssociationsWithInboundExpressions() { return getAssociationDefinitions().stream() .filter(assocDef -> CollectionUtils.isNotEmpty(assocDef.getInboundMappingTypes())) .map(a -> a.getName()).collect(Collectors.toCollection(HashSet::new)); }
From source file:org.codice.ddf.catalog.ui.util.EndpointUtil.java
@SuppressWarnings("squid:S1319") // needs to match signature of AttributeImpl public ArrayList<String> getStringList(List<Serializable> list) { if (list == null) { return new ArrayList<>(); }/*w ww . j ava 2s. co m*/ return list.stream().map(String::valueOf).collect(Collectors.toCollection(ArrayList::new)); }
From source file:com.github.jackygurui.vertxredissonrepository.repository.Impl.RedisRepositoryImpl.java
private void searchIndexByValueBlocking(String fieldName, String indexName, String min, String max, Integer offset, Integer limit, AsyncResultHandler<List<String>> resultHandler) { redissonOther.<String>getLexSortedSet(getScoredSortedIndexKey(fieldName, indexName)) .lexRangeAsync(min, true, max, true, offset, limit).addListener(future -> { Collection<String> res = (Collection<String>) future.get(); try { ArrayList<String> ids = res.stream().map(r -> lookupIdFromIndex(r, fieldName, indexName)) .collect(Collectors.toCollection(ArrayList::new)); resultHandler//from ww w. j a va 2s .c o m .handle(future.isSuccess() ? (future.get() != null ? Future.succeededFuture(ids) : Future.failedFuture( new RepositoryException("No search result returned"))) : Future.failedFuture(new RepositoryException(future.cause()))); if (future.isSuccess()) { logger.debug("[" + getStorageKey() + "] Search Index By Value Success. Records: " + ((Collection<String>) future.get()).size()); } else { logger.debug("[" + getStorageKey() + "] Search Index By Value Failure.", future.cause()); } } catch (RuntimeException e) { resultHandler.handle(Future.failedFuture(e.getCause())); logger.debug("[" + getStorageKey() + "] Search Index By Value Failure.", e); } }); }
From source file:chatbot.Chatbot.java
/**************************************************************************************************** * * @param responses//from ww w .j a v a 2s. c o m * @param input * @return */ private ArrayList<String> rankResponsesOnSentiment(ArrayList<String> responses, String input) { if (DB.sentiment.keySet().size() < 1) DB.readSentimentArray(); if (isExcludingNegativeSentiment) responses = responses.stream().filter(r -> DB.computeSentiment(r) >= 0) .collect(Collectors.toCollection(ArrayList::new)); else if (isMatchingSentiment) responses = responses.stream() .filter(r -> compareSentiment(DB.computeSentiment(r), DB.computeSentiment(input))) .collect(Collectors.toCollection(ArrayList::new)); return responses.size() > 0 ? responses : new ArrayList<>(Collections.singletonList("I don't know")); }
From source file:com.ge.predix.acs.service.policy.evaluation.PolicyEvaluationServiceTest.java
private Object[] filterOnePolicySetByNonexistentPolicySet(final List<PolicySet> onePolicySet) { return new Object[] { onePolicySet, Stream.of("nonexistent-policy-set").collect(Collectors.toCollection(LinkedHashSet::new)) }; }