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

How to use
forEach
method
in
java.util.Map

Best Java code snippets using java.util.Map.forEach (Showing top 20 results out of 24,426)

Refine searchRefine arrow

  • Map.put
  • Map.get
  • List.add
  • Map.size
  • Stream.collect
origin: spring-projects/spring-framework

@Override
public Map<String, String> toSingleValueMap() {
  LinkedHashMap<String, String> singleValueMap = new LinkedHashMap<>(this.headers.size());
  this.headers.forEach((key, value) -> singleValueMap.put(key, value.get(0)));
  return singleValueMap;
}
origin: spring-projects/spring-framework

/**
 * Specify mappings from type ids to Java classes, if desired.
 * This allows for synthetic ids in the type id message property,
 * instead of transferring Java class names.
 * <p>Default is no custom mappings, i.e. transferring raw Java class names.
 * @param typeIdMappings a Map with type id values as keys and Java classes as values
 */
public void setTypeIdMappings(Map<String, Class<?>> typeIdMappings) {
  this.idClassMappings = new HashMap<>();
  typeIdMappings.forEach((id, clazz) -> {
    this.idClassMappings.put(id, clazz);
    this.classIdMappings.put(clazz, id);
  });
}
origin: spring-projects/spring-framework

private StompHeaders(Map<String, List<String>> headers, boolean readOnly) {
  Assert.notNull(headers, "'headers' must not be null");
  if (readOnly) {
    Map<String, List<String>> map = new LinkedMultiValueMap<>(headers.size());
    headers.forEach((key, value) -> map.put(key, Collections.unmodifiableList(value)));
    this.headers = Collections.unmodifiableMap(map);
  }
  else {
    this.headers = headers;
  }
}
origin: spring-projects/spring-framework

@SuppressWarnings({"unchecked", "rawtypes"})
private void merge(Map<String, Object> output, Map<String, Object> map) {
  map.forEach((key, value) -> {
    Object existing = output.get(key);
    if (value instanceof Map && existing instanceof Map) {
      // Inner cast required by Eclipse IDE.
      Map<String, Object> result = new LinkedHashMap<>((Map<String, Object>) existing);
      merge(result, (Map) value);
      output.put(key, result);
    }
    else {
      output.put(key, value);
    }
  });
}
origin: spring-projects/spring-framework

/**
 * Create an instance with the given map of file extensions and media types.
 */
public MappingMediaTypeFileExtensionResolver(@Nullable Map<String, MediaType> mediaTypes) {
  if (mediaTypes != null) {
    mediaTypes.forEach((extension, mediaType) -> {
      String lowerCaseExtension = extension.toLowerCase(Locale.ENGLISH);
      this.mediaTypes.put(lowerCaseExtension, mediaType);
      this.fileExtensions.add(mediaType, lowerCaseExtension);
      this.allFileExtensions.add(lowerCaseExtension);
    });
  }
}
origin: spring-projects/spring-framework

private WebDataBinderFactory getDataBinderFactory(HandlerMethod handlerMethod) throws Exception {
  Class<?> handlerType = handlerMethod.getBeanType();
  Set<Method> methods = this.initBinderCache.get(handlerType);
  if (methods == null) {
    methods = MethodIntrospector.selectMethods(handlerType, INIT_BINDER_METHODS);
    this.initBinderCache.put(handlerType, methods);
  }
  List<InvocableHandlerMethod> initBinderMethods = new ArrayList<>();
  // Global methods first
  this.initBinderAdviceCache.forEach((clazz, methodSet) -> {
    if (clazz.isApplicableToBeanType(handlerType)) {
      Object bean = clazz.resolveBean();
      for (Method method : methodSet) {
        initBinderMethods.add(createInitBinderMethod(bean, method));
      }
    }
  });
  for (Method method : methods) {
    Object bean = handlerMethod.getBean();
    initBinderMethods.add(createInitBinderMethod(bean, method));
  }
  return createDataBinderFactory(initBinderMethods);
}
origin: spring-projects/spring-framework

