Refact iterator of Map with Java 8 forEach

See gh-1451
This commit is contained in:
diguage
2017-06-06 01:03:44 +08:00
committed by Stephane Nicoll
parent 5df053c44b
commit dab7a7f0ee
37 changed files with 117 additions and 184 deletions

View File

@@ -118,14 +118,12 @@ public class SimpleAliasRegistry implements AliasRegistry {
* @param result the resulting aliases list
*/
private void retrieveAliases(String name, List<String> result) {
for (Map.Entry<String, String> entry : this.aliasMap.entrySet()) {
String registeredName = entry.getValue();
this.aliasMap.forEach((alias, registeredName) -> {
if (registeredName.equals(name)) {
String alias = entry.getKey();
result.add(alias);
retrieveAliases(alias, result);
}
}
});
}
/**

View File

@@ -580,9 +580,7 @@ public class AnnotatedElementUtils {
public Object process(@Nullable AnnotatedElement annotatedElement, Annotation annotation, int metaDepth) {
AnnotationAttributes annotationAttributes = AnnotationUtils.getAnnotationAttributes(
annotation, classValuesAsString, nestedAnnotationsAsMap);
for (Map.Entry<String, Object> entry : annotationAttributes.entrySet()) {
attributesMap.add(entry.getKey(), entry.getValue());
}
annotationAttributes.forEach(attributesMap::add);
return CONTINUE;
}
});

View File

@@ -147,9 +147,7 @@ public class MethodMetadataReadingVisitor extends MethodVisitor implements Metho
for (AnnotationAttributes annotationAttributes : attributesList) {
AnnotationAttributes convertedAttributes = AnnotationReadingVisitorUtils.convertClassValues(
"method '" + getMethodName() + "'", this.classLoader, annotationAttributes, classValuesAsString);
for (Map.Entry<String, Object> entry : convertedAttributes.entrySet()) {
allAttributes.add(entry.getKey(), entry.getValue());
}
convertedAttributes.forEach((attrName, attrValue) -> allAttributes.add(attrName, attrValue));
}
}
return allAttributes;

View File

@@ -175,12 +175,10 @@ public class MimeType implements Comparable<MimeType>, Serializable {
this.subtype = subtype.toLowerCase(Locale.ENGLISH);
if (!CollectionUtils.isEmpty(parameters)) {
Map<String, String> map = new LinkedCaseInsensitiveMap<>(parameters.size(), Locale.ENGLISH);
for (Map.Entry<String, String> entry : parameters.entrySet()) {
String attribute = entry.getKey();
String value = entry.getValue();
parameters.forEach((attribute, value) -> {
checkParameters(attribute, value);
map.put(attribute, value);
}
});
this.parameters = Collections.unmodifiableMap(map);
}
else {
@@ -456,12 +454,12 @@ public class MimeType implements Comparable<MimeType>, Serializable {
}
private void appendTo(Map<String, String> map, StringBuilder builder) {
for (Map.Entry<String, String> entry : map.entrySet()) {
builder.append(';');
builder.append(entry.getKey());
map.forEach((key, val) -> {
builder.append(";");
builder.append(key);
builder.append('=');
builder.append(entry.getValue());
}
builder.append(val);
});
}
/**

View File

@@ -99,9 +99,7 @@ public class SimpleNamespaceContext implements NamespaceContext {
* The supplied map must consist of string key value pairs.
*/
public void setBindings(Map<String, String> bindings) {
for (Map.Entry<String, String> entry : bindings.entrySet()) {
bindNamespaceUri(entry.getKey(), entry.getValue());
}
bindings.forEach(this::bindNamespaceUri);
}
/**

View File

@@ -99,11 +99,10 @@ class StaxEventHandler extends AbstractStaxHandler {
private List<Namespace> getNamespaces(Map<String, String> namespaceMapping) {
List<Namespace> result = new ArrayList<>();
for (Map.Entry<String, String> entry : namespaceMapping.entrySet()) {
String prefix = entry.getKey();
String namespaceUri = entry.getValue();
result.add(this.eventFactory.createNamespace(prefix, namespaceUri));
}
namespaceMapping.forEach(
(prefix, namespaceUri)
-> result.add(this.eventFactory.createNamespace(prefix, namespaceUri))
);
return result;
}