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:com.github.drbookings.ui.controller.UpcomingController.java

private void addEvents(final LocalDate date, final Collection<BookingEntry> upcomingBookings,
        final Collection<CleaningEntry> upcomingCleanings) {
    final VBox box = new VBox(4);
    if (date.equals(LocalDate.now())) {
        box.getStyleClass().add("first-day");
    } else if (date.equals(LocalDate.now().plusDays(1))) {
        box.getStyleClass().add("second-day");
    } else if (date.isAfter(LocalDate.now().plusDays(1))) {
        box.getStyleClass().add("later");
    }//from w ww . j a va  2  s .  c  o m

    if (upcomingBookings.stream().filter(b -> b.isCheckIn() || b.isCheckOut()).collect(Collectors.toList())
            .isEmpty() && upcomingCleanings.isEmpty()) {
        final Text t0 = new Text(getDateString(date));
        final Text t1 = new Text(" there are no events.");
        t0.getStyleClass().add("emphasis");
        final TextFlow tf = new TextFlow();
        tf.getChildren().addAll(t0, t1);
        box.getChildren().addAll(tf);
    } else {
        final List<CheckInOutDetails> checkInNotes = Collections.synchronizedList(new ArrayList<>());
        final List<CheckInOutDetails> checkOutNotes = Collections.synchronizedList(new ArrayList<>());
        upcomingBookings.forEach(b -> {
            if (b.isCheckIn()) {
                String note = "";
                if (b.getElement().getCheckInNote() != null) {
                    note = b.getElement().getCheckInNote();
                }
                if (b.getElement().getSpecialRequestNote() != null) {
                    note = note + "\n" + b.getElement().getSpecialRequestNote();
                }
                checkInNotes.add(new CheckInOutDetails(b.getRoom().getName(),
                        b.getElement().getBookingOrigin().getName(), note));
            } else if (b.isCheckOut()) {
                checkOutNotes.add(new CheckInOutDetails(b.getRoom().getName(),
                        b.getElement().getBookingOrigin().getName(), b.getElement().getCheckOutNote()));
            }
        });
        Collections.sort(checkInNotes);
        Collections.sort(checkOutNotes);
        addGeneralSummary(date, box, checkInNotes);
        addCheckOutSummary(date, box, checkOutNotes);
        addCheckOutNotes(date, box, checkOutNotes);
        addCheckInSummary(date, box, checkInNotes);
        addCheckInNotes(date, box, checkInNotes);
        addCleaningSummary(date, box, upcomingCleanings);
        addCleanings(date, box, upcomingCleanings);
    }

    this.box.getChildren().add(box);

}

From source file:org.diorite.impl.inventory.recipe.craft.ShapedCraftingRecipeImpl.java

@Override
public CraftingRecipeCheckResult isMatching(final GridInventory inventory) {
    final CraftingRecipePattern pattern = this.pattern;
    final int patRows = pattern.getRows(), patCols = pattern.getColumns();
    final int invRows = inventory.getRows(), invCols = inventory.getColumns();
    if ((patRows > invRows) || (patCols > invCols)) // too big pattern for thix eq
    {//from w  ww.  ja v  a 2  s .c  o  m
        return null;
    }
    final Player player = (inventory.getHolder() instanceof Player) ? (Player) inventory.getHolder() : null;
    final int deltaRows = invRows - patRows, deltaCols = invCols - patCols;
    final Short2ObjectMap<ItemStack> onCraft = new Short2ObjectOpenHashMap<>(2, .5F);
    final CraftingGrid items = new CraftingGridImpl(invRows, invCols);
    final Collection<BiConsumer<Player, CraftingGrid>> reps = new ArrayList<>(invCols * invRows);

    int firstPatRow = -1;
    int firstPatCol = -1;
    int firstInvRow = -1;
    int firstInvCol = -1;
    if ((patRows == invRows) && (patCols == invCols)) {
        for (int row = 0; row < patRows; row++) {
            for (int col = 0; col < patCols; col++) {
                final CraftingRecipeItem recipeItem = pattern.getRecipeItem(row, col);
                final ItemStack invItem = inventory.getItem(row, col);
                if (recipeItem == null) {
                    if (invItem != null) {
                        return null;
                    }
                    continue;
                }
                final ItemStack valid = recipeItem.isValid(player, invItem);
                if (valid == null) // fast check first item
                {
                    return null;
                }
                items.setItem(row, col, valid);

                reps.add((p, c) -> {
                    final ItemStack repl = recipeItem.getReplacement(p, c);
                    if (repl != null) {
                        onCraft.put((short) 0, repl);
                    }
                });
            }
        }
        reps.forEach(c -> c.accept(player, items));
        return new CraftingRecipeCheckResultImpl(this,
                (this.resultFunc == null) ? this.result : this.resultFunc.apply(player, items.clone()), items,
                onCraft);
    } // inventory have more columns, so some columns on right or left should be empty

    // we need find first pattern element that isn't null
    patLoop: for (int row = 0; row < patRows; row++) {
        for (int col = 0; col < patCols; col++) {
            if (pattern.getRecipeItem(row, col) != null) {
                firstPatRow = row;
                firstPatCol = col;
                break patLoop;
            }
        }
    }
    // and inventory item
    invLoop: for (int row = 0; row < invRows; row++) {
        for (int col = 0; col < invCols; col++) {
            if (inventory.getItem(row, col) != null) {
                firstInvRow = row;
                firstInvCol = col;
                break invLoop;
            }
        }
    }
    if ((firstPatCol == -1) || (firstInvCol == -1)) // no items in pattern or inventory
    {
        return null;
    }

    final int deltaCol = firstInvCol - firstPatCol;
    final int deltaRow = firstInvRow - firstPatRow;

    if (((deltaCols - deltaCol) < 0) || ((deltaRows - deltaRow) < 0)) // too big pattern.
    {
        return null;
    }

    for (int patRow = 0; patRow < invRows; patRow++) {
        for (int patCol = 0; patCol < invCols; patCol++) {
            final int invRow = patRow + deltaRow;
            final int invCol = patCol + deltaCol;

            final CraftingRecipeItem recipeItem = pattern.getRecipeItem(patRow, patCol);
            final ItemStack invItem = inventory.getItem(invRow, invCol);
            if (recipeItem == null) {
                if (invItem != null) {
                    return null;
                }
                continue;
            }
            final ItemStack valid = recipeItem.isValid(player, invItem);
            if (valid == null) {
                return null;
            }
            items.setItem(invRow, invCol, valid);

            reps.add((p, c) -> {
                final ItemStack repl = recipeItem.getReplacement(p, c);
                if (repl != null) {
                    onCraft.put((short) 0, repl);
                }
            });
        }
    }
    return new CraftingRecipeCheckResultImpl(this,
            (this.resultFunc == null) ? this.result : this.resultFunc.apply(player, items.clone()), items,
            onCraft);
}

