Fixed critical issues reported by sonar (Performance - Inefficient use of keySet iterator instead of entrySet iterator)

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/HEAD@65396 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Tuna Aksoy
2014-03-22 15:56:17 +00:00
parent 935ca851cb
commit 166ece8ebb
9 changed files with 42 additions and 41 deletions

View File

@@ -107,10 +107,10 @@ public class ApplyCustomTypeAction extends RMActionExecuterAbstractBase
Map<String, Serializable> paramValues = action.getParameterValues(); Map<String, Serializable> paramValues = action.getParameterValues();
Map<QName, Serializable> result = new HashMap<QName, Serializable>(paramValues.size()); Map<QName, Serializable> result = new HashMap<QName, Serializable>(paramValues.size());
for (String paramName : paramValues.keySet()) for (Map.Entry<String, Serializable> entry : paramValues.entrySet())
{ {
QName propQName = QName.createQName(paramName, this.namespaceService); QName propQName = QName.createQName(entry.getKey(), this.namespaceService);
result.put(propQName, paramValues.get(paramName)); result.put(propQName, entry.getValue());
} }
return result; return result;
@@ -132,11 +132,12 @@ public class ApplyCustomTypeAction extends RMActionExecuterAbstractBase
this.parameterDefinitions = new ArrayList<ParameterDefinition>(props.size()); this.parameterDefinitions = new ArrayList<ParameterDefinition>(props.size());
for (QName qn : props.keySet()) for (Map.Entry<QName, PropertyDefinition> entry : props.entrySet())
{ {
String paramName = qn.toPrefixString(namespaceService); String paramName = entry.getKey().toPrefixString(namespaceService);
QName paramType = props.get(qn).getDataType().getName(); PropertyDefinition value = entry.getValue();
boolean paramIsMandatory = props.get(qn).isMandatory(); QName paramType = value.getDataType().getName();
boolean paramIsMandatory = value.isMandatory();
parameterDefinitions.add(new ParameterDefinitionImpl(paramName, paramType, paramIsMandatory, null)); parameterDefinitions.add(new ParameterDefinitionImpl(paramName, paramType, paramIsMandatory, null));
} }
} }

View File

@@ -575,9 +575,9 @@ public class RMAfterInvocationProvider extends RMSecurityCommon
Map<Set<String>, ResultSet> map = returnedObject.getResults(); Map<Set<String>, ResultSet> map = returnedObject.getResults();
Map<Set<String>, ResultSet> answer = new HashMap<Set<String>, ResultSet>(map.size(), 1.0f); Map<Set<String>, ResultSet> answer = new HashMap<Set<String>, ResultSet>(map.size(), 1.0f);
for (Set<String> group : map.keySet()) for (Map.Entry<Set<String>, ResultSet> entry : map.entrySet())
{ {
ResultSet raw = map.get(group); ResultSet raw = entry.getValue();
ResultSet permed; ResultSet permed;
if (PagingLuceneResultSet.class.isAssignableFrom(raw.getClass())) if (PagingLuceneResultSet.class.isAssignableFrom(raw.getClass()))
{ {
@@ -587,8 +587,9 @@ public class RMAfterInvocationProvider extends RMSecurityCommon
{ {
permed = decide(authentication, object, config, raw); permed = decide(authentication, object, config, raw);
} }
answer.put(group, permed); answer.put(entry.getKey(), permed);
} }
return new QueryEngineResults(answer); return new QueryEngineResults(answer);
} }

View File

@@ -35,16 +35,17 @@ import java.util.Map;
Map<String, List<String>> pivot = new HashMap<String, List<String>>(); Map<String, List<String>> pivot = new HashMap<String, List<String>>();
for(String authority : source.keySet()) for (Map.Entry<String, List<String>> entry : source.entrySet())
{ {
List<String>values = source.get(authority); List<String>values = entry.getValue();
for(String value : values) for (String value : values)
{ {
if(pivot.containsKey(value)) String authority = entry.getKey();
if (pivot.containsKey(value))
{ {
// already exists // already exists
List<String> list = pivot.get(value); List<String> list = pivot.get(value);
list.add(authority); list.add(authority );
} }
else else
{ {
@@ -55,6 +56,7 @@ import java.util.Map;
} }
} }
} }
return pivot; return pivot;
} }
} }

View File

