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:me.dwtj.java.compiler.utils.CompilationTaskBuilder.java

/**
 * A helper method for {@link #addOption(String)}
 *
 * @param  opts The sequence of options to be added/appended.
 * @return The receiver instance (i.e. {@code this}).
 *//*from  w ww  .ja v a 2 s  .c  o m*/
public CompilationTaskBuilder addAllOptions(Iterable<String> opts) {
    opts.forEach(this::addOption);
    return this;
}

From source file:me.dwtj.java.compiler.utils.CompilationTaskBuilder.java

/**
 * A helper method for {@link #addClass(String)}
 *
 * @param  classes The fully qualified names to be found and added as compilation units.
 * @return The receiver instance (i.e. {@code this}).
 *//*  www  .  j  av  a  2s.  c om*/
public CompilationTaskBuilder addAllClasses(Iterable<String> classes) {
    classes.forEach(this::addClass);
    return this;
}

From source file:me.dwtj.java.compiler.utils.CompilationTaskBuilder.java

/**
 * All of the given compilation units will be compiled during the compilation task.
 *
 * <p>By default, a compilation task has no compilation units.
 *
 * @param  units The compilation units to be added.
 * @return The receiver instance (i.e. {@code this}).
 *//*from   w ww.j  a v a 2s  .co m*/
public CompilationTaskBuilder addAllCompilationUnits(Iterable<JavaFileObject> units) {
    assert units != null;
    units.forEach(this::addCompilationUnit);
    return this;
}

From source file:gist.ac.netcs.fwdtraffic.FwdTrafficComponent.java

private JsonNode json(IntentService service, Iterable<Intent> intents) {
    ObjectMapper mapper = new ObjectMapper();
    ArrayNode result = mapper.createArrayNode();

    intents.forEach(intent -> result.add(jsonForEntity(intent, Intent.class)));
    return result;
}

From source file:at.ac.tuwien.qse.sepm.gui.controller.impl.OrganizerImpl.java

private <T> void refreshFilter(Aggregator<T> aggregator, FilterGroup<T> filter, Iterable<T> values,
        String defaultLabel, Function<T, String> converter) {
    Platform.runLater(() -> {/*from www  .  j a  v  a 2  s .c  o  m*/
        // NOTE: Remember the values that were excluded before the refresh and exclude them.
        // That way the filter stays the same and new values are included automatically.
        Set<T> excluded = filter.getExcludedValues();
        filter.getItems().clear();
        values.forEach(p -> {
            FilterControl<T> item = new FilterControl<>();
            item.setValue(p);
            item.setConverter(val -> {
                if (val == null) {
                    return defaultLabel;
                }
                return converter.apply(val);
            });
            item.setIncluded(!excluded.contains(p));
            item.setCount(aggregator.getCount(p));
            filter.getItems().add(item);
        });
    });
}

From source file:at.ac.tuwien.qse.sepm.gui.controller.impl.OrganizerImpl.java

private <T> void refreshFilterExcluded(Aggregator<T> aggregator, FilterGroup<T> filter, Iterable<T> values,
        String defaultLabel, Function<T, String> converter) {
    Platform.runLater(() -> {/*from  ww w.j a va 2  s . c o  m*/
        // NOTE: Remember the values that were excluded before the refresh and exclude them.
        // That way the filter stays the same and new values are included automatically.
        Set<T> included = filter.getIncludedValues();
        filter.getItems().clear();
        values.forEach(p -> {
            FilterControl<T> item = new FilterControl<>();
            item.setValue(p);
            item.setConverter(val -> {
                if (val == null) {
                    return defaultLabel;
                }
                return converter.apply(val);
            });
            item.setIncluded(included.contains(p));
            item.setCount(aggregator.getCount(p));
            filter.getItems().add(item);
        });
    });
}

From source file:org.talend.dataprep.preparation.service.PreparationService.java

/**
 * Check if the name is available in the given folderId.
 *
 * @param folderId where to look for the name.
 * @param name the wanted preparation name.
 * @throws TDPException Preparation name already used (409) if there's already a preparation with this name in the
 * folderId./* w w w .  jav a  2  s.  c  o  m*/
 */