private List<Namespace> getNamespaces(Map<String, String> namespaceMappings) {
  List<Namespace> result = new ArrayList<>(namespaceMappings.size());
  namespaceMappings.forEach((prefix, namespaceUri) ->
      result.add(this.eventFactory.createNamespace(prefix, namespaceUri)));
  return result;
}
origin: spring-projects/spring-framework

    String parameterNameToMatch = provider.parameterNameToUse(parameterName);
    if (parameterNameToMatch != null) {
      callParameterNames.put(parameterNameToMatch.toLowerCase(), parameterName);
Map<String, Object> matchedParameters = new HashMap<>(inParameters.size());
inParameters.forEach((parameterName, parameterValue) -> {
  String parameterNameToMatch = provider.parameterNameToUse(parameterName);
  String callParameterName = callParameterNames.get(lowerCase(parameterNameToMatch));
  if (callParameterName == null) {
    if (logger.isDebugEnabled()) {
    matchedParameters.put(callParameterName, parameterValue);
if (matchedParameters.size() < callParameterNames.size()) {
  for (String parameterName : callParameterNames.keySet()) {
    String parameterNameToMatch = provider.parameterNameToUse(parameterName);
    String callParameterName = callParameterNames.get(lowerCase(parameterNameToMatch));
    if (!matchedParameters.containsKey(callParameterName) && logger.isInfoEnabled()) {
      logger.info("Unable to locate the corresponding parameter value for '" + parameterName +
origin: prestodb/presto

public synchronized MemoryPoolInfo getInfo()
{
  Map<QueryId, List<MemoryAllocation>> memoryAllocations = new HashMap<>();
  for (Entry<QueryId, Map<String, Long>> entry : taggedMemoryAllocations.entrySet()) {
    List<MemoryAllocation> allocations = new ArrayList<>();
    if (entry.getValue() != null) {
      entry.getValue().forEach((tag, allocation) -> allocations.add(new MemoryAllocation(tag, allocation)));
    }
    memoryAllocations.put(entry.getKey(), allocations);
  }
  return new MemoryPoolInfo(maxBytes, reservedBytes, reservedRevocableBytes, queryMemoryReservations, memoryAllocations, queryMemoryRevocableReservations);
}
origin: apache/incubator-druid

 public List<String> getCurrentlyProcessingSegmentsAndHosts(String tier)
 {
  Map<SegmentId, String> segments = currentlyProcessingSegments.get(tier);
  List<String> retVal = new ArrayList<>();
  segments.forEach((segmentId, serverId) -> retVal.add(StringUtils.format("%s ON %s", segmentId, serverId)));
  return retVal;
 }
}
origin: spring-projects/spring-framework

protected final MultiValueMap<String, String> getParamsMultiValueMap(MockHttpServletRequest request) {
  Map<String, String[]> params = request.getParameterMap();
  MultiValueMap<String, String> multiValueMap = new LinkedMultiValueMap<>();
  params.forEach((name, values) -> {
    if (params.get(name) != null) {
      for (String value : values) {
        multiValueMap.add(name, value);
      }
    }
  });
  return multiValueMap;
}
origin: prestodb/presto

private static Map<String, Map<ColumnStatisticType, Block>> createColumnToComputedStatisticsMap(Map<ColumnStatisticMetadata, Block> computedStatistics)
{
  Map<String, Map<ColumnStatisticType, Block>> result = new HashMap<>();
  computedStatistics.forEach((metadata, block) -> {
    Map<ColumnStatisticType, Block> columnStatistics = result.computeIfAbsent(metadata.getColumnName(), key -> new HashMap<>());
    columnStatistics.put(metadata.getStatisticType(), block);
  });
  return result.entrySet()
      .stream()
      .collect(toImmutableMap(Entry::getKey, entry -> ImmutableMap.copyOf(entry.getValue())));
}
origin: spring-projects/spring-framework

@Test
public void enrichAndValidateAttributesWithSingleElementThatOverridesAnArray() {
  Map<String, Object> attributes = new HashMap<String, Object>() {{
    // Intentionally storing 'value' as a single String instead of an array.
    // put("value", asArray("/foo"));
    put("value", "/foo");
    put("name", "test");
  }};
  Map<String, Object> expected = new HashMap<String, Object>() {{
    put("value", asArray("/foo"));
    put("path", asArray("/foo"));
    put("name", "test");
    put("method", new RequestMethod[0]);
  }};
  MapAnnotationAttributeExtractor extractor = new MapAnnotationAttributeExtractor(attributes, WebMapping.class, null);
  Map<String, Object> enriched = extractor.getSource();
  assertEquals("attribute map size", expected.size(), enriched.size());
  expected.forEach((attr, expectedValue) -> assertThat("for attribute '" + attr + "'", enriched.get(attr), is(expectedValue)));
}
origin: neo4j/neo4j

public void forEach( BiConsumer<String,URI> consumer )
{
  entries.stream().collect( Collectors.groupingBy( e -> e.key ) )
      .forEach( ( key, list ) -> list.stream()
          .max( Comparator.comparing( e -> e.precedence ) )
          .ifPresent( e -> consumer.accept( key, e.uri ) ) );
}
origin: signalapp/Signal-Server

private void addTallyMaps(Map<String, long[]> tallyMap, Map<String, long[]> incrementMap) {
 incrementMap.forEach((key, increments) -> {
   long[] tallies = tallyMap.get(key);
   if (tallies == null) {
    tallyMap.put(key, increments);
   } else {
    for (int i = 0; i < INTERVALS.length; i++) {
     tallies[i] += increments[i];
    }
   }
  });
}
origin: spring-projects/spring-framework

/**
 * Transitively retrieve all aliases for the given name.
 * @param name the target name to find aliases for
 * @param result the resulting aliases list
 */
private void retrieveAliases(String name, List<String> result) {
  this.aliasMap.forEach((alias, registeredName) -> {
    if (registeredName.equals(name)) {
      result.add(alias);
      retrieveAliases(alias, result);
    }
  });
}
origin: spring-projects/spring-framework

private ModelFactory getModelFactory(HandlerMethod handlerMethod, WebDataBinderFactory binderFactory) {
  SessionAttributesHandler sessionAttrHandler = getSessionAttributesHandler(handlerMethod);
  Class<?> handlerType = handlerMethod.getBeanType();
  Set<Method> methods = this.modelAttributeCache.get(handlerType);
  if (methods == null) {
    methods = MethodIntrospector.selectMethods(handlerType, MODEL_ATTRIBUTE_METHODS);
    this.modelAttributeCache.put(handlerType, methods);
  }
  List<InvocableHandlerMethod> attrMethods = new ArrayList<>();
  // Global methods first
  this.modelAttributeAdviceCache.forEach((clazz, methodSet) -> {
    if (clazz.isApplicableToBeanType(handlerType)) {
      Object bean = clazz.resolveBean();
      for (Method method : methodSet) {
        attrMethods.add(createModelAttributeMethod(binderFactory, bean, method));
      }
    }
  });
  for (Method method : methods) {
    Object bean = handlerMethod.getBean();
    attrMethods.add(createModelAttributeMethod(binderFactory, bean, method));
  }
  return new ModelFactory(attrMethods, binderFactory, sessionAttrHandler);
}
origin: spring-projects/spring-framework

/**
 * Copy constructor which allows for ignoring certain entries.
 * Used for serialization without non-serializable entries.
 * @param original the MessageHeaders to copy
 * @param keysToIgnore the keys of the entries to ignore
 */
private MessageHeaders(MessageHeaders original, Set<String> keysToIgnore) {
  this.headers = new HashMap<>(original.headers.size());
  original.headers.forEach((key, value) -> {
    if (!keysToIgnore.contains(key)) {
      this.headers.put(key, value);
    }
  });
}
origin: spring-projects/spring-framework

/**
 * Construct a new MutablePropertyValues object from a Map.
 * @param original a Map with property values keyed by property name Strings
 * @see #addPropertyValues(Map)
 */
public MutablePropertyValues(@Nullable Map<?, ?> original) {
  // We can optimize this because it's all new:
  // There is no replacement of existing property values.
  if (original != null) {
    this.propertyValueList = new ArrayList<>(original.size());
    original.forEach((attrName, attrValue) -> this.propertyValueList.add(
        new PropertyValue(attrName.toString(), attrValue)));
  }
  else {
    this.propertyValueList = new ArrayList<>(0);
  }
}
origin: spring-projects/spring-framework

public void setNotificationInfoMappings(Map<String, Object> notificationInfoMappings) {
  notificationInfoMappings.forEach((beanKey, result) ->
      this.notificationInfoMappings.put(beanKey, extractNotificationMetadata(result)));
}
java.utilMapforEach

Popular methods of Map

  • put
    Maps the specified key to the specified value.
  • get
  • entrySet
    Returns a Set view of the mappings contained in this map. The set is backed by the map, so changes t
  • containsKey
    Returns whether this Map contains the specified key.
  • keySet
    Returns a set of the keys contained in this Map. The Set is backed by this Map so changes to one are
  • values
    Returns a Collection view of the values contained in this map. The collection is backed by the map,
  • remove
  • size
    Returns the number of mappings in this Map.
  • isEmpty
    Returns true if this map contains no key-value mappings.
  • clear
    Removes all elements from this Map, leaving it empty.
  • putAll
    Copies all of the mappings from the specified map to this map (optional operation). The effect of th
  • equals
    Compares the argument to the receiver, and returns true if the specified object is a Map and both Ma
  • putAll,
  • equals,
  • computeIfAbsent,
  • hashCode,
  • getOrDefault,
  • containsValue,
  • putIfAbsent,
  • compute,
  • merge

Popular in Java

  • Making http post requests using okhttp
  • getContentResolver (Context)
  • getResourceAsStream (ClassLoader)
  • findViewById (Activity)
  • Thread (java.lang)
    A thread is a thread of execution in a program. The Java Virtual Machine allows an application to ha
  • ServerSocket (java.net)
    This class represents a server-side socket that waits for incoming client connections. A ServerSocke
  • Locale (java.util)
    Locale represents a language/country/variant combination. Locales are used to alter the presentatio
  • Set (java.util)
    A Set is a data structure which does not allow duplicate elements.
  • Stack (java.util)
    Stack is a Last-In/First-Out(LIFO) data structure which represents a stack of objects. It enables u
  • LogFactory (org.apache.commons.logging)
    Factory for creating Log instances, with discovery and configuration features similar to that employ
  • Top Sublime Text 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