Commit 93ef7951 authored by Andy Wilkinson's avatar Andy Wilkinson

More use entrySet() rather than using keySet() and get(key)

This commit replaces some more occurrances of keySet() and get(key)
with more efficient usage of the map's entry set.

See gh-4813
parent 8f1f8dd6
/* /*
* Copyright 2012-2014 the original author or authors. * Copyright 2012-2016 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -36,6 +36,7 @@ import org.springframework.web.servlet.handler.AbstractUrlHandlerMapping; ...@@ -36,6 +36,7 @@ import org.springframework.web.servlet.handler.AbstractUrlHandlerMapping;
* {@link Endpoint} to expose Spring MVC mappings. * {@link Endpoint} to expose Spring MVC mappings.
* *
* @author Dave Syer * @author Dave Syer
* @author Andy Wilkinson
*/ */
@ConfigurationProperties(prefix = "endpoints.mappings", ignoreUnknownFields = false) @ConfigurationProperties(prefix = "endpoints.mappings", ignoreUnknownFields = false)
public class RequestMappingEndpoint extends AbstractEndpoint<Map<String, Object>> public class RequestMappingEndpoint extends AbstractEndpoint<Map<String, Object>>
...@@ -84,20 +85,19 @@ public class RequestMappingEndpoint extends AbstractEndpoint<Map<String, Object> ...@@ -84,20 +85,19 @@ public class RequestMappingEndpoint extends AbstractEndpoint<Map<String, Object>
return result; return result;
} }
@SuppressWarnings("rawtypes")
protected void extractMethodMappings(ApplicationContext applicationContext, protected void extractMethodMappings(ApplicationContext applicationContext,
Map<String, Object> result) { Map<String, Object> result) {
if (applicationContext != null) { if (applicationContext != null) {
for (String name : applicationContext for (Entry<String, AbstractHandlerMethodMapping> bean : applicationContext
.getBeansOfType(AbstractHandlerMethodMapping.class).keySet()) { .getBeansOfType(AbstractHandlerMethodMapping.class).entrySet()) {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Map<?, HandlerMethod> methods = applicationContext Map<?, HandlerMethod> methods = bean.getValue().getHandlerMethods();
.getBean(name, AbstractHandlerMethodMapping.class)
.getHandlerMethods();
for (Entry<?, HandlerMethod> method : methods.entrySet()) { for (Entry<?, HandlerMethod> method : methods.entrySet()) {
Map<String, String> map = new LinkedHashMap<String, String>(); Map<String, String> map = new LinkedHashMap<String, String>();
map.put("bean", name); map.put("bean", bean.getKey());
map.put("method", method.getValue().toString()); map.put("method", method.getValue().toString());
result.put( method.getKey().toString(), map); result.put(method.getKey().toString(), map);
} }
} }
} }
......
/* /*
* Copyright 2012-2015 the original author or authors. * Copyright 2012-2016 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -23,11 +23,15 @@ import java.util.Comparator; ...@@ -23,11 +23,15 @@ import java.util.Comparator;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry;
import java.util.SortedSet;
import java.util.TreeSet;
/** /**
* A helper class generating a report from the meta-data of a particular service. * A helper class generating a report from the meta-data of a particular service.
* *
* @author Stephane Nicoll * @author Stephane Nicoll
* @author Andy Wilkinson
* @since 1.2.0 * @since 1.2.0
*/ */
class ServiceCapabilitiesReportGenerator { class ServiceCapabilitiesReportGenerator {
...@@ -104,11 +108,20 @@ class ServiceCapabilitiesReportGenerator { ...@@ -104,11 +108,20 @@ class ServiceCapabilitiesReportGenerator {
StringBuilder report) { StringBuilder report) {
report.append("Available project types:" + NEW_LINE); report.append("Available project types:" + NEW_LINE);
report.append("------------------------" + NEW_LINE); report.append("------------------------" + NEW_LINE);
List<String> typeIds = new ArrayList<String>(metadata.getProjectTypes().keySet()); SortedSet<Entry<String, ProjectType>> entries = new TreeSet<Entry<String, ProjectType>>(
Collections.sort(typeIds); new Comparator<Entry<String, ProjectType>>() {
for (String typeId : typeIds) {
ProjectType type = metadata.getProjectTypes().get(typeId); @Override
report.append(typeId + " - " + type.getName()); public int compare(Entry<String, ProjectType> o1,
Entry<String, ProjectType> o2) {
return o1.getKey().compareTo(o2.getKey());
}
});
entries.addAll(metadata.getProjectTypes().entrySet());
for (Entry<String, ProjectType> entry : entries) {
ProjectType type = entry.getValue();
report.append(entry.getKey() + " - " + type.getName());
if (!type.getTags().isEmpty()) { if (!type.getTags().isEmpty()) {
reportTags(report, type); reportTags(report, type);
} }
......
/* /*
* Copyright 2012-2013 the original author or authors. * Copyright 2012-2016 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -19,6 +19,7 @@ package org.springframework.boot.maven; ...@@ -19,6 +19,7 @@ package org.springframework.boot.maven;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.List; import java.util.List;
import java.util.Map.Entry;
import java.util.Properties; import java.util.Properties;
import java.util.jar.JarEntry; import java.util.jar.JarEntry;
import java.util.jar.JarOutputStream; import java.util.jar.JarOutputStream;
...@@ -32,6 +33,7 @@ import org.apache.maven.plugins.shade.resource.ResourceTransformer; ...@@ -32,6 +33,7 @@ import org.apache.maven.plugins.shade.resource.ResourceTransformer;
* to be merged without losing any information. * to be merged without losing any information.
* *
* @author Dave Syer * @author Dave Syer
* @author Andy Wilkinson
*/ */
public class PropertiesMergingResourceTransformer implements ResourceTransformer { public class PropertiesMergingResourceTransformer implements ResourceTransformer {
...@@ -62,9 +64,9 @@ public class PropertiesMergingResourceTransformer implements ResourceTransformer ...@@ -62,9 +64,9 @@ public class PropertiesMergingResourceTransformer implements ResourceTransformer
Properties properties = new Properties(); Properties properties = new Properties();
properties.load(is); properties.load(is);
is.close(); is.close();
for (Object key : properties.keySet()) { for (Entry<Object, Object> entry : properties.entrySet()) {
String name = (String) key; String name = (String) entry.getKey();
String value = properties.getProperty(name); String value = (String) entry.getValue();
String existing = this.data.getProperty(name); String existing = this.data.getProperty(name);
this.data.setProperty(name, this.data.setProperty(name,
existing == null ? value : existing + "," + value); existing == null ? value : existing + "," + value);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment