Use Java 8 forEach method on Map

This commit is contained in:
Jon Borenstein
2017-04-25 18:00:38 -04:00
committed by Stephane Nicoll
parent 1ea54eb2c6
commit 13dc0cd828
8 changed files with 29 additions and 34 deletions

View File

@@ -106,11 +106,11 @@ public abstract class ClassUtils {
primitiveWrapperTypeMap.put(Integer.class, int.class);
primitiveWrapperTypeMap.put(Long.class, long.class);
primitiveWrapperTypeMap.put(Short.class, short.class);
for (Map.Entry<Class<?>, Class<?>> entry : primitiveWrapperTypeMap.entrySet()) {
primitiveWrapperTypeMap.entrySet().forEach(entry -> {
primitiveTypeToWrapperMap.put(entry.getValue(), entry.getKey());
registerCommonClasses(entry.getKey());
}
});
Set<Class<?>> primitiveTypes = new HashSet<>(32);
primitiveTypes.addAll(primitiveWrapperTypeMap.values());

View File

@@ -354,10 +354,10 @@ public abstract class CollectionUtils {
public static <K, V> MultiValueMap<K, V> unmodifiableMultiValueMap(MultiValueMap<? extends K, ? extends V> map) {
Assert.notNull(map, "'map' must not be null");
Map<K, List<V>> result = new LinkedHashMap<>(map.size());
for (Map.Entry<? extends K, ? extends List<? extends V>> entry : map.entrySet()) {
map.entrySet().forEach(entry -> {
List<? extends V> values = Collections.unmodifiableList(entry.getValue());
result.put(entry.getKey(), (List<V>) values);
}
});
Map<K, List<V>> unmodifiableMap = Collections.unmodifiableMap(result);
return toMultiValueMap(unmodifiableMap);
}
@@ -431,17 +431,13 @@ public abstract class CollectionUtils {
@Override
public void setAll(Map<K, V> values) {
for (Entry<K, V> entry : values.entrySet()) {
set(entry.getKey(), entry.getValue());
}
values.entrySet().forEach(entry -> set(entry.getKey(), entry.getValue()));
}
@Override
public Map<K, V> toSingleValueMap() {
LinkedHashMap<K, V> singleValueMap = new LinkedHashMap<>(this.map.size());
for (Entry<K, List<V>> entry : map.entrySet()) {
singleValueMap.put(entry.getKey(), entry.getValue().get(0));
}
map.entrySet().forEach(entry -> singleValueMap.put(entry.getKey(), entry.getValue().get(0)));
return singleValueMap;
}

View File

@@ -169,9 +169,8 @@ public class LinkedCaseInsensitiveMap<V> implements Map<String, V>, Serializable
if (map.isEmpty()) {
return;
}
for (Map.Entry<? extends String, ? extends V> entry : map.entrySet()) {
put(entry.getKey(), entry.getValue());
}
map.entrySet().forEach(entry -> put(entry.getKey(), entry.getValue()));
}
@Override

View File

@@ -100,17 +100,15 @@ public class LinkedMultiValueMap<K, V> implements MultiValueMap<K, V>, Serializa
@Override
public void setAll(Map<K, V> values) {
for (Entry<K, V> entry : values.entrySet()) {
set(entry.getKey(), entry.getValue());
}
values.entrySet().forEach(entry -> set(entry.getKey(), entry.getValue()));
}
@Override
public Map<K, V> toSingleValueMap() {
LinkedHashMap<K, V> singleValueMap = new LinkedHashMap<>(this.targetMap.size());
for (Entry<K, List<V>> entry : this.targetMap.entrySet()) {
singleValueMap.put(entry.getKey(), entry.getValue().get(0));
}
this.targetMap.entrySet().forEach(entry ->
singleValueMap.put(entry.getKey(), entry.getValue().get(0)));
return singleValueMap;
}
@@ -186,9 +184,9 @@ public class LinkedMultiValueMap<K, V> implements MultiValueMap<K, V>, Serializa
*/
public LinkedMultiValueMap<K, V> deepCopy() {
LinkedMultiValueMap<K, V> copy = new LinkedMultiValueMap<>(this.targetMap.size());
for (Map.Entry<K, List<V>> entry : this.targetMap.entrySet()) {
copy.put(entry.getKey(), new LinkedList<>(entry.getValue()));
}
this.targetMap.entrySet().forEach(entry ->
copy.put(entry.getKey(), new LinkedList<>(entry.getValue())));
return copy;
}