List of usage examples for java.util Collection stream
default Stream<E> stream()
From source file:ch.wisv.areafiftylan.utils.TaskScheduler.java
@Scheduled(fixedRate = ORDER_EXPIRY_CHECK_INTERVAL_SECONDS * 1000) public void ExpireOrders() { LocalDateTime expireBeforeDate = LocalDateTime.now().minusMinutes(ORDER_STAY_ALIVE_MINUTES); Collection<Order> allOrdersBeforeDate = orderRepository.findAllByCreationDateTimeBefore(expireBeforeDate); List<Order> expiredOrders = allOrdersBeforeDate.stream().filter(isExpired()).collect(Collectors.toList()); expiredOrders.forEach(o -> orderService.expireOrder(o)); }
From source file:de.hybris.platform.mpintgordermanagement.listeners.impl.MarketplaceSubmitEventListener.java
@Override public void afterSave(final Collection<AfterSaveEvent> events) { events.stream().filter(e -> { final int code = e.getPk().getTypeCode(); log.debug("checking event pk(code): " + code + " (expected: " + TMALL_ORDER_DEPLOYMENT_CODE + ")"); return (e.getType() == AfterSaveEvent.CREATE) && (code == TMALL_ORDER_DEPLOYMENT_CODE); }).forEach(e -> {/*from ww w . j a va 2s .c om*/ final PK pk = e.getPk(); log.info(String.format("found event{type:%d, pk:%s, type_code:%s, pk_value:%s}", e.getType(), pk, pk.getTypeCodeAsString(), pk.getLongValueAsString())); final TmallOrderEntryModel entry = modelService.<TmallOrderEntryModel>get(pk); final TmallOrderModel order = (TmallOrderModel) entry.getOrder(); final String TmallOrderEntriesNo = String.valueOf(order.getEntries().size()); if (order.getTmallOrderEntriesNo().equals(TmallOrderEntriesNo)) { order.setIsCompleted(true); modelService.save(order); } }); events.stream().filter(e -> { final int code = e.getPk().getTypeCode(); log.debug("checking event pk(code): " + code + " (expected: " + TMALL_ORDER_DEPLOYMENT_CODE + ")"); return (code == TMALL_ORDER_DEPLOYMENT_CODE && e.getType() != AfterSaveEvent.REMOVE); }).forEach(e -> { final PK pk = e.getPk(); log.info(String.format("found event{type:%d, pk:%s, type_code:%s, pk_value:%s}", e.getType(), pk, pk.getTypeCodeAsString(), pk.getLongValueAsString())); final TmallOrderEntryModel entry = modelService.<TmallOrderEntryModel>get(pk); final TmallOrderModel order = (TmallOrderModel) entry.getOrder(); final String TmallOrderEntriesNo = String.valueOf(order.getEntries().size()); BaseStoreModel baseStoreModel = order.getMarketplaceStore().getMarketplaceSeller().getBaseStore(); String submitOrderProcessCode = baseStoreModel.getSubmitOrderProcessCode(); if (TmallOrderEntriesNo.equals(order.getTmallOrderEntriesNo()) && !isContainProcess(order.getOrderProcess(), submitOrderProcessCode) && entry.getEntryStatus().getCode().equals("WAIT_SELLER_SEND_GOODS")) { order.setStore(order.getMarketplaceStore().getMarketplaceSeller().getBaseStore()); modelService.save(order); final OrderProcessModel TmallContinuationProcess = businessProcessService .<OrderProcessModel>createProcess(submitOrderProcessCode + "-" + order.getCode() + "-" + order.getModifiedtime().getTime(), submitOrderProcessCode); TmallContinuationProcess.setOrder(order); modelService.save(TmallContinuationProcess); log.info("Start Order continuation-process: '" + TmallContinuationProcess.getCode() + "'"); businessProcessService.startProcess(TmallContinuationProcess); } for (ConsignmentModel consignment : order.getConsignments()) { if (confirmShipService.canPerform(consignment)) { final Set<ConsignmentEntryModel> consignmentEntries = consignment.getConsignmentEntries(); for (final ConsignmentEntryModel consignmentEntry : consignmentEntries) { final TmallOrderEntryModel orderEntry = (TmallOrderEntryModel) consignmentEntry .getOrderEntry(); orderEntry.setWaitMarketPlaceResponse(Boolean.TRUE); } } } }); }
From source file:ijfx.core.io.ExplorableIOTest.java
private int contentHash(Collection<? extends Taggable> set) { return set.stream().map(Taggable::getMetaDataSet).mapToInt(ExplorableList::contentHash).sum(); }
From source file:com.netflix.spinnaker.fiat.permissions.DefaultPermissionsResolver.java
private Map<String, Collection<Role>> getAndMergeUserRoles(@NonNull Collection<ExternalUser> users) { List<String> usernames = users.stream().map(ExternalUser::getId).collect(Collectors.toList()); Map<String, Collection<Role>> userToRoles = userRolesProvider.multiLoadRoles(usernames); users.forEach(user -> {//from ww w. j av a2 s . c om userToRoles.computeIfAbsent(user.getId(), ignored -> new ArrayList<>()).addAll(user.getExternalRoles()); }); if (log.isDebugEnabled()) { try { log.debug("Multi-loaded roles: \n" + mapper.writerWithDefaultPrettyPrinter().writeValueAsString(userToRoles)); } catch (Exception e) { log.debug("Exception writing roles", e); } } return userToRoles; }
From source file:edu.ehu.galan.lite.model.Corpus.java
/** * Loads a corpus from a given folder and scans recursively all the documents inside it, * then it reorder using the file name (uses FilesUtils from CommonsIO), you need to choose * the source of knowledge to be used (Wikipedia or Wordnet) * @param pRootFolder//from w ww .j a v a2 s . c om * @param pType */ public void loadCorpus(String pRootFolder, Document.SourceType pType) { File file = new File(pRootFolder); rootFolder = pRootFolder; Collection<File> documents = FileUtils.listFiles(file, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE); documents.stream().sorted((d1, d2) -> d1.getName().compareTo(d2.getName())) .forEachOrdered((f) -> docList.add(new Document(f.getAbsolutePath(), f.getName()))); }
From source file:io.gravitee.repository.mongodb.management.MongoApiRepository.java
private Set<Api> mapApis(Collection<ApiMongo> apis) { return apis.stream().map(this::mapApi).collect(Collectors.toSet()); }
From source file:com.teradata.presto.yarn.test.utils.NodeSshUtils.java
public <T> List<T> withSshClient(Collection<String> hosts, Function<SshClient, T> closure) { return hosts.stream().map(host -> withSshClient(host, closure)).collect(toList()); }
From source file:io.gravitee.management.service.impl.PolicyServiceImpl.java
@Override public Set<PolicyEntity> findAll() { try {//from w w w. ja va 2 s . com LOGGER.debug("List all policies"); final Collection<PolicyPlugin> policyDefinitions = policyManager.findAll(); return policyDefinitions.stream().map(policyDefinition -> convert(policyDefinition, false)) .collect(Collectors.toSet()); } catch (Exception ex) { LOGGER.error("An error occurs while trying to list all policies", ex); throw new TechnicalManagementException("An error occurs while trying to list all policies", ex); } }
From source file:com.olacabs.fabric.compute.builder.impl.JarScanner.java
URL[] download(Collection<String> urls) { ArrayList<URL> downloadedURLs = urls.stream().map(url -> { URI uri = URI.create(url); String downloaderImplClassName = properties.getProperty(String.format("fs.%s.impl", uri.getScheme())); if (null == downloaderImplClassName) { throw new RuntimeException( new UnsupportedSchemeException(uri.getScheme() + " is not supported for downloading jars")); }//from w ww. j a v a 2s . c o m try { Class clazz = Class.forName(downloaderImplClassName); if (JarDownloader.class.isAssignableFrom(clazz)) { try { return ((JarDownloader) clazz.newInstance()).download(url).toUri().toURL(); } catch (Exception e) { throw new RuntimeException(e); } } else { throw new RuntimeException("Unsupported implementation " + downloaderImplClassName + " of " + JarDownloader.class.getSimpleName()); } } catch (ClassNotFoundException e) { throw new RuntimeException(e); } }).collect(Collectors.toCollection(ArrayList::new)); return downloadedURLs.toArray(new URL[downloadedURLs.size()]); }
From source file:com.asakusafw.runtime.directio.hadoop.HadoopDataSourceUtil.java
private static void parallel(ExecutorService executor, Collection<? extends Callable<?>> tasks) throws IOException, InterruptedException { List<Future<?>> futures = tasks.stream().map(task -> executor.submit(task)).collect(Collectors.toList()); for (Future<?> future : futures) { try {//from w w w . j ava 2 s .c om future.get(); } catch (CancellationException | InterruptedException e) { cancel(futures); throw e; } catch (ExecutionException e) { cancel(futures); try { throw e.getCause(); } catch (Error | RuntimeException | IOException | InterruptedException cause) { throw cause; } catch (Throwable cause) { throw new IOException(cause); } } } }