Example usage for java.lang Iterable forEach

List of usage examples for java.lang Iterable forEach

Introduction

In this page you can find the example usage for java.lang Iterable 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:org.diorite.impl.entity.tracker.BaseTracker.java

public void updatePlayers(final Iterable<IPlayer> players) {
    players.forEach(this::updatePlayer);
}

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

private List<JpaTargetTag> createTargetsWithTags() {
    final List<Target> targets = testdataFactory.createTargets(20);
    final Iterable<TargetTag> tags = testdataFactory.createTargetTags(20, "");

    tags.forEach(tag -> toggleTagAssignment(targets, tag));

    return targetTagRepository.findAll();
}

From source file:org.egov.wtms.service.es.WaterChargeSurveyDashboardService.java

private List<WaterChargeSurveyDashboardResponse> setSurveyResponse(String aggregationField,
        SearchResponse response, WaterChargeSurveyDashboardRequest request) {

    Terms ulbTerms = response.getAggregations().get(AGGREGATION_WISE);
    List<CityIndex> city = new ArrayList<>(0);
    if (isNotBlank(request.getUlbCode())
            && (ELECTION_WARD.equals(aggregationField) || FUNCTIONARY_NAME.equals(aggregationField))) {
        city.add(cityIndexService.findByCitycode(request.getUlbCode()));
    } else {/*from  w  w w.  j  av a 2s.c  om*/
        Iterable<CityIndex> cities = cityIndexService.findAll();
        cities.forEach(city::add);
    }

    List<WaterChargeSurveyDashboardResponse> responseList = new ArrayList<>();
    for (Bucket bucket : ulbTerms.getBuckets()) {
        WaterChargeSurveyDashboardResponse surveyResponse = new WaterChargeSurveyDashboardResponse();
        getAggregationNames(aggregationField, surveyResponse, city, bucket);
        surveyResponse.setApplicaitonReceived(getApplicationReceivedCount(bucket));
        surveyResponse.setSanctionOrderIssued(getSanctionOrderIssueCount(bucket));
        surveyResponse.setConnectionExecuted(getConnectionExecutedCount(bucket));
        double applicationReceived = surveyResponse.getApplicaitonReceived().getTotalConnection();
        double totalSanctionIssued = surveyResponse.getSanctionOrderIssued().getTotalConnection();
        surveyResponse.setPendingSanction(applicationReceived - totalSanctionIssued);
        surveyResponse.setPendingExecution(
                totalSanctionIssued - surveyResponse.getConnectionExecuted().getTotalConnection());
        responseList.add(surveyResponse);
    }
    return responseList;
}

From source file:org.jboss.set.aphrodite.issue.trackers.jira.IssueWrapper.java

private List<JiraChangelogItem> createJiraChangelogItems(Iterable<ChangelogItem> changelogItems) {
    List<JiraChangelogItem> jiraChangelogItems = new ArrayList<>();
    if (changelogItems != null)
        changelogItems.forEach(item -> jiraChangelogItems.add(new JiraChangelogItem(item.getField(),
                item.getFrom(), item.getFromString(), item.getTo(), item.getToString())));
    return jiraChangelogItems;
}

From source file:org.onosproject.drivers.juniper.FlowRuleJuniperImpl.java

