Example usage for java.util List stream

List of usage examples for java.util List stream

Introduction

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

Prototype

default Stream<E> stream() 

Source Link

Document

Returns a sequential Stream with this collection as its source.

Usage

From source file:info.magnolia.vaadin.periscope.result.SupplierUtil.java

/**
 * Highlight (using HTML tags) all occurrences of a query string, ignoring case.
 *
 * @param text Text in which parts should be highlighted
 * @param query Parts to highlight//w ww  .jav a 2s  .c  o  m
 * @return Highlighted string
 */
public static String highlight(final String text, final String query) {
    if (StringUtils.isBlank(query)) {
        return text;
    }

    final List<Integer> startIndices = allIndicesOf(text, query);
    final List<Integer> endIndices = startIndices.stream().map(i -> i + query.length()).collect(toList());

    // we run back to front to not mess up indices when inserting tags
    Collections.reverse(startIndices);
    Collections.reverse(endIndices);
    Queue<Integer> startQueue = new LinkedList<>(startIndices);
    Queue<Integer> endQueue = new LinkedList<>(endIndices);

    StringBuilder highlighted = new StringBuilder(text);
    while (!startQueue.isEmpty() || !endQueue.isEmpty()) {
        final Integer startCandidate = startQueue.peek();
        final Integer endCandidate = endQueue.peek();

        if (startCandidate != null && (endCandidate == null || startCandidate > endCandidate)) {
            highlighted.insert(startCandidate, "<strong>");
            startQueue.poll();
        } else {
            highlighted.insert(endCandidate, "</strong>");
            endQueue.poll();
        }
    }

    return highlighted.toString();
}

From source file:de.metas.ui.web.window.datatypes.json.JSONDocumentLayoutSection.java

static List<JSONDocumentLayoutSection> ofSectionsList(final List<DocumentLayoutSectionDescriptor> sections,
        final JSONOptions jsonOpts) {
    return sections.stream().map(section -> of(section, jsonOpts)).collect(GuavaCollectors.toImmutableList());
}

From source file:alfio.model.result.Result.java

public static <T> Result<T> validationError(List<ObjectError> errors) {
    return new Result<>(ResultStatus.VALIDATION_ERROR, null,
            errors.stream().map(ErrorDescriptor::fromObjectError).collect(Collectors.toList()));
}

From source file:edu.mit.lib.mama.Mama.java

private static String jsonObject(List<Mdv> props) {
    return props.stream().map(p -> jsonValue(p.field, p.value, true))
            .collect(Collectors.joining(",", "{", "}"));
}

From source file:br.usp.poli.lta.cereda.wsn2spa.Utils.java

private static List<Transition> toTransitions(List<SimpleTransition> spec) {
    List<Transition> transitions = new ArrayList<>();
    spec.stream().map((simple) -> {
        Transition transition = new Transition();
        transition.setFrom(simple.getSource());
        transition.setTo(simple.getTarget());
        if (!simple.epsilon()) {
            transition.setSymbol(simple.getSymbol().getValue());
        }// ww w. j av a  2s .c om
        return transition;
    }).forEach((t) -> {
        transitions.add(t);
    });
    return transitions;
}

From source file:edu.umd.umiacs.clip.tools.math.CorrelationUtils.java

private static Pair<double[], double[]> sort(final double[] x, final double[] y) {
    List<Pair<Double, Double>> list = range(0, x.length).boxed().map(i -> Pair.of(x[i], y[i]))
            .sorted(comparing(Pair::getLeft, reverseOrder())).collect(toList());
    double[] xSorted = list.stream().mapToDouble(Pair::getLeft).toArray();
    double[] ySorted = list.stream().mapToDouble(Pair::getRight).toArray();
    return Pair.of(xSorted, ySorted);
}

From source file:com.example.app.profile.ui.user.LoginLandingLinks.java

private static boolean canAccessMenuLink(MembershipOperation mop, List<Membership> memberships) {
    if (memberships.isEmpty())
        return false;
    return memberships.stream().anyMatch(m -> m.getOperations().contains(mop));
}

From source file:com.github.horrorho.inflatabledonkey.pcs.xfile.FileAssembler.java

static InputStream inputStream(List<Chunk> chunkData) throws UncheckedIOException {
    List<InputStream> inputStreams = chunkData.stream().map(Chunk::inputStream).collect(Collectors.toList());

    Enumeration<InputStream> enumeration = Collections.enumeration(inputStreams);
    return new BufferedInputStream(new SequenceInputStream(enumeration), BUFFER_SIZE);
}

From source file:cfd.backupper.state.StartupConfig.java

public static void putSetting(String key, List l) {

    //l needs to be toString(), otherwise there are no doublequotes in JSON.
    List stringedList = (List) l.stream().map(elem -> elem.toString()).collect(Collectors.toList());
    if (jo.containsKey(key)) {
        jo.replace(key, stringedList);// w ww  .j a v a  2  s . com
    } else {
        jo.put(key, stringedList);
    }
    try {
        FileWriter fw = new FileWriter(confFile, false);
        fw.append(jo.toJSONString());
        fw.flush();
        fw.close();
    } catch (IOException ex) {
        Logger.getLogger(StartupConfig.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:gov.ca.cwds.cals.util.PlacementHomeUtil.java

/**
 * Overloaded method for composing facility name according to applicants list.
 *
 * @param applicantsList applicants list
 * @return facility name// w  w w  . j ava2s.  c  om
 */
public static String composeFacilityNameByApplicantsList(List<RFA1aApplicant> applicantsList) {
    return composeFacilityName(
            applicantsList.stream().map(RFA1aFormMapper.INSTANCE::toApplicantDTO).collect(Collectors.toList()));
}