Example usage for java.util Collection stream

List of usage examples for java.util Collection stream

Introduction

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

Prototype

default Stream<E> stream() 

Source Link

Document

Returns a sequential Stream with this collection as its source.

Usage

From source file:delfos.dataset.util.DatasetPrinter.java

public static void printFancyRatingTable(RatingsDataset<? extends Rating> ratingsDataset,
        Collection<Integer> users, Collection<Integer> items) {
    //Escribo la cabecera
    {/* www  . ja v a  2 s  . c o  m*/
        Global.showInfoMessage("|\t\t|");
        items.stream().forEach((idItem) -> {
            Global.showInfoMessage("\tI_" + idItem + "\t|");
        });
        Global.showInfoMessage("\n");

        Global.showInfoMessage("+---------------+");
        items.stream().forEach((_item) -> {
            Global.showInfoMessage("---------------+");
        });
        Global.showInfoMessage("\n");
    }

    //Escribo cada lnea
    for (int idUser : users) {
        Global.showInfoMessage("|\tU_" + idUser + "\t|");
        for (int idItem : items) {
            try {
                Rating rating = ratingsDataset.getRating(idUser, idItem);
                if (rating == null) {
                    Global.showInfoMessage("\t - \t|");
                } else {

                    Global.showInfoMessage("\t" + NumberRounder.round(rating.getRatingValue()) + "\t|");
                }
            } catch (UserNotFound | ItemNotFound ex) {
                Global.showInfoMessage("\t - \t|");
            }
        }
        Global.showInfoMessage("\n");
    }

    //Cierro la tabla
    Global.showInfoMessage("+---------------+");
    items.stream().forEach((_item) -> {
        Global.showInfoMessage("---------------+");
    });
    Global.showInfoMessage("\n");
}

From source file:delfos.dataset.util.DatasetPrinter.java

public static void printCompactUserUserTable(Map<Integer, Map<Integer, Number>> values,
        Collection<Integer> users) {

    //Escribo la cabecera
    {/*from   www  .  j  av  a  2s.c o  m*/
        Global.showInfoMessage("|\t|");
        users.stream().forEach((idUser) -> {
            Global.showInfoMessage("U_" + idUser + "\t|");
        });
        Global.showInfoMessage("\n");

        Global.showInfoMessage("+-------+");
        users.stream().forEach((_item) -> {
            Global.showInfoMessage("-------+");
        });
        Global.showInfoMessage("\n");
    }

    //Escribo cada lnea
    for (int idUser : users) {
        Global.showInfoMessage("|U_" + idUser + "\t|");
        for (int idUser2 : users) {
            try {
                if (!values.containsKey(idUser)) {
                    throw new UserNotFound(idUser);
                } else {
                    if (!values.get(idUser).containsKey(idUser2)) {
                        throw new UserNotFound(idUser);
                    }
                    Number value = values.get(idUser).get(idUser2);
                    Global.showInfoMessage("" + NumberRounder.round(value) + "\t|");
                }
            } catch (UserNotFound ex) {
                Global.showInfoMessage(" - \t|");
            }
        }
        Global.showInfoMessage("\n");
    }

    //Cierro la tabla
    Global.showInfoMessage("+-------+");
    for (int idItem : users) {
        Global.showInfoMessage("-------+");
    }
    Global.showInfoMessage("\n");
}

From source file:com.shenit.commons.utils.CollectionUtils.java

/**
 * Found out the item that col1 contains but col2 not contains.
 * @param col1 Collection 1//from   w  w w . ja  va  2s  .  c  o  m
 * @param col2 Collection 2
 * @return The items only in col1 but not col2
 */
