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:edu.mit.lib.mama.Mama.java

private static List<String> findItems(Handle hdl, String qfield, String value, String[] rfields) {
    String queryBase = "select lmv.* from metadatavalue lmv, metadatavalue rmv where "
            + "lmv.item_id = rmv.item_id and rmv.metadata_field_id = ? and rmv.text_value = ? ";
    Query<Map<String, Object>> query;
    if (null == rfields) { // just return default field
        query = hdl.createQuery(queryBase + "and lmv.metadata_field_id = ?").bind(2,
                findFieldId(hdl, URI_FIELD));
    } else { // filter out fields we can't resolve
        String inList = Arrays.asList(rfields).stream().map(f -> String.valueOf(findFieldId(hdl, f)))
                .filter(id -> id != "-1").collect(Collectors.joining(","));
        query = hdl.createQuery(queryBase + "and lmv.metadata_field_id in (" + inList + ")");
    }//from  w w w.  j  ava 2s.  c o m
    List<Mdv> rs = query.bind(0, findFieldId(hdl, qfield)).bind(1, value).map(new MdvMapper()).list();
    // group the list by Item, then construct a JSON object with each item's properties
    return rs.stream().collect(Collectors.groupingBy(Mdv::getItemId)).values().stream().map(p -> jsonObject(p))
            .collect(Collectors.toList());
}

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

public static List<DocumentFilter> unwrapList(final List<JSONDocumentFilter> jsonFilters,
        final DocumentFilterDescriptorsProvider filterDescriptorProvider) {
    if (jsonFilters == null || jsonFilters.isEmpty()) {
        return ImmutableList.of();
    }/*  ww w  . j  ava2  s  .c o  m*/
    return jsonFilters.stream().map(jsonFilter -> unwrap(jsonFilter, filterDescriptorProvider))
            .filter(filter -> filter != null).collect(GuavaCollectors.toImmutableList());
}

From source file:jobhunter.api.infojobs.OfferRequest.java

/**
 * Generates a OfferRequest after parsing the given URL for the
 * InfoJobs' key./* w  w  w  .j  a va2  s .co  m*/
 * FTM I know of two URL formats where we can get the key from:
 * - Using the "of_codigo" query param
 * - Using the last 30 chars from a path param
 * This method handles both cases.
 * @param url
 * @return OfferRequest
 * @throws InfoJobsAPIException 
 */
public static OfferRequest of(String url) throws InfoJobsAPIException {
    List<NameValuePair> params = new ArrayList<>();
    try {
        params = URLEncodedUtils.parse(new URI(url), "UTF-8");
    } catch (URISyntaxException e) {
        l.error("Failed to build URI", e);
        throw new InfoJobsAPIException("Invalid URL " + url);
    }

    NameValuePair key = params.stream().filter(nvp -> nvp.getName().equalsIgnoreCase("of_codigo")).findFirst()
            .orElse(new BasicNameValuePair("of_codigo", StringUtils.right(url, 30)));

    return new OfferRequest(key);
}

From source file:com.freiheit.fuava.sftp.util.FilenameUtil.java

/**
 * Returns the lastest date/time from a list of filenames.
 *///from w  ww  .  j a v a 2s  . c o m
@CheckForNull
public static String extractLatestDateFromFilenames(final List<String> entryList, final FileType fileType,
        @Nullable final RemoteFileStatus status) throws ParseException {
    final Optional<String> maxDate = entryList.stream().filter(p -> p != null)
            .filter(f -> FilenameUtil.matchesSearchedFile(f, fileType, null, status))
            .max((a, b) -> Long.compare(getDateFromFilename(a), getDateFromFilename(b)));

    if (!maxDate.isPresent()) {
        return null; // no timestamp found
    }
    final String max = maxDate.get();

    return String.valueOf(getDateFromFilenameWithDelimiter(max));
}

From source file:com.github.mavogel.ilias.utils.IOUtils.java

/**
 * Checks the digits if they are in range against the choices.
 *
 * @param choices the choices// w w w . ja  va  2 s .c o m
 * @param digits the digits
 * @return true of they are correct, false otherwise
 */
private static boolean checkInputDigits(final List<?> choices, final List<Integer> digits) {
    return digits.stream().allMatch(idx -> isInRange(choices, idx));
}

From source file:com.github.mavogel.ilias.utils.IOUtils.java

/**
 * Parses the ranges from the tokens./*w w w .  j av a 2 s  .c  o m*/
 *
 * @param tokens the tokens @see {@link IOUtils#splitAndTrim(String)}
 * @return the ranges
 */
private static List<String[]> parseRanges(final List<String> tokens) {
    return tokens.stream().filter(s -> Defaults.RANGE_PATTERN.matcher(s).matches()).map(r -> r.split("-"))
            .collect(Collectors.toList());
}

From source file:com.github.mavogel.ilias.utils.IOUtils.java

/**
 * Parses the digits from the tokens/*from w  ww. jav  a 2s. c  om*/
 *
 * @param tokens the tokens @see {@link IOUtils#splitAndTrim(String)}
 * @return the tokens
 */
private static List<Integer> parseDigits(final List<String> tokens) {
    return tokens.stream().filter(s -> Defaults.DIGIT_PATTERN.matcher(s).matches()).map(Integer::valueOf)
            .collect(Collectors.toList());
}

From source file:com.wrmsr.wava.yen.translation.UnitTranslation.java

public static Function translateFunction(YFunction function, Map<Name, Signature> functionSignatures) {
    requireNonNull(function);//from  w  w  w  .  j av  a 2 s  . c  o  m
    checkArgument(function.getName().isPresent());
    checkArgument(function.getResult() != Type.UNREACHABLE);
    checkArgument(function.getBody().isPresent());
    checkArgument(function.getLocalNames().size() == function.getNumLocals());
    checkArgument(function.getLocalIndices().size() == function.getNumLocals());
    List<Pair<Name, Index>> localList = function.getLocalIndices().entrySet().stream()
            .map(e -> ImmutablePair.of(e.getKey(), e.getValue())).collect(Collectors.toList());
    localList.sort((l, r) -> l.getValue().compareTo(r.getValue()));
    checkArgument(
            enumerate(localList.stream().map(Pair::getRight)).allMatch(e -> e.getItem().get() == e.getIndex()));
    Locals locals = Locals
            .of(localList.stream().map(l -> ImmutablePair.of(l.getLeft(), function.getLocalType(l.getRight())))
                    .collect(toImmutableList()));
    Node body = NodeTranslation.translateNode(function.getBody().get(), functionSignatures);
    return new Function(function.getName().get(), function.getResult(), function.getNumParams(), locals, body);
}

From source file:act.installer.HMDBParser.java

/**
 * Get the text contents contained in a list of nodes.  Used for multi-valued fields that are siblings in the tree.
 * @param n A list of nodes whose text content should be extracted.
 * @return The text for each node.//  www . j a v a  2 s . c  om
 */
private static List<String> extractNodesText(List<Node> n) {
    return n.stream().map(Node::getTextContent).collect(Collectors.toList());
}

From source file:com.github.mavogel.ilias.utils.IOUtils.java

/**
 * Checks the ranges if they are meaningful against the choices.
 *
 * @param choices the choices/*  ww w.ja  v a  2s  .co m*/
 * @param ranges the ranges
 * @return true of they are correct, false otherwise
 */
private static boolean checkRanges(final List<?> choices, final List<String[]> ranges) {
    return ranges.stream()
            .allMatch(r -> isInMeaningfulRange(choices, Integer.valueOf(r[0]), Integer.valueOf(r[1])));
}