You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by eb...@apache.org on 2024/10/25 10:06:45 UTC
(commons-configuration) 01/05: Replace ObjectUtils to reduce the dependency on Commons Lang
This is an automated email from the ASF dual-hosted git repository.
ebourg pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-configuration.git
commit f968113b43ad984dca2135e5f0ce852db7496f0e
Author: Emmanuel Bourg <eb...@apache.org>
AuthorDate: Fri Oct 25 10:11:15 2024 +0200
Replace ObjectUtils to reduce the dependency on Commons Lang
---
.../org/apache/commons/configuration2/AbstractConfiguration.java | 7 ++++---
.../commons/configuration2/BaseHierarchicalConfiguration.java | 4 ++--
.../org/apache/commons/configuration2/io/FileLocatorUtils.java | 5 ++---
3 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/src/main/java/org/apache/commons/configuration2/AbstractConfiguration.java b/src/main/java/org/apache/commons/configuration2/AbstractConfiguration.java
index 0b078eb7..7cde0d23 100644
--- a/src/main/java/org/apache/commons/configuration2/AbstractConfiguration.java
+++ b/src/main/java/org/apache/commons/configuration2/AbstractConfiguration.java
@@ -51,7 +51,6 @@ import org.apache.commons.configuration2.sync.NoOpSynchronizer;
import org.apache.commons.configuration2.sync.Synchronizer;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.ClassUtils;
-import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.function.FailableRunnable;
import org.apache.commons.lang3.function.FailableSupplier;
@@ -507,7 +506,8 @@ public abstract class AbstractConfiguration extends BaseEventSource implements C
*/
private Object convertToArray(final Class<?> cls, final String key, final Object defaultValue) {
checkDefaultValueArray(cls, defaultValue);
- return ObjectUtils.defaultIfNull(getConversionHandler().toArray(getProperty(key), cls, getInterpolator()), defaultValue);
+ Object value = getConversionHandler().toArray(getProperty(key), cls, getInterpolator());
+ return value != null ? value : defaultValue;
}
/**
@@ -620,7 +620,8 @@ public abstract class AbstractConfiguration extends BaseEventSource implements C
private <T> T getAndConvertProperty(final Class<T> cls, final String key, final T defaultValue) {
final Object value = getProperty(key);
try {
- return ObjectUtils.defaultIfNull(getConversionHandler().to(value, cls, getInterpolator()), defaultValue);
+ T convertedValue = getConversionHandler().to(value, cls, getInterpolator());
+ return convertedValue != null ? convertedValue : defaultValue;
} catch (final ConversionException cex) {
// improve error message
throw new ConversionException(String.format("Key '%s' cannot be converted to class %s. Value is: '%s'.", key, cls.getName(), String.valueOf(value)),
diff --git a/src/main/java/org/apache/commons/configuration2/BaseHierarchicalConfiguration.java b/src/main/java/org/apache/commons/configuration2/BaseHierarchicalConfiguration.java
index 75bbd177..18c8faa7 100644
--- a/src/main/java/org/apache/commons/configuration2/BaseHierarchicalConfiguration.java
+++ b/src/main/java/org/apache/commons/configuration2/BaseHierarchicalConfiguration.java
@@ -24,6 +24,7 @@ import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
+import java.util.Objects;
import java.util.stream.Collectors;
import org.apache.commons.configuration2.event.ConfigurationEvent;
@@ -41,7 +42,6 @@ import org.apache.commons.configuration2.tree.NodeTreeWalker;
import org.apache.commons.configuration2.tree.QueryResult;
import org.apache.commons.configuration2.tree.ReferenceNodeHandler;
import org.apache.commons.configuration2.tree.TrackedNodeModel;
-import org.apache.commons.lang3.ObjectUtils;
/**
* <p>
@@ -292,7 +292,7 @@ public class BaseHierarchicalConfiguration extends AbstractHierarchicalConfigura
* @return a flag whether the value was changed
*/
private boolean valueChanged(final Object interpolatedValue, final Object value) {
- return ObjectUtils.notEqual(interpolatedValue, value);
+ return !Objects.equals(interpolatedValue, value);
}
@Override
diff --git a/src/main/java/org/apache/commons/configuration2/io/FileLocatorUtils.java b/src/main/java/org/apache/commons/configuration2/io/FileLocatorUtils.java
index ef739d9d..8c56d463 100644
--- a/src/main/java/org/apache/commons/configuration2/io/FileLocatorUtils.java
+++ b/src/main/java/org/apache/commons/configuration2/io/FileLocatorUtils.java
@@ -24,7 +24,6 @@ import java.util.Arrays;
import java.util.Map;
import org.apache.commons.configuration2.ex.ConfigurationException;
-import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -411,7 +410,7 @@ public final class FileLocatorUtils {
* @return the {@code FileSystem} to be used for this {@code FileLocator}
*/
static FileSystem getFileSystem(final FileLocator locator) {
- return locator != null ? ObjectUtils.defaultIfNull(locator.getFileSystem(), DEFAULT_FILE_SYSTEM) : DEFAULT_FILE_SYSTEM;
+ return locator == null || locator.getFileSystem() == null ? DEFAULT_FILE_SYSTEM : locator.getFileSystem();
}
/**
@@ -423,7 +422,7 @@ public final class FileLocatorUtils {
* @return the {@code FileLocationStrategy} for this {@code FileLocator}
*/
static FileLocationStrategy getLocationStrategy(final FileLocator locator) {
- return locator != null ? ObjectUtils.defaultIfNull(locator.getLocationStrategy(), DEFAULT_LOCATION_STRATEGY) : DEFAULT_LOCATION_STRATEGY;
+ return locator == null || locator.getLocationStrategy() == null ? DEFAULT_LOCATION_STRATEGY : locator.getLocationStrategy();
}
/**