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
This commit is contained in:
Andy Wilkinson
2016-01-15 16:58:21 +00:00
parent 8f1f8dd680
commit 93ef795159
3 changed files with 34 additions and 19 deletions

View File

@@ -1,5 +1,5 @@
/*
* 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");
* you may not use this file except in compliance with the License.
@@ -23,11 +23,15 @@ import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
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.
*
* @author Stephane Nicoll
* @author Andy Wilkinson
* @since 1.2.0
*/
class ServiceCapabilitiesReportGenerator {
@@ -104,11 +108,20 @@ class ServiceCapabilitiesReportGenerator {
StringBuilder report) {
report.append("Available project types:" + NEW_LINE);
report.append("------------------------" + NEW_LINE);
List<String> typeIds = new ArrayList<String>(metadata.getProjectTypes().keySet());
Collections.sort(typeIds);
for (String typeId : typeIds) {
ProjectType type = metadata.getProjectTypes().get(typeId);
report.append(typeId + " - " + type.getName());
SortedSet<Entry<String, ProjectType>> entries = new TreeSet<Entry<String, ProjectType>>(
new Comparator<Entry<String, ProjectType>>() {
@Override
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()) {
reportTags(report, type);
}