Tabnine Logo
Stream.forEach
Code IndexAdd Tabnine to your IDE (free)

How to use
forEach
method
in
java.util.stream.Stream

Best Java code snippets using java.util.stream.Stream.forEach (Showing top 20 results out of 46,332)

Refine searchRefine arrow

  • Stream.filter
  • List.stream
  • Stream.map
  • Set.stream
  • Collection.stream
  • Map.Entry.getValue
  • Map.Entry.getKey
  • Map.entrySet
origin: spring-projects/spring-framework

/**
 * Match handlers declared under a base package, e.g. "org.example".
 * @param packages one or more base package classes
 */
public Builder basePackage(String... packages) {
  Arrays.stream(packages).filter(StringUtils::hasText).forEach(this::addBasePackage);
  return this;
}
origin: eclipse-vertx/vert.x

@Override
public Collection<CommandFactory<?>> lookup() {
 List<CommandFactory<?>> list = new ArrayList<>();
 commands.stream().forEach(list::add);
 return list;
}
origin: spring-projects/spring-framework

/**
 * Configure path prefixes to apply to controller methods.
 * <p>Prefixes are used to enrich the mappings of every {@code @RequestMapping}
 * method whose controller type is matched by a corresponding
 * {@code Predicate} in the map. The prefix for the first matching predicate
 * is used, assuming the input map has predictable order.
 * <p>Consider using {@link org.springframework.web.method.HandlerTypePredicate
 * HandlerTypePredicate} to group controllers.
 * @param prefixes a map with path prefixes as key
 * @since 5.1
 * @see org.springframework.web.method.HandlerTypePredicate
 */
public void setPathPrefixes(Map<String, Predicate<Class<?>>> prefixes) {
  this.pathPrefixes.clear();
  prefixes.entrySet().stream()
      .filter(entry -> StringUtils.hasText(entry.getKey()))
      .forEach(entry -> this.pathPrefixes.put(entry.getKey(), entry.getValue()));
}
origin: spring-projects/spring-framework

/**
 * Provide the TaskScheduler to use for SockJS endpoints for which a task
 * scheduler has not been explicitly registered. This method must be called
 * prior to {@link #getHandlerMapping()}.
 */
protected void setTaskScheduler(TaskScheduler scheduler) {
  this.registrations.stream()
      .map(ServletWebSocketHandlerRegistration::getSockJsServiceRegistration)
      .filter(Objects::nonNull)
      .filter(r -> r.getTaskScheduler() == null)
      .forEach(registration -> registration.setTaskScheduler(scheduler));
}
origin: Vedenin/useful-java-links

/** 8. Using Java 8 Stream Api parallel **/
@Benchmark
public long test8_UsingJava8StreamApiParallel() throws IOException {
  final long[] i = {0};
  map.entrySet().stream().parallel().forEach(e -> i[0] += e.getKey() + e.getValue());
  return i[0];
}
origin: prestodb/presto

private static List<Type> toTypes(List<Type> groupByTypes, List<Aggregator> aggregates)
{
  ImmutableList.Builder<Type> builder = ImmutableList.builder();
  builder.addAll(groupByTypes);
  aggregates.stream()
      .map(Aggregator::getType)
      .forEach(builder::add);
  return builder.build();
}
origin: SonarSource/sonarqube

private static void validatePropertySet(SetRequest request, @Nullable PropertyDefinition definition) {
 checkRequest(definition != null, "Setting '%s' is undefined", request.getKey());
 checkRequest(PropertyType.PROPERTY_SET.equals(definition.type()), "Parameter '%s' is used for setting of property set type only", PARAM_FIELD_VALUES);
 Set<String> fieldKeys = definition.fields().stream().map(PropertyFieldDefinition::key).collect(Collectors.toSet());
 ListMultimap<String, String> valuesByFieldKeys = ArrayListMultimap.create(fieldKeys.size(), request.getFieldValues().size() * fieldKeys.size());
 request.getFieldValues().stream()
  .map(oneFieldValues -> readOneFieldValues(oneFieldValues, request.getKey()))
  .peek(map -> checkRequest(map.values().stream().anyMatch(StringUtils::isNotBlank), MSG_NO_EMPTY_VALUE))
  .flatMap(map -> map.entrySet().stream())
  .peek(entry -> valuesByFieldKeys.put(entry.getKey(), entry.getValue()))
  .forEach(entry -> checkRequest(fieldKeys.contains(entry.getKey()), "Unknown field key '%s' for setting '%s'", entry.getKey(), request.getKey()));
 checkFieldType(request, definition, valuesByFieldKeys);
}
origin: jenkinsci/jenkins

