List of usage examples for java.util Collection forEach
default void forEach(Consumer<? super T> action)
From source file:com.fredhopper.connector.index.populator.ProductEssentialsPopulator.java
@Override public void populate(final ItemToConvert<ProductModel> source, final FhProductData target) throws ConversionException { Preconditions.checkArgument(source != null); Preconditions.checkArgument(target != null); final IndexConfig indexConfig = source.getIndexConfig(); final ProductModel product = source.getItem(); Preconditions.checkArgument(indexConfig != null); Preconditions.checkArgument(CollectionUtils.isNotEmpty(indexConfig.getLocales())); target.setProductId(getSanitizeIdStrategy().sanitizeId(product.getCode())); final Collection<CategoryModel> input = categoryFilterStrategy .filterCategories(product.getSupercategories(), getCategorySource().getRootCategories()); if (CollectionUtils.isNotEmpty(input)) { final Set<String> categoryIds = new HashSet<>(); input.forEach(category -> categoryIds.add(getSanitizeIdStrategy().sanitizeId(category.getCode()))); final HashMap<Locale, Set<String>> output = new HashMap<>(); indexConfig.getLocales().forEach(locale -> output.put(locale, categoryIds)); target.setCategories(output);/*from www . ja v a2s . co m*/ } else { throw new ConversionException("Product: " + product.getCode() + " does not belong to any categories."); } }
From source file:org.jbpm.workbench.forms.display.backend.provider.KieWorkbenchFormsValuesProcessor.java
protected ContextForms generateDefaultForms(T settings) { ContextForms result = new ContextForms(); Collection<FormDefinition> contextForms = generateDefaultFormsForContext(settings); if (contextForms == null) { throw new IllegalArgumentException("Unable to create forms for context"); }/*from www. jav a2 s . c o m*/ contextForms.forEach(form -> { if (form.getName().equals(getFormName(settings) + BPMNVariableUtils.TASK_FORM_SUFFIX)) { result.setRootForm(form); } else { result.getNestedForms().add(form); } }); return result; }
From source file:org.devgateway.ocds.web.rest.controller.CostEffectivenessVisualsController.java
@ApiOperation(value = "Aggregated version of /api/costEffectivenessTenderAmount and " + "/api/costEffectivenessAwardAmount." + "This endpoint aggregates the responses from the specified endpoints, per year. " + "Responds to the same filters.") @RequestMapping(value = "/api/costEffectivenessTenderAwardAmount", method = { RequestMethod.POST, RequestMethod.GET }, produces = "application/json") public List<DBObject> costEffectivenessTenderAwardAmount( @ModelAttribute @Valid final GroupingFilterPagingRequest filter) { Future<List<DBObject>> costEffectivenessAwardAmountFuture = controllerLookupService.asyncInvoke( new AsyncBeanParamControllerMethodCallable<List<DBObject>, GroupingFilterPagingRequest>() { @Override//from ww w . jav a 2s.com public List<DBObject> invokeControllerMethod(GroupingFilterPagingRequest filter) { return costEffectivenessAwardAmount(filter); } }, filter); Future<List<DBObject>> costEffectivenessTenderAmountFuture = controllerLookupService.asyncInvoke( new AsyncBeanParamControllerMethodCallable<List<DBObject>, GroupingFilterPagingRequest>() { @Override public List<DBObject> invokeControllerMethod(GroupingFilterPagingRequest filter) { return costEffectivenessTenderAmount(filter); } }, filter); //this is completely unnecessary since the #get methods are blocking //controllerLookupService.waitTillDone(costEffectivenessAwardAmountFuture, costEffectivenessTenderAmountFuture); LinkedHashMap<Object, DBObject> response = new LinkedHashMap<>(); try { costEffectivenessAwardAmountFuture.get() .forEach(dbobj -> response.put(getYearMonthlyKey(filter, dbobj), dbobj)); costEffectivenessTenderAmountFuture.get().forEach(dbobj -> { if (response.containsKey(getYearMonthlyKey(filter, dbobj))) { Map<?, ?> map = dbobj.toMap(); map.remove(Keys.YEAR); if (filter.getMonthly()) { map.remove(Keys.MONTH); } response.get(getYearMonthlyKey(filter, dbobj)).putAll(map); } else { response.put(getYearMonthlyKey(filter, dbobj), dbobj); } }); } catch (InterruptedException | ExecutionException e) { throw new RuntimeException(e); } Collection<DBObject> respCollection = response.values(); respCollection.forEach(dbobj -> { BigDecimal totalTenderAmount = BigDecimal.valueOf(dbobj.get(Keys.TOTAL_TENDER_AMOUNT) == null ? 0d : ((Number) dbobj.get(Keys.TOTAL_TENDER_AMOUNT)).doubleValue()); BigDecimal totalAwardAmount = BigDecimal.valueOf(dbobj.get(Keys.TOTAL_AWARD_AMOUNT) == null ? 0d : ((Number) dbobj.get(Keys.TOTAL_AWARD_AMOUNT)).doubleValue()); dbobj.put(Keys.DIFF_TENDER_AWARD_AMOUNT, totalTenderAmount.subtract(totalAwardAmount)); dbobj.put(Keys.PERCENTAGE_AWARD_AMOUNT, totalTenderAmount.compareTo(BigDecimal.ZERO) != 0 ? (totalAwardAmount.setScale(15).divide(totalTenderAmount, BigDecimal.ROUND_HALF_UP) .multiply(ONE_HUNDRED)) : BigDecimal.ZERO); dbobj.put(Keys.PERCENTAGE_DIFF_AMOUNT, totalTenderAmount.compareTo(BigDecimal.ZERO) != 0 ? (((BigDecimal) dbobj.get(Keys.DIFF_TENDER_AWARD_AMOUNT)).setScale(15) .divide(totalTenderAmount, BigDecimal.ROUND_HALF_UP).multiply(ONE_HUNDRED)) : BigDecimal.ZERO); }); return new ArrayList<>(respCollection); }
From source file:org.openwms.core.AbstractGenericEntityService.java
/** * {@inheritDoc}/*w ww . ja va 2 s .c o m*/ */ @Override public Collection<T> saveAll(Collection<T> entities) { Assert.notEmpty(entities, translate(ExceptionCodes.ENTITY_NOT_BE_NULL)); List<T> result = new ArrayList<>(entities.size()); entities.forEach(f -> result.add(f.isNew() ? create(f) : getRepository().save(f))); return result; }
From source file:com.ikanow.aleph2.analytics.storm.assets.PassthroughTopology.java
@Override public Tuple2<Object, Map<String, String>> getTopologyAndConfiguration(final DataBucketBean bucket, final IEnrichmentModuleContext context) { final TopologyBuilder builder = new TopologyBuilder(); final Collection<Tuple2<BaseRichSpout, String>> entry_points = context .getTopologyEntryPoints(BaseRichSpout.class, Optional.of(bucket)); //DEBUG/* ww w .j av a2 s . co m*/ _logger.debug("Passthrough topology: loaded: " + entry_points.stream().map(x -> x.toString()).collect(Collectors.joining(":"))); entry_points.forEach(spout_name -> builder.setSpout(spout_name._2(), spout_name._1())); entry_points.stream() .reduce(builder.setBolt(BOLT_NAME, context.getTopologyStorageEndpoint(BaseRichBolt.class, Optional.of(bucket))), (acc, v) -> acc.localOrShuffleGrouping(v._2()), (acc1, acc2) -> acc1 // (not possible in practice) ); return Tuples._2T(builder.createTopology(), Collections.emptyMap()); }
From source file:org.diorite.impl.entity.attrib.AttributePropertyImpl.java
public AttributePropertyImpl(final AttributeType type, final Collection<AttributeModifier> modifiers) { this.type = type; this.value = type.getDefaultValue(); if (modifiers != null) { this.modifiers = new ConcurrentHashMap<>(modifiers.size() + 1, 0.3f, 8); modifiers.forEach(mod -> this.modifiers.put(mod.getUuid(), mod)); } else {// w w w . j a va2s . c o m this.modifiers = new ConcurrentHashMap<>(5, 0.3f, 8); } this.recalculateFinalValue(); }
From source file:com.ebay.logstorm.server.services.impl.PipelineExecutionServiceImpl.java
@Transactional private void checkInitExecutionContext(PipelineEntity pipeline) { Preconditions.checkNotNull(pipeline, "pipeline is null: " + pipeline); Preconditions.checkNotNull(pipeline.getCluster(), "cluster is null: " + pipeline); Preconditions.checkNotNull(pipeline.getCluster().getPlatformInstance(), "platform instance is null: " + pipeline); if (pipeline.getInstances() != null && pipeline.getInstances().size() > 0) { Collection<PipelineExecutionEntity> instances = pipeline.getInstances(); pipeline.setInstances(Collections.emptyList()); entityService.updatePipeline(pipeline); instances.forEach(this::removeExecutionEntity); }//from w w w . j a v a2 s .co m if (pipeline.getInstances() == null || pipeline.getInstances().size() == 0) { LOG.info("{} has not been deployed yet, deploying now", pipeline); List<PipelineExecutionEntity> executors = new ArrayList<>(pipeline.getParallelism()); for (int i = 0; i < pipeline.getParallelism(); i++) { PipelineExecutionEntity instance = new PipelineExecutionEntity(); instance.setNumber(i); instance.setName(String.format("%s_%s", pipeline.getName(), instance.getNumber())); instance.setPipeline(pipeline); executors.add(this.createExecutionEntity(instance)); } pipeline.setInstances(executors); entityService.updatePipeline(pipeline); LOG.info("Initialized {} instances for pipeline {}", executors.size(), pipeline); } }
From source file:dk.dma.ais.abnormal.analyzer.analysis.CloseEncounterAnalysis.java
protected void performAnalysis() { LOG.debug("Starting " + getAnalysisName()); final long systemTimeMillisBeforeAnalysis = System.currentTimeMillis(); Collection<Track> tracks = getTrackingService().getTracks(); tracks.forEach(t -> analyseCloseEncounters(tracks, t)); final long systemTimeMillisAfterAnalysis = System.currentTimeMillis(); statisticsService.incAnalysisStatistics(getAnalysisName(), "Analyses performed"); LOG.debug(getAnalysisName() + " of " + tracks.size() + " tracks completed in " + (systemTimeMillisAfterAnalysis - systemTimeMillisBeforeAnalysis) + " msecs."); }
From source file:com.example.app.model.DemoUserProfileDAO.java
/** * Delete the specified user profiles.//w w w .jav a 2 s . c o m * * @param userProfiles the user profiles to delete. */ public void deleteUserProfiles(Collection<? extends DemoUserProfile> userProfiles) { beginTransaction(); boolean success = false; try { final Session session = getSession(); userProfiles.forEach(session::delete); success = true; } finally { if (success) commitTransaction(); else recoverableRollbackTransaction(); } }
From source file:com.netflix.spinnaker.fiat.roles.github.GithubTeamsUserRolesProvider.java
@Override public Map<String, Collection<Role>> multiLoadRoles(Collection<String> userEmails) { if (userEmails == null || userEmails.isEmpty()) { return new HashMap<>(); }/*from w w w.j av a2 s.co m*/ val emailGroupsMap = new HashMap<String, Collection<Role>>(); userEmails.forEach(email -> emailGroupsMap.put(email, loadRoles(email))); return emailGroupsMap; }