@SuppressWarnings("unchecked")
public static <T> Collection<T> diff(Collection<T> col1, Collection<T> col2) {
    if (ValidationUtils.isEmpty(col1))
        return col2;
    else if (ValidationUtils.isEmpty(col2))
        return col1;
    try {
        Collection<T> diff = col1.getClass().newInstance();
        col1.stream().forEach((item1) -> {
            if (col2.parallelStream().noneMatch((item2) -> ValidationUtils.eq(item1, item2))) {
                diff.add(item1);
            }
        });
        return diff;
    } catch (InstantiationException | IllegalAccessException e) {
        LOG.warn("[diff] Could not create instance for {} with empty parameter constructor", col1.getClass());
    }
    return null;
}

From source file:ddf.catalog.history.Historian.java

private static String getList(Collection<String> set) {
    return set.stream().collect(TO_A_STRING);
}

From source file:delfos.dataset.util.DatasetPrinter.java

public static String printCompactRatingTable(RatingsDataset<? extends Rating> ratingsDataset,
        Collection<Integer> users, Collection<Integer> items) {

    StringBuilder str = new StringBuilder();

    //Escribo la cabecera
    {//from ww w.j  a  v  a 2 s .  c  o m
        str.append("|\t|");
        items.stream().forEach((idItem) -> {
            str.append("I_").append(idItem).append("\t|");
        });
        str.append("\n");

        str.append("+-------+");
        items.stream().forEach((_item) -> {
            str.append("-------+");
        });
        str.append("\n");
    }

    //Escribo cada lnea
    for (int idUser : users) {
        str.append("|U_").append(idUser).append("\t|");
        for (int idItem : items) {
            try {
                Rating rating = ratingsDataset.getRating(idUser, idItem);
                if (rating == null) {
                    str.append(" - \t|");
                } else {

                    str.append("").append(NumberRounder.round(rating.getRatingValue())).append("\t|");
                }
            } catch (UserNotFound | ItemNotFound ex) {
                str.append(" - \t|");
            }

        }
        str.append("\n");
    }

    //Cierro la tabla
    str.append("+-------+");
    items.stream().forEach((_item) -> {
        str.append("-------+");
    });
    str.append("\n");

    return str.toString();
}

From source file:com.thinkbiganalytics.nifi.rest.support.NifiProcessUtil.java

/**
 * Filters the specified list of process groups for ones matching the specified feed name, including versioned process groups.
 *
 * @param processGroups the list of process groups to filter
 * @param feedName      the feed system name to match, case-insensitive
 * @return the matching process groups//from  w w w.  j a v  a  2s.c  o  m
 */
@Nonnull
public static Set<ProcessGroupDTO> findProcessGroupsByFeedName(
        @Nonnull final Collection<ProcessGroupDTO> processGroups, @Nonnull final String feedName) {
    Pattern pattern = Pattern.compile("^" + Pattern.quote(feedName) + "( - \\d+)?$", Pattern.CASE_INSENSITIVE);
    return processGroups.stream().filter(processGroup -> pattern.matcher(processGroup.getName()).matches())
            .collect(Collectors.toSet());
}

From source file:de.bund.bfr.knime.gis.views.canvas.CanvasUtils.java

public static <T> Set<T> getElementsById(Map<String, T> elements, Collection<String> ids) {
    return ids.stream().map(id -> elements.get(id)).filter(Objects::nonNull)
            .collect(Collectors.toCollection(LinkedHashSet::new));
}

From source file:de.bund.bfr.knime.gis.views.canvas.CanvasUtils.java

public static Set<String> getElementIds(Collection<? extends Element> elements) {
    return elements.stream().map(e -> e.getId()).collect(Collectors.toCollection(LinkedHashSet::new));
}

From source file:de.bund.bfr.knime.gis.views.canvas.CanvasUtils.java

public static <T extends Element> Set<T> getElementsById(Collection<T> elements, Set<String> ids) {
    return elements.stream().filter(e -> ids.contains(e.getId()))
            .collect(Collectors.toCollection(LinkedHashSet::new));
}

From source file:com.evolveum.midpoint.wf.impl.util.MiscDataUtil.java

public static List<String> refsToStrings(@NotNull Collection<ObjectReferenceType> refs) {
    return refs.stream().map(r -> refToString(r)).collect(Collectors.toList());
}