private void parseFileIntoList(List<String> lines, Set<String> whitelist, Set<String> blacklist){
  lines.stream()
      .filter(line -> !line.matches("#.*|\\s*"))
      .forEach(line -> {
        if (line.startsWith("!")) {
          String withoutExclamation = line.substring(1);
          if (!withoutExclamation.isEmpty()) {
            blacklist.add(withoutExclamation);
          }
        } else {
          whitelist.add(line);
        }
      });
}

origin: prestodb/presto

private List<Symbol> getPushedDownGroupingSet(AggregationNode aggregation, Set<Symbol> availableSymbols, Set<Symbol> requiredJoinSymbols)
{
  List<Symbol> groupingSet = aggregation.getGroupingKeys();
  // keep symbols that are directly from the join's child (availableSymbols)
  List<Symbol> pushedDownGroupingSet = groupingSet.stream()
      .filter(availableSymbols::contains)
      .collect(Collectors.toList());
  // add missing required join symbols to grouping set
  Set<Symbol> existingSymbols = new HashSet<>(pushedDownGroupingSet);
  requiredJoinSymbols.stream()
      .filter(existingSymbols::add)
      .forEach(pushedDownGroupingSet::add);
  return pushedDownGroupingSet;
}
origin: spring-projects/spring-framework

  private static <K,V> void copy(MultiValueMap<K,V> src, MultiValueMap<K,V> dst) {
    if (!src.isEmpty()) {
      src.entrySet().stream()
          .filter(entry -> !dst.containsKey(entry.getKey()))
          .forEach(entry -> dst.put(entry.getKey(), entry.getValue()));
    }
  }
}
origin: Graylog2/graylog2-server

@Override
public void upgrade() {
  this.indexSetService.findAll()
    .stream()
    .map(mongoIndexSetFactory::create)
    .flatMap(indexSet -> getReopenedIndices(indexSet).stream())
    .map(indexName -> { LOG.debug("Marking index {} to be reopened using alias.", indexName); return indexName; })
    .forEach(indices::markIndexReopened);
}
origin: lets-blade/blade

public String parsePath(String path) {
  if (StringKit.isBlank(path)) return path;
  String[] pathModule = path.split("/");
  Arrays.stream(pathModule)
      .filter(row -> !row.isEmpty())
      .map(this::rowToPath)
      .forEach(this::join);
  pathBuilder.deleteCharAt(pathBuilder.length() - 1);
  return build(true);
}
origin: spring-projects/spring-framework

@Override
protected void applyCookies() {
  getCookies().values().stream().flatMap(Collection::stream)
      .map(cookie -> new DefaultCookie(cookie.getName(), cookie.getValue()))
      .forEach(this.request::addCookie);
}
origin: spring-projects/spring-framework

/**
 * Create a new {@link MockMultipartHttpServletRequest} based on the
 * supplied {@code ServletContext} and the {@code MockMultipartFiles}
 * added to this builder.
 */
@Override
protected final MockHttpServletRequest createServletRequest(ServletContext servletContext) {
  MockMultipartHttpServletRequest request = new MockMultipartHttpServletRequest(servletContext);
  this.files.stream().forEach(request::addFile);
  this.parts.values().stream().flatMap(Collection::stream).forEach(request::addPart);
  if (!this.parts.isEmpty()) {
    new StandardMultipartHttpServletRequest(request)
        .getMultiFileMap().values().stream().flatMap(Collection::stream)
        .forEach(request::addFile);
  }
  return request;
}
origin: spring-projects/spring-framework

public void setCookies(@Nullable Cookie... cookies) {
  this.cookies = (ObjectUtils.isEmpty(cookies) ? null : cookies);
  this.headers.remove(HttpHeaders.COOKIE);
  if (this.cookies != null) {
    Arrays.stream(this.cookies)
        .map(c -> c.getName() + '=' + (c.getValue() == null ? "" : c.getValue()))
        .forEach(value -> doAddHeaderValue(HttpHeaders.COOKIE, value, false));
  }
}
origin: spring-projects/spring-framework