@Override
public Collection<FlowEntry> getFlowEntries() {

    DeviceId devId = checkNotNull(this.data().deviceId());
    NetconfController controller = checkNotNull(handler().get(NetconfController.class));
    NetconfSession session = controller.getDevicesMap().get(devId).getSession();
    if (session == null) {
        log.warn("Device {} is not registered in netconf", devId);
        return Collections.EMPTY_LIST;
    }//from   w  w  w .ja v  a2  s . co  m

    //Installed static routes
    String reply;
    try {
        reply = session.get(routingTableBuilder());
    } catch (NetconfException e) {
        throw new IllegalStateException(new NetconfException("Failed to retrieve configuration.", e));
    }
    Collection<StaticRoute> devicesStaticRoutes = JuniperUtils.parseRoutingTable(loadXmlString(reply));

    //Expected FlowEntries installed
    FlowRuleService flowRuleService = this.handler().get(FlowRuleService.class);
    Iterable<FlowEntry> flowEntries = flowRuleService.getFlowEntries(devId);

    Collection<FlowEntry> installedRules = new HashSet<>();
    flowEntries.forEach(flowEntry -> {
        Optional<IPCriterion> ipCriterion = getIpCriterion(flowEntry);
        if (!ipCriterion.isPresent()) {
            return;
        }

        Optional<OutputInstruction> output = getOutput(flowEntry);
        if (!output.isPresent()) {
            return;
        }
        //convert FlowRule into static route
        getStaticRoute(devId, ipCriterion.get(), output.get(), flowEntry.priority()).ifPresent(staticRoute -> {
            //Two type of FlowRules:
            //1. FlowRules to forward to a remote subnet: they are translated into static route
            // configuration. So a removal request will be processed.
            //2. FlowRules to forward on a subnet directly attached to the router (Generally speaking called local):
            // those routes do not require any configuration because the router is already able to forward on
            // directly attached subnet. In this case, when the driver receive the request to remove,
            // it will report as removed.

            if (staticRoute.isLocalRoute()) {
                //if the FlowRule is in PENDING_REMOVE or REMOVED, it is not reported.
                if (flowEntry.state() == PENDING_REMOVE || flowEntry.state() == REMOVED) {
                    devicesStaticRoutes.remove(staticRoute);
                } else {
                    //FlowRule is reported installed
                    installedRules.add(flowEntry);
                    devicesStaticRoutes.remove(staticRoute);
                }

            } else {
                //if the route is found in the device, the FlowRule is reported installed.
                if (devicesStaticRoutes.contains(staticRoute)) {
                    installedRules.add(flowEntry);
                    devicesStaticRoutes.remove(staticRoute);
                }
            }
        });
    });

    if (!devicesStaticRoutes.isEmpty()) {
        log.info("Found static routes on device {} not installed by ONOS: {}", devId, devicesStaticRoutes);
        //            FIXME: enable configuration to purge already installed flows.
        //            It cannot be allowed by default because it may remove needed management routes
        //            log.warn("Removing from device {} the FlowEntries not expected {}", deviceId, devicesStaticRoutes);
        //            devicesStaticRoutes.forEach(staticRoute -> editRoute(session, REMOVE, staticRoute));
    }
    return installedRules;
}

From source file:org.onosproject.store.intent.impl.GossipIntentStore.java

@Override
public void batchWrite(Iterable<IntentData> updates) {
    updates.forEach(this::write);
}

From source file:org.springframework.cloud.gcp.data.spanner.core.SpannerTemplate.java

private StringBuilder logColumns(String tableName, KeySet keys, Iterable<String> columns) {
    StringBuilder logSb = new StringBuilder(
            "Executing read on table " + tableName + " with keys: " + keys + " and columns: ");
    StringJoiner sj = new StringJoiner(",");
    columns.forEach((col) -> sj.add(col));
    logSb.append(sj.toString());/* w  w w .j  a v a  2 s.c om*/
    return logSb;
}

From source file:org.talend.dataprep.folder.store.AbstractFolderTest.java

/**
 * this test create a hierarchy then delete part of it doing some assert on list, size then delete part of it
 * asserting the deletion//from   ww  w  .  jav a 2 s  .c  om
 */
@Test
public void create_two_children_little_children_then_remove() throws Exception {

    // - foo
    // - beer
    // +- bar

    long sizeBefore = getFolderRepository().size();
    Folder foo = getFolderRepository().addFolder(homeFolderId, "foo");
    Folder beer = getFolderRepository().addFolder(homeFolderId, "beer");
    Folder bar = getFolderRepository().addFolder(beer.getId(), "bar");

    Iterable<Folder> iterable = getFolderRepository().children(homeFolderId);
    List<Folder> folders = new ArrayList<>();
    iterable.forEach(folders::add);

    assertThat(folders).isNotNull().isNotEmpty().hasSize(2);

    // testing child of /bar

    iterable = getFolderRepository().children(beer.getId());
    folders = Lists.newArrayList(iterable);

    assertThat(folders).isNotNull().isNotEmpty().hasSize(1);
    assertThat(StringUtils.strip(folders.get(0).getPath(), "/")).isEqualToIgnoringCase("beer/bar");
    assertThat(folders.get(0).getName()).isEqualToIgnoringCase("bar");

    getFolderRepository().removeFolder(bar.getId());

    // testing child of /beer after removing the first child
    iterable = getFolderRepository().children(beer.getId());
    folders = Lists.newArrayList(iterable);

    assertThat(folders).isNotNull().isEmpty();

    // testing the whole size

    long sizeAfter = getFolderRepository().size();

    assertThat(sizeAfter).isEqualTo(2);
    getFolderRepository().removeFolder(foo.getId());
    getFolderRepository().removeFolder(beer.getId());

    sizeAfter = getFolderRepository().size();
    assertThat(sizeAfter).isEqualTo(sizeBefore);

    iterable = getFolderRepository().children(homeFolderId);
    folders = Lists.newArrayList(iterable);

    assertThat(folders).isNotNull().isEmpty();

}

From source file:org.talend.dataprep.folder.store.AbstractFolderTest.java

/**
 *
 * This test create one child under root assert size, child list then create three folder entries then delete
 *///from w w  w . ja v a  2s  .c o m
