Skip to content

Commit

Permalink
Iterating on entrySet() instead of keySet() when key and value are ne…
Browse files Browse the repository at this point in the history
…eded
  • Loading branch information
dvmarcilio committed Jul 18, 2019
1 parent 85b62ed commit 0d6105d
Show file tree
Hide file tree
Showing 30 changed files with 153 additions and 97 deletions.
Expand Up @@ -225,8 +225,8 @@ public String toString() {

if (spanTags != null && !spanTags.isEmpty()) {
result.append(",\"spanTags\":[");
for (String key : spanTags.keySet()) {
result.append("{\"").append(key).append("\": \"").append(spanTags.get(key)).append("\"},");
for (Entry<String, String> entry : spanTags.entrySet()) {
result.append("{\"").append(entry.getKey()).append("\": \"").append(entry.getValue()).append("\"},");
}
result.deleteCharAt(result.length() - 1);
result.append("]");
Expand Down
Expand Up @@ -46,6 +46,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

/**
*
Expand Down Expand Up @@ -126,10 +127,10 @@ public static void convertToConfigProperties(HandlerContext handlerCtx) {

if (props != null) {
for (Map<String, String> prop : props) {
for (String key : prop.keySet()) {
if (key.equals("name")) {
if (prop.get(key).toString().contains("payara.microprofile")) {
prop.put(key, prop.get(key).toString().replaceAll("payara.microprofile.", ""));
for (Entry<String, String> entry : prop.entrySet()) {
if (entry.getKey().equals("name")) {
if (entry.getValue().toString().contains("payara.microprofile")) {
prop.put(entry.getKey(), entry.getValue().toString().replaceAll("payara.microprofile.", ""));
convertedProps.add(prop);
}
}
Expand Down Expand Up @@ -159,10 +160,10 @@ public static void convertToMicroProfileProperties(HandlerContext handlerCtx) {

if (props != null) {
for (Map<String, String> prop : props) {
for (String key : prop.keySet()) {
if (key.equals("name")) {
if (!prop.get(key).toString().contains("payara.microprofile.")) {
prop.put(key, "payara.microprofile." + prop.get(key).toString().replaceAll("\\s+", ""));
for (Entry<String, String> entry : prop.entrySet()) {
if (entry.getKey().equals("name")) {
if (!entry.getValue().toString().contains("payara.microprofile.")) {
prop.put(entry.getKey(), "payara.microprofile." + entry.getValue().toString().replaceAll("\\s+", ""));
}
}
}
Expand Down
Expand Up @@ -50,6 +50,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.atomic.AtomicReference;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
Expand Down Expand Up @@ -145,9 +146,10 @@ private static ServiceLocator getHabitat() {
private static NamedNamingObjectProxy getCachedProxy(String name) {
rwLock.readLock().lock();
try {
for (String proxyPrefix : proxies.keySet()) {
for (Entry<String, NamedNamingObjectProxy> entry : proxies.entrySet()) {
String proxyPrefix = entry.getKey();
if (name.startsWith(proxyPrefix)) {
return proxies.get(proxyPrefix);
return entry.getValue();
}
}
} finally {
Expand Down
Expand Up @@ -219,11 +219,11 @@ public void execute(AdminCommandContext context) {
part.setMessage(localStrings.getLocalString("listsubcomponents.no.elements.to.list", "Nothing to List."));
}
int i=0;
for (String key : subComponents.keySet()) {
for (Entry<String, String> entry : subComponents.entrySet()) {
ActionReport.MessagePart childPart = part.addChild();
childPart.setMessage(
String.format(formattedLine,
new Object[]{key, subComponents.get(key)} ));
new Object[]{entry.getKey(), entry.getValue()} ));
if (appname == null && !app.isVirtual()) {
// we use the property mechanism to provide
// support for JSR88 client
Expand All @@ -233,7 +233,7 @@ public void execute(AdminCommandContext context) {
}
}
if (resources) {
Module module = application.getModule(key);
Module module = application.getModule(entry.getKey());
if (module != null) {
ActionReport subReport = report.addSubActionsReport();
CommandRunner.CommandInvocation inv = commandRunner.getCommandInvocation("_list-resources", subReport, context.getSubject());
Expand Down
Expand Up @@ -983,9 +983,10 @@ private List<EjbInterceptor> getClassOrMethodInterceptors(MethodDescriptor busin

List<EjbInterceptor> classOrMethodInterceptors = null;

for (MethodDescriptor methodDesc : methodInterceptorsMap.keySet()) {
for (Entry<MethodDescriptor, List<EjbInterceptor>> entry : methodInterceptorsMap.entrySet()) {
MethodDescriptor methodDesc = entry.getKey();
if (methodDesc.implies(businessMethod)) {
classOrMethodInterceptors = methodInterceptorsMap.get(methodDesc);
classOrMethodInterceptors = entry.getValue();
}
}

Expand Down
Expand Up @@ -350,16 +350,18 @@ public boolean hasRemoveMethods() {
*/
public EjbRemovalInfo getRemovalInfo(MethodDescriptor method) {
// first try to find the exact match
for (MethodDescriptor methodDesc : removeMethods.keySet()) {
for (Entry<MethodDescriptor, EjbRemovalInfo> entry : removeMethods.entrySet()) {
MethodDescriptor methodDesc = entry.getKey();
if (methodDesc.equals(method)) {
return removeMethods.get(methodDesc);
return entry.getValue();
}
}

// if nothing is found, try to find the loose match
for (MethodDescriptor methodDesc : removeMethods.keySet()) {
for (Entry<MethodDescriptor, EjbRemovalInfo> entry : removeMethods.entrySet()) {
MethodDescriptor methodDesc = entry.getKey();
if (methodDesc.implies(method)) {
return removeMethods.get(methodDesc);
return entry.getValue();
}
}

Expand Down
Expand Up @@ -45,6 +45,7 @@
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import com.sun.enterprise.deployment.EjbInterceptor;
Expand Down Expand Up @@ -290,10 +291,11 @@ private TranslationResults buildResults() {
}
}

for(MethodDescriptor nextMethod : methodInterceptorsMap.keySet()) {
for (Entry<MethodDescriptor, List<EjbInterceptor>> entry : methodInterceptorsMap.entrySet()) {
MethodDescriptor nextMethod = entry.getKey();

List<String> interceptorClassChain = (List<String>)
methodInterceptorsMap.get(nextMethod);
entry.getValue();

List<EjbInterceptor> interceptorChain =
new LinkedList<EjbInterceptor>();
Expand Down
Expand Up @@ -32,6 +32,7 @@ and Distribution License("CDDL") (collectively, the "License"). You
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.Callable;
import java.util.concurrent.Future;
import java.util.logging.Level;
Expand Down Expand Up @@ -141,10 +142,11 @@ public Map<InstanceDescriptor, Future<? extends ClusterCommandResult>> run (Stri

Map<String,Future<ClusterCommandResult>> commandResult = instanceService.executeClusteredASAdmin(command, args);
Map<InstanceDescriptor, Future<? extends ClusterCommandResult>> result = new HashMap<>(commandResult.size());
for (String uuid : commandResult.keySet()) {
for (Entry<String,Future<ClusterCommandResult>> entry : commandResult.entrySet()) {
String uuid = entry.getKey();
InstanceDescriptor id = instanceService.getDescriptor(uuid);
if (id != null) {
result.put(id, commandResult.get(uuid));
result.put(id, entry.getValue());
}
}
return result;
Expand All @@ -169,10 +171,11 @@ public Map<InstanceDescriptor, Future<? extends ClusterCommandResult>> run (Coll

Map<String,Future<ClusterCommandResult>> commandResult = instanceService.executeClusteredASAdmin(memberUUIDs,command, args);
Map<InstanceDescriptor, Future<? extends ClusterCommandResult>> result = new HashMap<>(commandResult.size());
for (String uuid : commandResult.keySet()) {
for (Entry<String,Future<ClusterCommandResult>> entry : commandResult.entrySet()) {
String uuid = entry.getKey();
InstanceDescriptor id = instanceService.getDescriptor(uuid);
if (id != null) {
result.put(id, commandResult.get(uuid));
result.put(id, entry.getValue());
}
}
return result;
Expand All @@ -193,10 +196,11 @@ public <T extends Serializable> Map<InstanceDescriptor, Future<T>> run (Callable

Map<String, Future<T>> runCallable = instanceService.runCallable(callable);
Map<InstanceDescriptor, Future<T>> result = new HashMap<>(runCallable.size());
for (String uuid : runCallable.keySet()) {
for (Entry<String, Future<T>> entry : runCallable.entrySet()) {
String uuid = entry.getKey();
InstanceDescriptor id = instanceService.getDescriptor(uuid);
if (id != null) {
result.put(id, runCallable.get(uuid));
result.put(id, entry.getValue());
}
}
return result;
Expand All @@ -221,10 +225,11 @@ public <T extends Serializable> Map<InstanceDescriptor, Future<T>> run (Collecti

Map<String, Future<T>> runCallable = instanceService.runCallable(memberUUIDs,callable);
Map<InstanceDescriptor, Future<T>> result = new HashMap<>(runCallable.size());
for (String uuid : runCallable.keySet()) {
for (Entry<String, Future<T>> entry : runCallable.entrySet()) {
String uuid = entry.getKey();
InstanceDescriptor id = instanceService.getDescriptor(uuid);
if (id != null) {
result.put(id, runCallable.get(uuid));
result.put(id, entry.getValue());
}
}
return result;
Expand Down
Expand Up @@ -59,6 +59,7 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
Expand Down Expand Up @@ -530,8 +531,8 @@ public int migrateTimers(String fromOwnerId) {
}
}

for (String pk : toRestore.keySet()) {
pkCache.put(pk, toRestore.get(pk));
for (Entry<String, HZTimer> entry : toRestore.entrySet()) {
pkCache.put(entry.getKey(), entry.getValue());
totalTimersMigrated++;
}

Expand Down
Expand Up @@ -51,6 +51,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;

import static com.google.common.base.Preconditions.checkState;
Expand Down Expand Up @@ -151,8 +152,9 @@ private Map<String, JsonValue> handleNamespacedClaims(Map<String, JsonValue> cur
if(this.enableNamespacedClaims){
final String namespace = customNamespace.orElse(DEFAULT_NAMESPACE);
Map<String, JsonValue> processedClaims = new HashMap<>(currentClaims.size());
for(String claimName : currentClaims.keySet()){
JsonValue value = currentClaims.get(claimName);
for (Entry<String, JsonValue> entry : currentClaims.entrySet()) {
String claimName = entry.getKey();
JsonValue value = entry.getValue();
if(claimName.startsWith(namespace)){
claimName = claimName.substring(namespace.length());
}
Expand Down
Expand Up @@ -47,6 +47,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
import java.util.Set;
import java.util.TreeMap;
Expand Down Expand Up @@ -208,9 +209,10 @@ public Map<String, Set<String>> getEndpointMap(String appName) {

// loop through jersey components
boolean hasEndpoints = false;
for (ServletContainer jerseyApplication : jerseyApplicationMap.keySet()) {
for (Entry<ServletContainer, String> entry : jerseyApplicationMap.entrySet()) {
ServletContainer jerseyApplication = entry.getKey();
String appRoot = jerseyApplication.getServletContext().getContextPath();
String jerseyAppRoot = jerseyApplicationMap.get(jerseyApplication);
String jerseyAppRoot = entry.getValue();

List<Class<?>> containedClasses = getClasses(jerseyApplication);

Expand Down
Expand Up @@ -51,6 +51,7 @@
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReadWriteLock;
Expand Down Expand Up @@ -230,9 +231,10 @@ public String[] detachListener(RegistrationListener listener, String layer, Stri
String registrationId = getRegistrationID(layer, appContext);

doWriteLocked(() -> {
for (String targetID : idToRegistrationListenersMap.keySet()) {
for (Entry<String, List<RegistrationListener>> entry : idToRegistrationListenersMap.entrySet()) {
String targetID = entry.getKey();
if (regIdImplies(registrationId, targetID)) {
List<RegistrationListener> listeners = idToRegistrationListenersMap.get(targetID);
List<RegistrationListener> listeners = entry.getValue();
if (listeners != null && listeners.remove(listener)) {
removedListenerIds.add(targetID);
}
Expand Down
Expand Up @@ -43,6 +43,7 @@
import static java.util.Collections.synchronizedMap;

import java.util.Map;
import java.util.Map.Entry;
import java.util.WeakHashMap;

import com.sun.enterprise.deployment.ServiceReferenceDescriptor;
Expand Down Expand Up @@ -72,8 +73,9 @@ public AuthConfigRegistrationWrapper lookupListenerWrapper(ServiceReferenceDescr
public void removeListenerWrapper(AuthConfigRegistrationWrapper wrapper) {
ServiceReferenceDescriptor entryToRemove = null;

for (ServiceReferenceDescriptor svc : svcRefListenerMap.keySet()) {
AuthConfigRegistrationWrapper wrp = svcRefListenerMap.get(svc);
for (Entry<ServiceReferenceDescriptor, AuthConfigRegistrationWrapper> entry : svcRefListenerMap.entrySet()) {
ServiceReferenceDescriptor svc = entry.getKey();
AuthConfigRegistrationWrapper wrp = entry.getValue();
if (wrp == wrapper) {
entryToRemove = svc;
break;
Expand Down
Expand Up @@ -51,6 +51,7 @@
import java.util.Set;
import java.util.HashSet;
import java.util.Map;
import java.util.Map.Entry;
import java.util.List;
import java.util.HashMap;
import java.util.ArrayList;
Expand Down Expand Up @@ -120,23 +121,25 @@ private void _checkDefaultValues(final AMXConfigProxy amxConfig)

// test the Map keyed by XML attribute name
final Map<String, String> defaultValuesXML = amxConfig.getDefaultValues(false);
for (final String attrName : defaultValuesXML.keySet())
for (final Entry<String, String> entry : defaultValuesXML.entrySet())
{
String attrName = entry.getKey();
// no default value should ever be null

assert defaultValuesXML.get(attrName) != null :
assert entry.getValue() != null :
"null value for attribute " + attrName + " in " + objectName;
}

// test the Map keyed by AMXProxy attribute name
final Map<String, String> defaultValuesAMX = amxConfig.getDefaultValues(true);

assert defaultValuesXML.size() == defaultValuesAMX.size();
for (final String attrName : defaultValuesAMX.keySet())
for (final Entry<String, String> entry : defaultValuesAMX.entrySet())
{
String attrName = entry.getKey();
// no default value should ever be null

assert defaultValuesAMX.get(attrName) != null :
assert entry.getValue() != null :
"null value for attribute " + attrName + " in " + objectName;
}
}
Expand Down
Expand Up @@ -102,12 +102,13 @@ public Map<URI, List<String>> getTldMap() {
public synchronized Map<URI, List<String>> getTldListenerMap() {
if (tldListenerMap == null) {
tldListenerMap = new HashMap<URI, List<String>>();
for (URI uri : tldMap.keySet()) {
for (Entry<URI, List<String>> entry : tldMap.entrySet()) {
URI uri = entry.getKey();
/*
* In the case of JSF, the only TLD that declares any listener is META-INF/jsf_core.tld
*/
if (tldMap.get(uri).contains("META-INF/jsf_core.tld")) {
tldListenerMap.put(uri, tldMap.get(uri));
if (entry.getValue().contains("META-INF/jsf_core.tld")) {
tldListenerMap.put(uri, entry.getValue());
break;
}
}
Expand Down

0 comments on commit 0d6105d

Please sign in to comment.