@Nullable
private Collection<CacheOperation> parseCacheAnnotations(
    DefaultCacheConfig cachingConfig, AnnotatedElement ae, boolean localOnly) {
  Collection<? extends Annotation> anns = (localOnly ?
      AnnotatedElementUtils.getAllMergedAnnotations(ae, CACHE_OPERATION_ANNOTATIONS) :
      AnnotatedElementUtils.findAllMergedAnnotations(ae, CACHE_OPERATION_ANNOTATIONS));
  if (anns.isEmpty()) {
    return null;
  }
  final Collection<CacheOperation> ops = new ArrayList<>(1);
  anns.stream().filter(ann -> ann instanceof Cacheable).forEach(
      ann -> ops.add(parseCacheableAnnotation(ae, cachingConfig, (Cacheable) ann)));
  anns.stream().filter(ann -> ann instanceof CacheEvict).forEach(
      ann -> ops.add(parseEvictAnnotation(ae, cachingConfig, (CacheEvict) ann)));
  anns.stream().filter(ann -> ann instanceof CachePut).forEach(
      ann -> ops.add(parsePutAnnotation(ae, cachingConfig, (CachePut) ann)));
  anns.stream().filter(ann -> ann instanceof Caching).forEach(
      ann -> parseCachingAnnotation(ae, cachingConfig, (Caching) ann, ops));
  return ops;
}
origin: stanfordnlp/CoreNLP

public SortedMap<String, Double> getWeightVector() {
 SortedMap<String, Double> m = new TreeMap<>((f1, f2) -> {
  double weightDifference = Math.abs(weights.getCount(f2)) - Math.abs(weights.getCount(f1));
  return weightDifference == 0 ? f1.compareTo(f2) : (int) Math.signum(weightDifference);
 });
 weights.entrySet().stream().forEach(e -> m.put(e.getKey(), e.getValue()));
 return m;
}
origin: ctripcorp/apollo

@Override
public List<UserInfo> findByUserIds(List<String> userIds) {
 if (CollectionUtils.isEmpty(userIds)) {
  return null;
 } else {
  ContainerCriteria criteria = query().where(loginIdAttrName).is(userIds.get(0));
  userIds.stream().skip(1).forEach(userId -> criteria.or(loginIdAttrName).is(userId));
  return ldapTemplate.search(ldapQueryCriteria().and(criteria), ldapUserInfoMapper);
 }
}
origin: google/error-prone

public void setEnableAllChecksAsWarnings(boolean enableAllChecksAsWarnings) {
 // Checks manually disabled before this flag are reset to warning-level
 severityMap.entrySet().stream()
   .filter(e -> e.getValue() == Severity.OFF)
   .forEach(e -> e.setValue(Severity.WARN));
 this.enableAllChecksAsWarnings = enableAllChecksAsWarnings;
}
origin: hs-web/hsweb-framework

public static <T> void registerQuerySuppiler(Class<T> type, Function<T, Query<T, QueryParamEntity>> querySupplier) {
  validatorCache.computeIfAbsent(type, instrance::createValidator)
      .values()
      .stream()
      .filter(DefaultValidator.class::isInstance)
      .map(DefaultValidator.class::cast)
      .forEach(validator -> validator.querySupplier = querySupplier);
}
java.util.streamStreamforEach

Javadoc

Performs an action for each element of this stream.

This is a terminal operation.

The behavior of this operation is explicitly nondeterministic. For parallel stream pipelines, this operation does not guarantee to respect the encounter order of the stream, as doing so would sacrifice the benefit of parallelism. For any given element, the action may be performed at whatever time and in whatever thread the library chooses. If the action accesses shared state, it is responsible for providing the required synchronization.

Popular methods of Stream

  • collect
  • map
  • filter
  • findFirst
  • of
  • anyMatch
  • flatMap
  • sorted
  • toArray
  • findAny
  • count
  • allMatch
  • count,
  • allMatch,
  • concat,
  • reduce,
  • mapToInt,
  • distinct,
  • empty,
  • noneMatch,
  • iterator

Popular in Java

  • Start an intent from android
  • onRequestPermissionsResult (Fragment)
  • addToBackStack (FragmentTransaction)
  • findViewById (Activity)
  • Point (java.awt)
    A point representing a location in (x,y) coordinate space, specified in integer precision.
  • LinkedHashMap (java.util)
    LinkedHashMap is an implementation of Map that guarantees iteration order. All optional operations a
  • ConcurrentHashMap (java.util.concurrent)
    A plug-in replacement for JDK1.5 java.util.concurrent.ConcurrentHashMap. This version is based on or
  • Pattern (java.util.regex)
    Patterns are compiled regular expressions. In many cases, convenience methods such as String#matches
  • ServletException (javax.servlet)
    Defines a general exception a servlet can throw when it encounters difficulty.
  • Logger (org.apache.log4j)
    This is the central class in the log4j package. Most logging operations, except configuration, are d
  • Top PhpStorm plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now