Example usage for java.util Collection forEach

List of usage examples for java.util Collection forEach

Introduction

In this page you can find the example usage for java.util Collection forEach.

Prototype

default void forEach(Consumer<? super T> action) 

Source Link

Document

Performs the given action for each element of the Iterable until all elements have been processed or the action throws an exception.

Usage

From source file:de.blizzy.rust.lootconfig.LootConfigDump.java

private void run() throws IOException {
    LootConfig config = loadConfig(configFile);

    Table<LootContainer, Category, Multiset<Float>> dropChances = HashBasedTable.create();

    Collection<LootContainer> lootContainers = config.LootContainers.values();
    config.Categories.values().stream().filter(Category::hasItemsOrBlueprints).forEach(category -> {
        lootContainers.forEach(lootContainer -> {
            Multiset<Float> categoryInContainerDropChances = getItemCategoryDropChances(category,
                    lootContainer);/* ww w. ja va 2  s  . com*/
            if (!categoryInContainerDropChances.isEmpty()) {
                dropChances.put(lootContainer, category, categoryInContainerDropChances);
            }
        });
    });

    dropChances.rowKeySet().stream()
            .filter(lootContainer -> SHOW_DMLOOT || !lootContainer.name.contains("dmloot"))
            .sorted((lootContainer1, lootContainer2) -> Collator.getInstance().compare(lootContainer1.name,
                    lootContainer2.name))
            .forEach(lootContainer -> {
                System.out.printf("%s (blueprint fragments: %s)", lootContainer,
                        lootContainer.DistributeFragments ? "yes" : "no").println();
                Map<Category, Multiset<Float>> lootContainerDropChances = dropChances.row(lootContainer);
                AtomicDouble lootContainerDropChancesSum = new AtomicDouble();
                AtomicInteger categoriesCount = new AtomicInteger();
                lootContainerDropChances.entrySet().stream().sorted(this::compareByChances).limit(7)
                        .forEach(categoryDropChancesEntry -> {
                            Category category = categoryDropChancesEntry.getKey();
                            Multiset<Float> categoryDropChances = categoryDropChancesEntry.getValue();
                            float categoryDropChancesSum = sum(categoryDropChances);
                            lootContainerDropChancesSum.addAndGet(categoryDropChancesSum);
                            System.out.printf("  %s %s%s%s", formatPercent(categoryDropChancesSum), category,
                                    (category.Items.size() > 0) ? " (" + formatItems(category) + ")" : "",
                                    (category.Blueprints.size() > 0) ? " [" + formatBlueprints(category) + "]"
                                            : "")
                                    .println();
                            categoriesCount.incrementAndGet();
                        });
                if (categoriesCount.get() < lootContainerDropChances.size()) {
                    System.out.printf("  %s other (%d)",
                            formatPercent(1f - (float) lootContainerDropChancesSum.get()),
                            lootContainerDropChances.size() - categoriesCount.get()).println();
                }
            });
}

From source file:org.apache.samza.operators.impl.OperatorImplGraph.java

/**
 * Traverses the DAG of {@link OperatorSpec}s starting from the provided {@link OperatorSpec},
 * creates the corresponding DAG of {@link OperatorImpl}s, and returns the root {@link OperatorImpl} node.
 *
 * @param prevOperatorSpec  the parent of the current {@code operatorSpec} in the traversal
 * @param operatorSpec  the operatorSpec to create the {@link OperatorImpl} for
 * @param config  the {@link Config} required to instantiate operators
 * @param context  the {@link TaskContext} required to instantiate operators
 * @return  the operator implementation for the operatorSpec
 *///  ww w  . j a  v  a 2 s .c  om
OperatorImpl createAndRegisterOperatorImpl(OperatorSpec prevOperatorSpec, OperatorSpec operatorSpec,
        Config config, TaskContext context) {
    if (!operatorImpls.containsKey(operatorSpec) || operatorSpec instanceof JoinOperatorSpec) {
        // Either this is the first time we've seen this operatorSpec, or this is a join operator spec
        // and we need to create 2 partial join operator impls for it. Initialize and register the sub-DAG.
        OperatorImpl operatorImpl = createOperatorImpl(prevOperatorSpec, operatorSpec, config, context);
        operatorImpl.init(config, context);
        operatorImpls.put(operatorImpl.getOperatorName(), operatorImpl);

        Collection<OperatorSpec> registeredSpecs = operatorSpec.getRegisteredOperatorSpecs();
        registeredSpecs.forEach(registeredSpec -> {
            OperatorImpl nextImpl = createAndRegisterOperatorImpl(operatorSpec, registeredSpec, config,
                    context);
            operatorImpl.registerNextOperator(nextImpl);
        });
        return operatorImpl;
    } else {
        // the implementation corresponding to operatorSpec has already been instantiated
        // and registered, so we do not need to traverse the DAG further.
        return operatorImpls.get(operatorSpec);
    }
}

From source file:com.github.tddts.jet.service.impl.SearchOperationsImpl.java

/**
 * Loads orders for given set of regions.
 *//*w  w  w.j  ava 2 s. c  o m*/
@Override
@SendSearchEvents(before = LOADING_ORDERS)
public void loadOrders() {
    Collection<Integer> regionIds = getRegionIds(searchParams.getRegions());
    regionIds.forEach(region -> paginationExecutor.add(createPaginationForRegion(region)));
    paginationExecutor.execute();
}

From source file:net.gtaun.shoebill.common.dialog.ListDialog.java

