List of usage examples for java.util.stream StreamSupport stream
public static <T> Stream<T> stream(Spliterator<T> spliterator, boolean parallel)
From source file:org.pentaho.database.service.ServiceLoaderDatabaseDialectProvider.java
public ServiceLoaderDatabaseDialectProvider( Function<Class<IDatabaseDialect>, Iterable<IDatabaseDialect>> loaderFunction) { Stream<IDatabaseDialect> databaseDialectStream = StreamSupport .stream(loaderFunction.apply(IDatabaseDialect.class).spliterator(), false); allDialects = Collections.unmodifiableList(databaseDialectStream.collect(Collectors.toList())); allDialectsTypeMap = Collections.unmodifiableMap(allDialects.stream() .collect(Collectors.toMap(IDatabaseDialect::getDatabaseType, Function.identity()))); usableDialects = Collections//from w ww .ja v a 2s.co m .unmodifiableList(allDialects.stream().filter(usableFilter(LOG)).collect(Collectors.toList())); usableDialectTypeMap = Collections.unmodifiableMap(usableDialects.stream() .collect(Collectors.toMap(IDatabaseDialect::getDatabaseType, Function.identity()))); }
From source file:com.epam.ta.reportportal.ws.resolver.SortArgumentResolver.java
@Override public Sort resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) { /*/* w w w. j a va2s . c om*/ * Resolve sort argument in default way */ Sort defaultSort = super.resolveArgument(parameter, mavContainer, webRequest, binderFactory); /* * Try to find parameter to be sorted in internal-external mapping */ if (null != parameter.getParameterAnnotation(SortFor.class) && null != defaultSort) { Class<?> domainModelType = parameter.getParameterAnnotation(SortFor.class).value(); CriteriaMap<?> map = criteriaMapFactory.getCriteriaMap(domainModelType); /* * Build Sort with search criteria from internal domain model */ return new Sort(StreamSupport.stream(defaultSort.spliterator(), false).map(order -> { Optional<CriteriaHolder> criteriaHolder = map.getCriteriaHolderUnchecked(order.getProperty()); BusinessRule.expect(criteriaHolder, Preconditions.IS_PRESENT) .verify(ErrorType.INCORRECT_SORTING_PARAMETERS, order.getProperty()); return new Order(order.getDirection(), criteriaHolder.get().getQueryCriteria()); }).collect(toList())); } else { /* * Return default sort in case there are no SortFor annotation */ return defaultSort; } }
From source file:edu.pitt.dbmi.ccd.anno.data.AnnotationTargetResourceAssembler.java
/** * convert AnnotationTargets to AnnotationTargetResources * * @param targets entities/*w w w . j a va 2 s . co m*/ * @return List of resources */ @Override public List<AnnotationTargetResource> toResources(Iterable<? extends AnnotationTarget> targets) throws IllegalArgumentException { // Assert targets is not empty Assert.isTrue(targets.iterator().hasNext()); return StreamSupport.stream(targets.spliterator(), false).map(this::toResource) .collect(Collectors.toList()); }
From source file:io.wcm.devops.conga.generator.plugins.handlebars.helper.AbstractEachIfHelper.java
/** * Filter iterable to contain only items that have any value set for the given property name. * @param items Items/* w w w . j a va2s . com*/ * @param propertyName Property name * @param options Options * @return Filtered items */ private Iterable<Object> filterIterable(Iterable<Object> items, String propertyName, Options options) { return StreamSupport.stream(items.spliterator(), false).filter(item -> item != null) .filter(item -> checkProperty(item, propertyName, options)).collect(Collectors.toList()); }
From source file:org.mskcc.shenkers.data.interval.GIntervalTreeMap.java
public Stream<Node<T>> streamOverlapNodes(String chr, int start, int end, Strand strand) { boolean parallel = false; int characteristics = 0; return StreamSupport.stream( Spliterators.spliteratorUnknownSize(queryNodes(chr, start, end, strand), characteristics), parallel);/*from w w w. j a va 2s . c o m*/ }
From source file:com.tesco.mewbase.bson.Bson.java
static <T> Stream<T> asStream(Iterator<T> sourceIterator) { Iterable<T> iterable = () -> sourceIterator; return StreamSupport.stream(iterable.spliterator(), false); }
From source file:org.apache.solr.client.solrj.io.eval.FindDelayEvaluator.java
@Override public Object doWork(Object first, Object second) throws IOException { if (null == first) { throw new IOException(String.format(Locale.ROOT, "Invalid expression %s - null found for the first value", toExpression(constructingFactory))); }/*from w w w. j a v a 2s . c o m*/ if (null == second) { throw new IOException(String.format(Locale.ROOT, "Invalid expression %s - null found for the second value", toExpression(constructingFactory))); } if (!(first instanceof List<?>)) { throw new IOException(String.format(Locale.ROOT, "Invalid expression %s - found type %s for the first value, expecting a list of numbers", toExpression(constructingFactory), first.getClass().getSimpleName())); } if (!(second instanceof List<?>)) { throw new IOException(String.format(Locale.ROOT, "Invalid expression %s - found type %s for the second value, expecting a list of numbers", toExpression(constructingFactory), first.getClass().getSimpleName())); } // Get first and second lists as arrays, where second is in reverse order double[] firstArray = ((List) first).stream().mapToDouble(value -> ((BigDecimal) value).doubleValue()) .toArray(); double[] secondArray = StreamSupport .stream(Spliterators.spliteratorUnknownSize( ((LinkedList) ((List) second).stream().collect(Collectors.toCollection(LinkedList::new))) .descendingIterator(), Spliterator.ORDERED), false) .mapToDouble(value -> ((BigDecimal) value).doubleValue()).toArray(); double[] convolution = MathArrays.convolve(firstArray, secondArray); double maxValue = -Double.MAX_VALUE; double indexOfMaxValue = -1; for (int idx = 0; idx < convolution.length; ++idx) { double abs = Math.abs(convolution[idx]); if (abs > maxValue) { maxValue = abs; indexOfMaxValue = idx; } } return (indexOfMaxValue + 1) - secondArray.length; }
From source file:edu.pitt.dbmi.ccd.db.service.GroupService.java
public List<Group> findByNames(Iterable<String> names) { return StreamSupport.stream(names.spliterator(), false).map(this::findByName).collect(Collectors.toList()); }
From source file:org.bozzo.ipplan.domain.model.ui.SubnetResource.java
/** * @param id/* w ww.ja va 2 s . co m*/ * @param infraId * @param ip * @param size * @param description * @param group * @param lastModifed * @param userId * @param optionId * @param swipMod */ @JsonCreator public SubnetResource(@JsonProperty("id") Long id, @JsonProperty Integer infraId, @JsonProperty Long ip, @JsonProperty Integer netmask, @JsonProperty Long size, @JsonProperty String description, @JsonProperty String group, @JsonProperty Date lastModifed, @JsonProperty String userId, @JsonProperty Long optionId, @JsonProperty Date swipMod, @JsonProperty Iterable<Address> addresses) { this.id = id; this.infraId = infraId; this.ip = ip; this.size = size; this.netmask = netmask; this.description = description; this.group = group; this.lastModifed = lastModifed; this.userId = userId; this.optionId = optionId; this.swipMod = swipMod; if (addresses != null) { this.setAddresses( StreamSupport.stream(addresses.spliterator(), true).map(new ToAddressResourceFunction())); } }
From source file:com.homeadvisor.kafdrop.service.MessageInspector.java
public List<MessageVO> getMessages(String topicName, int partitionId, int offset, int count) { final TopicVO topic = kafkaMonitor.getTopic(topicName).orElseThrow(TopicNotFoundException::new); final TopicPartitionVO partition = topic.getPartition(partitionId) .orElseThrow(PartitionNotFoundException::new); return kafkaMonitor.getBroker(partition.getLeader().getId()).map(broker -> { SimpleConsumer consumer = new SimpleConsumer(broker.getHost(), broker.getPort(), 10000, 100000, ""); final FetchRequestBuilder fetchRequestBuilder = new FetchRequestBuilder().clientId("KafDrop") .maxWait(5000) // todo: make configurable .minBytes(1);/*from w w w . jav a 2s . com*/ List<MessageVO> messages = new ArrayList<>(count); long currentOffset = offset; while (messages.size() < count) { final FetchRequest fetchRequest = fetchRequestBuilder .addFetch(topicName, partitionId, currentOffset, 1024 * 1024).build(); FetchResponse fetchResponse = consumer.fetch(fetchRequest); final ByteBufferMessageSet messageSet = fetchResponse.messageSet(topicName, partitionId); if (messageSet.validBytes() <= 0) break; int oldSize = messages.size(); StreamSupport.stream(messageSet.spliterator(), false).limit(count - messages.size()) .map(MessageAndOffset::message).map(this::createMessage).forEach(messages::add); currentOffset += messages.size() - oldSize; } return messages; }).orElseGet(Collections::emptyList); }