@@ -161,14 +161,14 @@ public class CustomEmailMappingServiceImpl extends AbstractLifecycleBean impleme
// load the contents of the extractors property file // load the contents of the extractors property file
Map<String, Set<QName>> currentMapping = extracter.getCurrentMapping(); Map<String, Set<QName>> currentMapping = extracter.getCurrentMapping();
for(String key : currentMapping.keySet()) for (Map.Entry<String, Set<QName>> entry : currentMapping.entrySet())
{ {
Set<QName> set = currentMapping.get(key); Set<QName> set = entry.getValue();
for(QName qname : set) for (QName qname : set)
{ {
CustomMapping value = new CustomMapping(); CustomMapping value = new CustomMapping();
value.setFrom(key); value.setFrom(entry.getKey());
QName resolvedQname = qname.getPrefixedQName(nspr); QName resolvedQname = qname.getPrefixedQName(nspr);
value.setTo(resolvedQname.toPrefixString()); value.setTo(resolvedQname.toPrefixString());
customMappings.add(value); customMappings.add(value);

View File

@@ -839,10 +839,10 @@ public class RecordsManagementSearchBehaviour implements RecordsManagementModel
private Set<QName> determineChangedProps(Map<QName, Serializable> oldProps, Map<QName, Serializable> newProps) private Set<QName> determineChangedProps(Map<QName, Serializable> oldProps, Map<QName, Serializable> newProps)
{ {
Set<QName> result = new HashSet<QName>(); Set<QName> result = new HashSet<QName>();
for (QName qn : oldProps.keySet()) for (Map.Entry<QName, Serializable> entry : oldProps.entrySet())
{ {
if (newProps.get(qn) == null || QName qn = entry.getKey();
!newProps.get(qn).equals(oldProps.get(qn))) if (newProps.get(qn) == null || !newProps.get(qn).equals(entry.getValue()))
{ {
result.add(qn); result.add(qn);
} }

View File

@@ -336,8 +336,9 @@ public class ModelSecurityServiceImpl extends BaseBehaviourBean
!AuthenticationUtil.isRunAsUserTheSystemUser() && !AuthenticationUtil.isRunAsUserTheSystemUser() &&
nodeService.exists(nodeRef)) nodeService.exists(nodeRef))
{ {
for (QName property : after.keySet()) for (Map.Entry<QName, Serializable> entry : after.entrySet())
{ {
QName property = entry.getKey();
if (isProtectedProperty(property)) if (isProtectedProperty(property))
{ {
// always allow if this is the first time we are setting the protected property // always allow if this is the first time we are setting the protected property
@@ -346,7 +347,7 @@ public class ModelSecurityServiceImpl extends BaseBehaviourBean
return; return;
} }
if (!EqualsHelper.nullSafeEquals(before.get(property), after.get(property)) && if (!EqualsHelper.nullSafeEquals(before.get(property), entry.getValue()) &&
!canEditProtectedProperty(nodeRef, property)) !canEditProtectedProperty(nodeRef, property))
{ {
// the user can't edit the protected property // the user can't edit the protected property

View File

@@ -539,20 +539,16 @@ public class RecordServiceImpl extends BaseBehaviourBean
nodeService.exists(nodeRef) && nodeService.exists(nodeRef) &&
isRecord(nodeRef)) isRecord(nodeRef))
{ {
for (QName property : after.keySet()) for (Map.Entry<QName, Serializable> entry : after.entrySet())
{ {
Serializable beforeValue = null; Serializable beforeValue = null;
QName property = entry.getKey();
if (before != null) if (before != null)
{ {
beforeValue = before.get(property); beforeValue = before.get(property);
} }
Serializable afterValue = null; Serializable afterValue = entry.getValue();
if (after != null)
{
afterValue = after.get(property);
}
boolean propertyUnchanged = false; boolean propertyUnchanged = false;
if (beforeValue instanceof Date && afterValue instanceof Date) if (beforeValue instanceof Date && afterValue instanceof Date)
{ {

View File

@@ -201,12 +201,12 @@ public class RmActionPost extends DeclarativeWebScript
{ {
Map<NodeRef, RecordsManagementActionResult> resultMap = this.rmActionService.executeRecordsManagementAction(targetNodeRefs, actionName, actionParams); Map<NodeRef, RecordsManagementActionResult> resultMap = this.rmActionService.executeRecordsManagementAction(targetNodeRefs, actionName, actionParams);
Map<String, String> results = new HashMap<String, String>(resultMap.size()); Map<String, String> results = new HashMap<String, String>(resultMap.size());
for (NodeRef nodeRef : resultMap.keySet()) for (Map.Entry<NodeRef, RecordsManagementActionResult> entry : resultMap.entrySet())
{ {
Object value = resultMap.get(nodeRef).getValue(); Object value = entry.getValue().getValue();
if (value != null) if (value != null)
{ {
results.put(nodeRef.toString(), resultMap.get(nodeRef).getValue().toString()); results.put(entry.getKey().toString(), value.toString());
} }
} }
model.put("results", results); model.put("results", results);

View File

@@ -265,15 +265,15 @@ public class NodeParameterProcessor extends ParameterProcessor implements Parame
private boolean processPropertyDefinitions(Map<QName, PropertyDefinition> properties, String substitutionFragment, Set<String> suggestions) private boolean processPropertyDefinitions(Map<QName, PropertyDefinition> properties, String substitutionFragment, Set<String> suggestions)
{ {
boolean gotMaximumSuggestions = false; boolean gotMaximumSuggestions = false;
if(properties != null) if (properties != null)
{ {
for(QName key : properties.keySet()) for (Map.Entry<QName, PropertyDefinition> entry : properties.entrySet())
{ {
PropertyDefinition propertyDefinition = properties.get(key); PropertyDefinition propertyDefinition = entry.getValue();
QName type = propertyDefinition.getDataType().getName(); QName type = propertyDefinition.getDataType().getName();
if(ArrayUtils.contains(supportedDataTypes, type)) if(ArrayUtils.contains(supportedDataTypes, type))
{ {
String suggestion = getName() + "." + key.getPrefixString(); String suggestion = getName() + "." + entry.getKey().getPrefixString();
if(suggestion.toLowerCase().contains(substitutionFragment)) if(suggestion.toLowerCase().contains(substitutionFragment))
{ {
if(suggestions.size() < this.maximumNumberSuggestions) if(suggestions.size() < this.maximumNumberSuggestions)