protected ListDialog(Player player, EventManager eventManager) {
    super(DialogStyle.LIST, player, eventManager);
    items = new ArrayList<ListDialogItem>() {
        private static final long serialVersionUID = 2260194681967627384L;

        @Override//  ww w  .jav  a  2 s.co  m
        public void add(int index, ListDialogItem e) {
            e.currentDialog = ListDialog.this;
            super.add(index, e);
        }

        @Override
        public boolean add(ListDialogItem e) {
            e.currentDialog = ListDialog.this;
            return super.add(e);
        }

        @Override
        public ListDialogItem set(int index, ListDialogItem e) {
            e.currentDialog = ListDialog.this;
            return super.set(index, e);
        }

        @Override
        public boolean addAll(Collection<? extends ListDialogItem> c) {
            c.forEach((e) -> e.currentDialog = ListDialog.this);
            return super.addAll(c);
        }

        @Override
        public boolean addAll(int index, Collection<? extends ListDialogItem> c) {
            c.forEach((e) -> e.currentDialog = ListDialog.this);
            return super.addAll(index, c);
        }
    };
    displayedItems = new ArrayList<>();
}

From source file:de.codesourcery.spring.contextrewrite.RewriteConfig.java

/**
 * Add rewriting rules.//from   ww  w.  ja va2 s  .c  o  m
 * 
 * @param rules
 * @throws IllegalStateException if any of the rules has an ID that clashes with another rule that has already been added to this instance. Anonymous rules (rules without an ID) can
 * never clash.
 */
public void addRules(Collection<Rule> rules) throws IllegalStateException {

    Validate.notNull(rules, "rule must not be NULL");
    rules.forEach(this::addRule);
}

From source file:org.openmrs.CohortTest.java

@Test
public void intersect_shouldContainVoidedAndExpiredMemberships() throws Exception {
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    Date startDate = dateFormat.parse("2017-01-01 00:00:00");
    Date endDate = dateFormat.parse("2017-02-01 00:00:00");

    Cohort cohortOne = new Cohort(3);
    CohortMembership membershipOne = new CohortMembership(7, startDate);
    membershipOne.setVoided(true);/*from www.j  a v a2 s.c o m*/
    membershipOne.setEndDate(endDate);
    cohortOne.addMembership(membershipOne);

    Cohort cohortTwo = new Cohort(4);
    CohortMembership membershipTwo = new CohortMembership(8, startDate);
    membershipTwo.setVoided(true);
    membershipTwo.setEndDate(endDate);
    cohortTwo.addMembership(membershipOne);
    cohortTwo.addMembership(membershipTwo);

    Cohort cohortIntersect = Cohort.intersect(cohortOne, cohortTwo);
    Collection<CohortMembership> intersectOfMemberships = cohortIntersect.getMemberships();
    assertTrue(intersectOfMemberships.stream().anyMatch(m -> m.getVoided() || m.getEndDate() != null));
    intersectOfMemberships.forEach(m -> {
        assertTrue(m.getPatientId().equals(7));
        assertTrue(m.getVoided() && m.getEndDate() != null);
    });
}

From source file:com.watchrabbit.crawler.executor.service.CrawlExecutorServiceImpl.java

private void enableSession(RemoteWebDriver driver, CrawlForm form, Collection<Cookie> session) {
    driver.get(form.getUrl());/*from ww  w  . j a  v a 2  s . co  m*/
    loaderService.waitFor(driver);
    if (!session.isEmpty()) {
        driver.manage().deleteAllCookies();
        session.forEach(driver.manage()::addCookie);

        driver.get(form.getUrl());
        loaderService.waitFor(driver);
    }
    if (StringUtils.isNotEmpty(form.getKeyword())) {
        Optional<SearchForm> searchFormOptional = findSearchInput(driver);
        searchFormOptional.ifPresent(searchForm -> {
            searchForm.input.sendKeys(form.getKeyword());
            loaderService.waitFor(driver);
            searchForm.submit.click();
            loaderService.waitFor(driver);
        });

    }
}

From source file:io.apicurio.hub.api.bitbucket.BitbucketSourceConnectorTest.java

@Test
@Ignore//from  w ww .  j a v a2s.  co  m
public void testGetTeams() throws SourceConnectorException, BitbucketException {
    Collection<BitbucketTeam> teams = service.getTeams();
    Assert.assertNotNull(teams);
    Assert.assertFalse(teams.isEmpty());
    teams.forEach(team -> {
        System.out.println("Found team: " + team.getDisplayName() + " -- " + team.getUsername());
    });
}

From source file:org.eclipse.hawkbit.repository.jpa.JpaEntityFactory.java

@Override
public ActionStatus generateActionStatus(final Action action, final Status status, final Long occurredAt,
        final Collection<String> messages) {

    final ActionStatus result = new JpaActionStatus((JpaAction) action, status, occurredAt, null);
    messages.forEach(result::addMessage);

    return result;
}

From source file:io.neba.core.resourcemodels.registration.ModelRegistrar.java

private void registerModels(Bundle bundle, ResourceModelFactory factory) {
    final Collection<ResourceModelFactory.ModelDefinition> modelDefinitions = factory.getModelDefinitions();

    logger.info("Registering {} resource models from bundle: " + displayNameOf(bundle) + " ...",
            modelDefinitions.size());//from  w ww. java  2  s.  c o m
    modelDefinitions.forEach(d -> {
        final OsgiModelSource<Object> source = new OsgiModelSource<>(d, factory, bundle);
        this.resourceModelMetaDataRegistrar.register(source);
        this.registry.add(d.getResourceModel().types(), source);
        logger.debug("Registered model {} as a model for the resource types {}.", d.getName(),
                join(d.getResourceModel().types(), ","));
    });

    this.resourceToModelAdapterUpdater.refresh();
}