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:com.qpark.eip.core.sftp.SftpDownload.java

/**
 * Get the list of Objects from the SFTP.
 *
 * @param typeFactory/*from w ww .java 2s  . co m*/
 *            the factory creating a list of T.
 * @param baseDir
 *            base source directory to get the files from (e.g. incoming)
 * @param fileNamePart
 *            the part, the file name need to contain (e.g. logs).
 * @param fileFormat
 *            the file format (e.g. xml, txt, json ...)
 * @return the list of Objects.
 */
public <T> List<T> getObjects(final TypeFactory<T> typeFactory, final String baseDir, final String fileNamePart,
        final String fileFormat) {
    this.logger.debug("+getObjects");
    final List<T> value = new ArrayList<>();
    final String sourceDir = this.sftpGateway.getFilePath(baseDir, SftpGateway.DIRECTORY_OPEN);
    try {
        final Collection<String> filePathes = this.sftpGateway.getTreeOfFiles(sourceDir,
                String.format("20.*?%s.%s", fileNamePart, fileFormat));
        filePathes.stream().sorted()
                .forEach(filePath -> value.addAll(this.getObject(typeFactory, baseDir, filePath)));
    } catch (final Exception e) {
        this.logger.error(String.format("%s:%s", sourceDir, e.getMessage()), e);
    } finally {
        this.logger.debug("-getObjects {} #{}", sourceDir, value.size());
    }
    return value;
}

From source file:com.github.totyumengr.minicubes.cluster.BootTimeSeriesMiniCubeController.java

@RequestMapping(value = "/status", method = RequestMethod.GET)
public @ResponseBody Map<String, List<String>> status() {

    Map<String, List<String>> status = new LinkedHashMap<>();
    Collection<String> allCubeIds = manager.allCubeIds();
    status.put("working", allCubeIds.stream().filter(e -> !e.startsWith("?")).collect(Collectors.toList()));
    status.put("awaiting", allCubeIds.stream().filter(e -> e.startsWith("?")).collect(Collectors.toList()));

    LOGGER.info("All miniCube size in cluster: {}, working/awaiting is {}/{}", allCubeIds.size(),
            status.get("working").size(), status.get("awaiting").size());

    return status;
}

From source file:ru.apertum.qsystem.server.Spring.java

public void saveAll(Collection list) {
    final Session ses = getTxManager().getSessionFactory().getCurrentSession();
    list.stream().forEach((object) -> {
        ses.save(object);//from   w  ww.  ja  v a 2  s  . c o  m
    });
    ses.flush();
}

From source file:ru.apertum.qsystem.server.Spring.java

public void saveOrUpdateAll(Collection list) {
    final Session ses = getTxManager().getSessionFactory().getCurrentSession();
    list.stream().forEach((object) -> {
        ses.saveOrUpdate(object);/*from   ww  w.j a v a  2 s  .  c o m*/
    });
    ses.flush();
}

From source file:ru.apertum.qsystem.server.Spring.java

public void deleteAll(Collection list) {
    final Session ses = getTxManager().getSessionFactory().getCurrentSession();
    list.stream().forEach((object) -> {
        ses.delete(object);//  ww  w  .j a v  a 2  s  .  c  o  m
    });
    ses.flush();
}

From source file:com.github.ukase.toolkit.jar.JarSource.java

@Autowired
public JarSource(CompoundTemplateLoader templateLoader, UkaseSettings settings) {
    this.templateLoader = templateLoader;

    if (settings.getJar() == null) {
        classLoader = null;/*  w  w  w.  j av a  2  s. co  m*/
        fonts = Collections.emptyList();

        return;
    }

    try {
        URL jar = settings.getJar().toURI().toURL();

        Collection<String> props = templateLoader.getResources(IS_HELPERS_CONFIGURATION);

        Properties properties = new Properties();
        props.stream().map(templateLoader::getResource).filter(entry -> entry != null).map(this::mapZipEntry)
                .filter(stream -> stream != null).forEach(stream -> loadStreamToProperties(stream, properties));
        properties.forEach(this::registerHelper);

        fonts = templateLoader.getResources(IS_FONT).parallelStream().map(font -> "jar:" + jar + "!/" + font)
                .collect(Collectors.toList());

        if (hasHelpers()) {
            URL[] jars = new URL[] { jar };
            classLoader = new URLClassLoader(jars, getClass().getClassLoader());
            helpers.forEach((name, className) -> helpersInstances.put(name, getHelper(className)));
        } else {
            classLoader = null;
        }

    } catch (IOException e) {
        throw new IllegalStateException("Wrong configuration", e);
    }
}

From source file:co.runrightfast.core.security.cert.CAIssuedX509V3CertRequest.java

private void checkConstraints(final Collection<X509CertExtension> extensions) {
    if (CollectionUtils.isEmpty(extensions)) {
        return;//from w ww  .ja  va 2  s . co  m
    }

    final Extensions exts = new Extensions(
            extensions.stream().map(X509CertExtension::toExtension).toArray(Extension[]::new));
    checkArgument(AuthorityKeyIdentifier.fromExtensions(exts) == null,
            "AuthorityKeyIdentifier must not be specified as an extension - it is added automatically");
}

From source file:ch.wisv.areafiftylan.products.service.TicketServiceImpl.java

private Collection<Ticket> getCaptainedTickets(User u) {
    Collection<Team> captainedTeams = teamService.getTeamByCaptainId(u.getId());

    return captainedTeams.stream().flatMap(t -> t.getMembers().stream()).filter(m -> !m.equals(u))
            .flatMap(m -> ticketRepository.findAllByOwnerUsernameIgnoreCase(m.getUsername()).stream()
                    .filter(Ticket::isValid))
            .collect(Collectors.toList());
}

From source file:com.khartec.waltz.data.application.AppTagDao.java

public int[] updateTags(long id, Collection<String> tags) {
    LOG.info("Updating tags for application " + id + ", tags: " + tags);

    dsl.delete(APPLICATION_TAG).where(APPLICATION_TAG.APPLICATION_ID.eq(id)).execute();

    List<ApplicationTagRecord> records = tags.stream().map(t -> new ApplicationTagRecord(id, t))
            .collect(Collectors.toList());

    return dsl.batchInsert(records).execute();
}

From source file:ddf.catalog.metacard.duplication.DuplicationValidator.java

private String collectionToString(final Collection collection) {

    return (String) collection.stream().map(Object::toString).sorted().collect(Collectors.joining(", "));
}