From source file:org.ethereum.rpc.Web3Impl.java

@Override
public String[] net_peerList() {
    Collection<Channel> peers = worldManager.getChannelManager().getActivePeers();
    List<String> response = new ArrayList<>();
    peers.forEach(channel -> response.add(channel.toString()));
    return response.stream().toArray(String[]::new);
}

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

/**
 * Creates an action entry into the action repository. In case of existing
 * scheduled actions the scheduled actions gets canceled. A scheduled action
 * is created in-active.//from  w  w  w  .  ja  va2s. c  om
 */
private void createScheduledAction(final Collection<Target> targets, final DistributionSet distributionSet,
        final ActionType actionType, final Long forcedTime, final Rollout rollout,
        final RolloutGroup rolloutGroup) {
    // cancel all current scheduled actions for this target. E.g. an action
    // is already scheduled and a next action is created then cancel the
    // current scheduled action to cancel. E.g. a new scheduled action is
    // created.
    final List<Long> targetIds = targets.stream().map(Target::getId).collect(Collectors.toList());
    actionRepository.switchStatus(Action.Status.CANCELED, targetIds, false, Action.Status.SCHEDULED);
    targets.forEach(target -> {
        final JpaAction action = new JpaAction();
        action.setTarget(target);
        action.setActive(false);
        action.setDistributionSet(distributionSet);
        action.setActionType(actionType);
        action.setForcedTime(forcedTime);
        action.setStatus(Status.SCHEDULED);
        action.setRollout(rollout);
        action.setRolloutGroup(rolloutGroup);
        actionRepository.save(action);
    });
}

From source file:org.libreplan.web.planner.allocation.AdvancedAllocationController.java

void listenTo(Collection<Row> rows) {
    rows.forEach(this::listenTo);
}

From source file:org.apache.flink.client.cli.CliFrontend.java

private <T> void listJobs(ClusterClient<T> clusterClient, boolean showRunning, boolean showScheduled,
        boolean showAll) throws FlinkException {
    Collection<JobStatusMessage> jobDetails;
    try {//from  w w w  .  j  av  a  2  s  . c  o  m
        CompletableFuture<Collection<JobStatusMessage>> jobDetailsFuture = clusterClient.listJobs();

        logAndSysout("Waiting for response...");
        jobDetails = jobDetailsFuture.get();

    } catch (Exception e) {
        Throwable cause = ExceptionUtils.stripExecutionException(e);
        throw new FlinkException("Failed to retrieve job list.", cause);
    }

    LOG.info("Successfully retrieved list of jobs");

    final List<JobStatusMessage> runningJobs = new ArrayList<>();
    final List<JobStatusMessage> scheduledJobs = new ArrayList<>();
    final List<JobStatusMessage> terminatedJobs = new ArrayList<>();
    jobDetails.forEach(details -> {
        if (details.getJobState() == JobStatus.CREATED) {
            scheduledJobs.add(details);
        } else if (!details.getJobState().isGloballyTerminalState()) {
            runningJobs.add(details);
        } else {
            terminatedJobs.add(details);
        }
    });

    if (showRunning || showAll) {
        if (runningJobs.size() == 0) {
            System.out.println("No running jobs.");
        } else {
            System.out.println("------------------ Running/Restarting Jobs -------------------");
            printJobStatusMessages(runningJobs);
            System.out.println("--------------------------------------------------------------");
        }
    }
    if (showScheduled || showAll) {
        if (scheduledJobs.size() == 0) {
            System.out.println("No scheduled jobs.");
        } else {
            System.out.println("----------------------- Scheduled Jobs -----------------------");
            printJobStatusMessages(scheduledJobs);
            System.out.println("--------------------------------------------------------------");
        }
    }
    if (showAll) {
        if (terminatedJobs.size() != 0) {
            System.out.println("---------------------- Terminated Jobs -----------------------");
            printJobStatusMessages(terminatedJobs);
            System.out.println("--------------------------------------------------------------");
        }
    }
}

