Skip to content

Commit

Permalink
Refactor to use getOrDefault on Map
Browse files Browse the repository at this point in the history
Signed-off-by: Jarno Elovirta <jarno@elovirta.com>
  • Loading branch information
jelovirt committed Oct 6, 2023
1 parent 94bb36a commit 8770d82
Showing 1 changed file with 6 additions and 22 deletions.
28 changes: 6 additions & 22 deletions src/main/java/org/dita/dost/reader/SubjectSchemeReader.java
Expand Up @@ -200,10 +200,7 @@ public void processEnumerationDef(final Element schemeRoot, final Element enumer
// Put default values.
final String keyValue = child.getAttribute(ATTRIBUTE_NAME_KEYREF);
if (keyValue != null) {
Map<String, String> S = defaultValueMap.get(attributeName);
if (S == null) {
S = new HashMap<>();
}
final Map<String, String> S = defaultValueMap.getOrDefault(attributeName, new HashMap<>());
S.put(elementName, keyValue);
defaultValueMap.put(attributeName, S);
}
Expand All @@ -215,14 +212,8 @@ public void processEnumerationDef(final Element schemeRoot, final Element enumer
}
final Element subTree = searchForKey(schemeRoot, keyValue);
if (subTree != null) {
Map<String, Set<Element>> S = bindingMap.get(attributeName);
if (S == null) {
S = new HashMap<>();
}
Set<Element> A = S.get(elementName);
if (A == null) {
A = new HashSet<>();
}
final Map<String, Set<Element>> S = bindingMap.getOrDefault(attributeName, new HashMap<>());
final Set<Element> A = S.getOrDefault(elementName, new HashSet<>());
if (!A.contains(subTree)) {
// Add sub-tree to valid values map
putValuePairsIntoMap(subTree, elementName, attributeName, keyValue);
Expand Down Expand Up @@ -283,15 +274,8 @@ private void putValuePairsIntoMap(
return;
}

Map<String, Set<String>> valueMap = validValuesMap.get(attName);
if (valueMap == null) {
valueMap = new HashMap<>();
}

Set<String> valueSet = valueMap.get(elementName);
if (valueSet == null) {
valueSet = new HashSet<>();
}
final Map<String, Set<String>> valueMap = validValuesMap.getOrDefault(attName, new HashMap<>());
final Set<String> valueSet = valueMap.getOrDefault(elementName, new HashSet<>());

final LinkedList<Element> queue = new LinkedList<>();
queue.offer(subtree);
Expand All @@ -303,7 +287,7 @@ private void putValuePairsIntoMap(
}
if (SUBJECTSCHEME_SUBJECTDEF.matches(node)) {
final String key = node.getAttribute(ATTRIBUTE_NAME_KEYS);
if (!(key == null || key.trim().isEmpty() || key.equals(category))) {
if (!(key.trim().isEmpty() || key.equals(category))) {
valueSet.add(key);
}
}
Expand Down

0 comments on commit 8770d82

Please sign in to comment.