private void checkIfPreparationNameIsAvailable(String folderId, String name) {

    // make sure the preparation does not already exist in the target folderId
    final Iterable<FolderEntry> entries = folderRepository.entries(folderId, PREPARATION);
    entries.forEach(folderEntry -> {
        Preparation preparation = preparationRepository.get(folderEntry.getContentId(), Preparation.class);
        if (preparation != null && StringUtils.equals(name, preparation.getName())) {
            final ExceptionContext context = build() //
                    .put("id", folderEntry.getContentId()) //
                    .put("folderId", folderId) //
                    .put("name", name);
            throw new TDPException(PREPARATION_NAME_ALREADY_USED, context, true);
        }
    });
}

From source file:com.bouncestorage.swiftproxy.v1.ObjectResource.java

private Response getSloObject(BlobStore blobStore, Blob blob, GetOptions options,
        List<Pair<Long, Long>> ranges) {
    try {//from w  w w  .  j a v a 2  s  . c o  m
        Iterable<ManifestEntry> entries = Arrays.asList(readSLOManifest(blob.getPayload().openStream()));
        Pair<Long, String> sizeAndEtag = getManifestTotalSizeAndETag(entries);

        logger.debug("getting SLO object: {}", sizeAndEtag);
        entries.forEach(e -> logger.debug("sub-object: {}", e));

        InputStream combined = new ManifestObjectInputStream(blobStore, entries);
        long size = sizeAndEtag.getFirst();
        if (ranges != null) {
            combined = new HttpRangeInputStream(combined, sizeAndEtag.getFirst(), ranges);
            size = getTotalRangesLength(ranges, size);
            logger.debug("range request for {} bytes", size);
        }
        return addObjectHeaders(Response.ok(combined), blob.getMetadata(),
                Optional.of(overwriteSizeAndETag(size, sizeAndEtag.getSecond()))).build();
    } catch (IOException e) {
        throw propagate(e);
    }
}

From source file:org.obiba.mica.access.service.DataAccessRequestService.java

public DataAccessRequest save(@NotNull DataAccessRequest request) {
    DataAccessRequest saved = request;//from w  w  w. j a v  a2s .c  o m
    DataAccessRequest.Status from = null;
    Iterable<Attachment> attachmentsToDelete = null;
    Iterable<Attachment> attachmentsToSave = null;

    if (request.isNew()) {
        setAndLogStatus(saved, DataAccessRequest.Status.OPENED);
        saved.setId(generateId());
        attachmentsToSave = saved.getAttachments();
    } else {
        saved = dataAccessRequestRepository.findOne(request.getId());
        if (saved != null) {
            attachmentsToDelete = Sets.difference(Sets.newHashSet(saved.getAttachments()),
                    Sets.newHashSet(request.getAttachments()));
            attachmentsToSave = Sets.difference(Sets.newHashSet(request.getAttachments()),
                    Sets.newHashSet(saved.getAttachments()));

            from = saved.getStatus();
            // validate the status
            dataAccessRequestUtilService.checkStatusTransition(saved, request.getStatus());
            saved.setStatus(request.getStatus());
            if (request.hasStatusChangeHistory())
                saved.setStatusChangeHistory(request.getStatusChangeHistory());
            // merge beans
            BeanUtils.copyProperties(request, saved, "id", "version", "createdBy", "createdDate",
                    "lastModifiedBy", "lastModifiedDate", "statusChangeHistory");
        } else {
            saved = request;
            setAndLogStatus(saved, DataAccessRequest.Status.OPENED);
        }
    }

    schemaFormContentFileService.save(saved, dataAccessRequestRepository.findOne(request.getId()),
            String.format("/data-access-request/%s", saved.getId()));

    if (attachmentsToSave != null)
        attachmentsToSave.forEach(a -> {
            fileStoreService.save(a.getId());
            a.setJustUploaded(false);
            attachmentRepository.save(a);
        });

    saved.setLastModifiedDate(DateTime.now());
    dataAccessRequestRepository.saveWithReferences(saved);

    if (attachmentsToDelete != null)
        attachmentsToDelete.forEach(a -> fileStoreService.delete(a.getId()));

    eventBus.post(new DataAccessRequestUpdatedEvent(saved));
    sendNotificationEmails(saved, from);
    return saved;
}