From source file:edu.stanford.muse.index.Archive.java

public List<MultiDoc> clustersForDocs(Collection<? extends Document> docs, MultiDoc.ClusteringType ct) {
    //TODO: whats the right thing to do when docClusters is null?
    if (docClusters == null || (ct == MultiDoc.ClusteringType.NONE)) {
        List<MultiDoc> new_mDocs = new ArrayList<>();
        MultiDoc md = new MultiDoc(0, "all");
        docs.forEach(md::add);

        new_mDocs.add(md);
        return new_mDocs;
    }/*w  w w  .j ava 2  s.c  om*/

    Map<Document, Integer> map = new LinkedHashMap<>();
    int i = 0;
    for (MultiDoc mdoc : docClusters) {
        for (Document d : mdoc.docs)
            map.put(d, i);
        i++;
    }

    List<MultiDoc> new_mDocs = new ArrayList<>();
    for (MultiDoc md : docClusters)
        new_mDocs.add(null);

    for (Document d : docs) {
        int x = map.get(d);
        MultiDoc new_mDoc = new_mDocs.get(x);
        if (new_mDoc == null) {
            MultiDoc original = docClusters.get(x);
            new_mDoc = new MultiDoc(original.getUniqueId(), original.description);
            new_mDocs.set(x, new_mDoc);
        }
        new_mDoc.add(d);
    }

    List<MultiDoc> result = new ArrayList<>();
    for (MultiDoc md : new_mDocs)
        if (md != null)
            result.add(md);

    return result;
}

From source file:com.marand.thinkmed.medications.dao.openehr.MedicationsOpenEhrDao.java

public void appendWarningsToTherapy(@Nonnull final String patientId, @Nonnull final String therapyId,
        @Nonnull final Collection<String> warnings) {
    com.marand.maf.core.StringUtils.checkNotBlank(patientId, "patientId must be defined");
    com.marand.maf.core.StringUtils.checkNotBlank(therapyId, "therapyId must be defined");
    Preconditions.checkNotNull(warnings, "warnings must not be null");

    final Pair<String, String> therapyIdPair = TherapyIdUtils.parseTherapyId(therapyId);
    final MedicationOrderComposition composition = loadMedicationOrderComposition(patientId,
            therapyIdPair.getFirst());/*from  w w w . j ava  2  s  .  co m*/
    final OrderActivity orderActivity = MedicationsEhrUtils
            .getMedicationInstructionByEhrName(composition, therapyIdPair.getSecond()).getOrder().get(0);

    final String prefix = TherapyCommentEnum.getFullString(TherapyCommentEnum.WARNING) + " ";
    warnings.forEach(w -> orderActivity.getComment().add(DataValueUtils.getText(prefix + w)));

    updateSubjectComposition(patientId, composition, composition.getUid().getValue());
}

From source file:org.nanoframework.orm.jedis.sharded.RedisClientImpl.java

@Override
public List<Map<String, String>> info() {
    ShardedJedis jedis = null;//from  w w w .  j  a  v a 2 s.c  o  m
    try {
        jedis = POOL.getJedis(config.getRedisType());
        final Collection<Jedis> shards = jedis.getAllShards();
        final List<Map<String, String>> infos = Lists.newArrayList();
        shards.forEach(shard -> {
            final String info = shard.info();
            infos.add(info0(info));
        });

        return infos;
    } catch (final Throwable e) {
        throw new RedisClientException(e.getMessage(), e);
    } finally {
        POOL.close(jedis);
    }
}

From source file:org.nanoframework.orm.jedis.sharded.RedisClientImpl.java

@Override
public List<Map<String, String>> info(final String section) {
    ShardedJedis jedis = null;//from  w  ww.  j  a v a  2 s  .  co m
    try {
        jedis = POOL.getJedis(config.getRedisType());
        final Collection<Jedis> shards = jedis.getAllShards();
        final List<Map<String, String>> infos = Lists.newArrayList();
        shards.forEach(shard -> {
            final String info = shard.info(section);
            infos.add(info0(info));
        });

        return infos;
    } catch (final Throwable e) {
        throw new RedisClientException(e.getMessage(), e);
    } finally {
        POOL.close(jedis);
    }
}