@Test
public void create_child_with_two_entries_then_remove() throws Exception {

    long sizeBefore = getFolderRepository().size();
    Folder foo = getFolderRepository().addFolder(homeFolderId, "foo");
    Folder foobeer = getFolderRepository().addFolder(foo.getId(), "beer");
    long sizeAfter = getFolderRepository().size();
    assertThat(sizeAfter).isEqualTo(sizeBefore + 2);

    assertChildrenSize(homeFolderId, 1);

    FolderEntry beerEntry = new FolderEntry(DATASET, "littlecreatures");
    FolderEntry wineEntry = new FolderEntry(DATASET, "bordeaux");

    getFolderRepository().addFolderEntry(beerEntry, foo.getId());
    getFolderRepository().addFolderEntry(wineEntry, foo.getId());

    wineEntry = new FolderEntry(DATASET, "bordeaux");
    getFolderRepository().addFolderEntry(wineEntry, foobeer.getId());

    Iterable<FolderEntry> folderEntries = getFolderRepository().entries(foo.getId(), DATASET);
    List<FolderEntry> entries = Lists.newArrayList(folderEntries);

    assertThat(entries).isNotNull().isNotEmpty().hasSize(2);

    folderEntries = getFolderRepository().findFolderEntries("bordeaux", DATASET);
    entries.clear();
    folderEntries.forEach(entries::add);
    assertThat(entries).isNotNull().isNotEmpty().hasSize(2);

    folderEntries = getFolderRepository().findFolderEntries("littlecreatures", DATASET);
    entries.clear();
    folderEntries.forEach(entries::add);
    assertThat(entries).isNotNull().isNotEmpty().hasSize(1);

    getFolderRepository().removeFolderEntry(foo.getId(), "littlecreatures", DATASET);

    getFolderRepository().removeFolderEntry(foo.getId(), "bordeaux", DATASET);

    getFolderRepository().removeFolderEntry(foobeer.getId(), "bordeaux", DATASET);

    folderEntries = getFolderRepository().entries(foo.getId(), DATASET);
    entries = Lists.newArrayList(folderEntries);

    assertThat(entries).isNotNull().isEmpty();

    getFolderRepository().removeFolder(foo.getId());

    sizeAfter = getFolderRepository().size();

    assertThat(sizeAfter).isEqualTo(sizeBefore);

    assertChildrenSize(homeFolderId, 0);

}

From source file:org.talend.dataprep.folder.store.AbstractFolderTest.java

/**
 *
 * This test create one child under root assert size, child list then create three folder entries then delete
 * expect exception/*from w  w w .j  av  a2s  .c o  m*/
 */
@Test
public void create_child_with_two_entries_then_remove_expect_exception() throws Exception {

    long sizeBefore = getFolderRepository().size();
    Folder foo = getFolderRepository().addFolder(homeFolderId, "foo");
    Folder foobeer = getFolderRepository().addFolder(foo.getId(), "/beer");
    long sizeAfter = getFolderRepository().size();

    assertThat(sizeAfter).isEqualTo(sizeBefore + 2);

    assertChildrenSize(homeFolderId, 1);

    FolderEntry beerEntry = new FolderEntry(DATASET, "littlecreatures");
    FolderEntry wineEntry = new FolderEntry(DATASET, "bordeaux");

    getFolderRepository().addFolderEntry(beerEntry, foo.getId());
    getFolderRepository().addFolderEntry(wineEntry, foo.getId());

    wineEntry = new FolderEntry(DATASET, "bordeaux");

    getFolderRepository().addFolderEntry(wineEntry, foobeer.getId());

    Iterable<FolderEntry> folderEntries = getFolderRepository().entries(foo.getId(), DATASET);
    List<FolderEntry> entries = Lists.newArrayList(folderEntries);

    assertThat(entries).isNotNull().isNotEmpty().hasSize(2);

    folderEntries = getFolderRepository().findFolderEntries("bordeaux", DATASET);
    entries.clear();
    folderEntries.forEach(entries::add);
    assertThat(entries).isNotNull().isNotEmpty().hasSize(2);

    folderEntries = getFolderRepository().findFolderEntries("littlecreatures", DATASET);
    entries.clear();
    folderEntries.forEach(entries::add);
    assertThat(entries).isNotNull().isNotEmpty().hasSize(1);

    folderEntries = getFolderRepository().entries(foo.getId(), DATASET);
    entries = Lists.newArrayList(folderEntries);

    assertThat(entries).isNotNull().isNotEmpty().hasSize(2);

    try {
        getFolderRepository().removeFolder(foo.getId());
        fail("Should throw exception because folder is not empty.");
    } catch (TDPException e) {
        assertEquals(FolderErrorCodes.FOLDER_NOT_EMPTY, e.getCode());
    }

}