This is an automated email from the ASF dual-hosted git repository. ggregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-configuration.git
The following commit(s) were added to refs/heads/master by this push: new 7ae11a39 Use modern Map APIs 7ae11a39 is described below commit 7ae11a3987c617d9619d7d9847c267344af8cfce Author: Gary Gregory <garydgreg...@gmail.com> AuthorDate: Fri Jul 7 00:11:21 2023 -0400 Use modern Map APIs --- .../org/apache/commons/configuration2/INIConfiguration.java | 6 +----- .../commons/configuration2/PropertiesConfigurationLayout.java | 10 ++-------- .../apache/commons/configuration2/event/EventListenerList.java | 6 +----- .../apache/commons/configuration2/tree/ModelTransaction.java | 7 +------ 4 files changed, 5 insertions(+), 24 deletions(-) diff --git a/src/main/java/org/apache/commons/configuration2/INIConfiguration.java b/src/main/java/org/apache/commons/configuration2/INIConfiguration.java index 33620d20..b834e463 100644 --- a/src/main/java/org/apache/commons/configuration2/INIConfiguration.java +++ b/src/main/java/org/apache/commons/configuration2/INIConfiguration.java @@ -480,11 +480,7 @@ public class INIConfiguration extends BaseHierarchicalConfiguration implements F if (isSectionLine(line)) { final int length = sectionInLineCommentsAllowed ? line.indexOf("]") : line.length() - 1; final String section = line.substring(1, length); - sectionBuilder = sectionBuilders.get(section); - if (sectionBuilder == null) { - sectionBuilder = new ImmutableNode.Builder(); - sectionBuilders.put(section, sectionBuilder); - } + sectionBuilder = sectionBuilders.computeIfAbsent(section, k -> new ImmutableNode.Builder()); } else { String key; String value = ""; diff --git a/src/main/java/org/apache/commons/configuration2/PropertiesConfigurationLayout.java b/src/main/java/org/apache/commons/configuration2/PropertiesConfigurationLayout.java index f496caa7..d0acec68 100644 --- a/src/main/java/org/apache/commons/configuration2/PropertiesConfigurationLayout.java +++ b/src/main/java/org/apache/commons/configuration2/PropertiesConfigurationLayout.java @@ -555,14 +555,8 @@ public class PropertiesConfigurationLayout implements EventListener<Configuratio throw new IllegalArgumentException("Property key must not be null!"); } - PropertyLayoutData data = layoutData.get(key); - if (data == null) { - data = new PropertyLayoutData(); - data.setSingleLine(true); - layoutData.put(key, data); - } - - return data; + // PropertyLayoutData defaults to singleLine = true + return layoutData.computeIfAbsent(key, k -> new PropertyLayoutData()); } /** diff --git a/src/main/java/org/apache/commons/configuration2/event/EventListenerList.java b/src/main/java/org/apache/commons/configuration2/event/EventListenerList.java index 5a2d8a6c..29ba5cc4 100644 --- a/src/main/java/org/apache/commons/configuration2/event/EventListenerList.java +++ b/src/main/java/org/apache/commons/configuration2/event/EventListenerList.java @@ -180,11 +180,7 @@ public class EventListenerList { final List<EventListenerRegistrationData<? extends T>> results = new LinkedList<>(); listeners.forEach(reg -> { - Set<EventType<?>> base = superTypes.get(reg.getEventType()); - if (base == null) { - base = EventType.fetchSuperEventTypes(reg.getEventType()); - superTypes.put(reg.getEventType(), base); - } + Set<EventType<?>> base = superTypes.computeIfAbsent(reg.getEventType(), EventType::fetchSuperEventTypes); if (base.contains(eventType)) { @SuppressWarnings("unchecked") final diff --git a/src/main/java/org/apache/commons/configuration2/tree/ModelTransaction.java b/src/main/java/org/apache/commons/configuration2/tree/ModelTransaction.java index 626e647c..e4fd85ab 100644 --- a/src/main/java/org/apache/commons/configuration2/tree/ModelTransaction.java +++ b/src/main/java/org/apache/commons/configuration2/tree/ModelTransaction.java @@ -312,12 +312,7 @@ class ModelTransaction { Operations fetchOperations(final ImmutableNode target, final int level) { final Integer nodeLevel = Integer.valueOf(level == LEVEL_UNKNOWN ? level(target) : level); final Map<ImmutableNode, Operations> levelOperations = operations.computeIfAbsent(nodeLevel, k -> new HashMap<>()); - Operations ops = levelOperations.get(target); - if (ops == null) { - ops = new Operations(); - levelOperations.put(target, ops); - } - return ops; + return levelOperations.computeIfAbsent(target, k -> new Operations()); } /**