List of usage examples for java.util.stream Collectors toList
public static <T> Collector<T, ?, List<T>> toList()
From source file:com.ikanow.aleph2.data_model.utils.ProcessUtils.java
/** * Starts the given process by calling process_builder.start(); * Records the started processes pid and start date. * /*from www. j av a 2 s .c o m*/ * @param process_builder * @throws IOException * @return returns any error in _1(), the pid in _2() */ public static Tuple2<String, String> launchProcess(final ProcessBuilder process_builder, final String application_name, final DataBucketBean bucket, final String aleph_root_path, final Optional<Tuple2<Long, Integer>> timeout_kill) { try { if (timeout_kill.isPresent()) { final Stream<String> timeout_stream = Stream.of("timeout", "-s", timeout_kill.get()._2.toString(), timeout_kill.get()._1.toString()); process_builder.command(Stream.concat(timeout_stream, process_builder.command().stream()) .collect(Collectors.toList())); } //starts the process, get pid back logger.debug("Starting process: " + process_builder.command().toString()); final Process px = process_builder.start(); String err = null; String pid = null; if (!px.isAlive()) { err = "Unknown error: " + px.exitValue() + ": " + process_builder.command().stream().collect(Collectors.joining(" ")); // (since not capturing output) } else { pid = getPid(px); //get the date on the pid file from /proc/<pid> final long date = getDateOfPid(pid); //record pid=date to aleph_root_path/pid_manager/bucket._id/application_name storePid(application_name, bucket, aleph_root_path, pid, date); } return Tuples._2T(err, pid); } catch (Throwable t) { return Tuples._2T(ErrorUtils.getLongForm("{0}", t), null); } }
From source file:com.netflix.spinnaker.front50.model.pipeline.DefaultPipelineDAO.java
@Override public Collection<Pipeline> getPipelinesByApplication(String application) { return all().stream().filter(pipeline -> pipeline.getApplication() != null && pipeline.getApplication().equalsIgnoreCase(application)).collect(Collectors.toList()); }
From source file:fi.helsinki.opintoni.service.CourseService.java
public List<CourseDto> getTeacherCourses(String teacherNumber, Locale locale) { return oodiClient.getTeacherCourses(teacherNumber, DateTimeUtil.getSemesterStartDateString(LocalDate.now())) .stream().map(c -> courseConverter.toDto(c, locale)).collect(Collectors.toList()); }
From source file:uk.ac.ebi.ep.data.repositories.EnzymePortalEcNumbersRepositoryImpl.java
@Transactional(readOnly = true) @Override/*from ww w . j av a 2 s . co m*/ public List<EcNumber> findEnzymeFamiliesByTaxId(Long taxId) { EntityGraph eGraph = entityManager.getEntityGraph("EcNumberEntityGraph"); eGraph.addAttributeNodes("uniprotAccession"); JPAQuery query = new JPAQuery(entityManager); query.setHint("javax.persistence.fetchgraph", eGraph); List<EcNumber> result = query.from($).where($.uniprotAccession.taxId.eq(taxId)) .list(Projections.constructor(EcNumber.class, $.ecFamily)).stream().distinct() .collect(Collectors.toList()); result.sort(SORT_BY_EC); return result; }
From source file:com.netflix.genie.core.jpa.specifications.JpaApplicationSpecs.java
/** * Get a specification using the specified parameters. * * @param name The name of the application * @param user The name of the user who created the application * @param statuses The status of the application * @param tags The set of tags to search the command for * @param type The type of applications to fine * @return A specification object used for querying *//*from w ww .jav a2 s .c o m*/ public static Specification<ApplicationEntity> find(final String name, final String user, final Set<ApplicationStatus> statuses, final Set<String> tags, final String type) { return (final Root<ApplicationEntity> root, final CriteriaQuery<?> cq, final CriteriaBuilder cb) -> { final List<Predicate> predicates = new ArrayList<>(); if (StringUtils.isNotBlank(name)) { predicates.add(JpaSpecificationUtils.getStringLikeOrEqualPredicate(cb, root.get(ApplicationEntity_.name), name)); } if (StringUtils.isNotBlank(user)) { predicates.add(JpaSpecificationUtils.getStringLikeOrEqualPredicate(cb, root.get(ApplicationEntity_.user), user)); } if (statuses != null && !statuses.isEmpty()) { final List<Predicate> orPredicates = statuses.stream() .map(status -> cb.equal(root.get(ApplicationEntity_.status), status)) .collect(Collectors.toList()); predicates.add(cb.or(orPredicates.toArray(new Predicate[orPredicates.size()]))); } if (tags != null && !tags.isEmpty()) { predicates.add( cb.like(root.get(ApplicationEntity_.tags), JpaSpecificationUtils.getTagLikeString(tags))); } if (StringUtils.isNotBlank(type)) { predicates.add(JpaSpecificationUtils.getStringLikeOrEqualPredicate(cb, root.get(ApplicationEntity_.type), type)); } return cb.and(predicates.toArray(new Predicate[predicates.size()])); }; }
From source file:io.yields.math.concepts.operator.Smoothness.java
public static List<Tuple> normalize(Collection<Tuple> tuples) { DoubleSummaryStatistics statsForX = tuples.stream() .collect(Collectors.summarizingDouble(tuple -> tuple.getX())); DoubleSummaryStatistics statsForY = tuples.stream() .collect(Collectors.summarizingDouble(tuple -> tuple.getY())); double minX = statsForX.getMin(); double maxX = statsForX.getMax(); double minY = statsForY.getMin(); double maxY = statsForY.getMax(); return tuples.stream().map(tuple -> { double x = (tuple.getX() - minX) / (maxX - minX); double y = (tuple.getY() - minY) / (maxY - minY); return new Tuple(x, y); }).collect(Collectors.toList()); }
From source file:com.devicehive.handler.notification.NotificationSearchHandlerTest.java
@Override public void setUp() throws Exception { super.setUp(); guid = UUID.randomUUID().toString(); // create notifications notifications = LongStream.range(0, 3).mapToObj(i -> createNotification(i, guid)) .collect(Collectors.toList()); // insert notifications notifications.stream().map(this::insertNotification).forEach(this::waitForResponse); }
From source file:cc.kave.commons.pointsto.evaluation.PointsToSetEvaluation.java
public void run(Path contextsDir) throws IOException { StatementCounterVisitor stmtCounterVisitor = new StatementCounterVisitor(); List<Context> contexts = getSamples(contextsDir).stream() .filter(cxt -> cxt.getSST().accept(stmtCounterVisitor, null) > 0).collect(Collectors.toList()); log("Using %d contexts for evaluation\n", contexts.size()); PointsToUsageExtractor extractor = new PointsToUsageExtractor(); for (Context context : contexts) { PointstoSetSizeAnalysis analysis = new PointstoSetSizeAnalysis(); extractor.extract(analysis.compute(context)); results.addAll(analysis.getSetSizes()); }// w ww . ja v a2 s . co m DescriptiveStatistics statistics = new DescriptiveStatistics(); for (Integer setSize : results) { statistics.addValue(setSize.doubleValue()); } log("mean: %.2f\n", statistics.getMean()); log("stddev: %.2f\n", statistics.getStandardDeviation()); log("min/max: %.2f/%.2f\n", statistics.getMin(), statistics.getMax()); }
From source file:co.mafiagame.engine.command.internalcommand.AnnounceRoleCommand.java
@Override public ResultMessage execute(EmptyContext context) { Game game = context.getGame();/*from w w w . jav a 2s. c o m*/ List<Message> messages = new ArrayList<>(); game.getPlayers().forEach(p -> messages .add(new Message(RoleUtil.roleIs(p.getRole())).setReceiverId(p.getAccount().getUserInterfaceId()))); List<Player> mafias = game.mafias(); List<String> mafiaUserNames = mafias.stream().map(Player::getAccount).map(Account::getUsername) .collect(Collectors.toList()); mafias.forEach(m -> messages .add(new Message("mafia.are.players").setReceiverId(m.getAccount().getUserInterfaceId()) .setArgs(ListToString.toString(mafiaUserNames)))); return new ResultMessage(messages, ChannelType.USER_PRIVATE, context.getInterfaceContext()); }
From source file:com.devicehive.dao.rdbms.NetworkDaoRdbmsImpl.java
@Override public List<NetworkVO> findByName(String name) { List<Network> result = createNamedQuery(Network.class, "Network.findByName", Optional.of(CacheConfig.get())) .setParameter("name", name).getResultList(); Stream<NetworkVO> objectStream = result.stream().map(Network::convertNetwork); return objectStream.collect(Collectors.toList()); }