You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2023/03/25 21:35:20 UTC
[commons-configuration] 03/12: Better internal method names
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
commit 57e1b945584ea7055203e2d4702c8267f08590c5
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Mar 25 16:49:39 2023 -0400
Better internal method names
---
.../commons/configuration2/io/FileHandler.java | 14 ++---
.../configuration2/io/FileLocatorUtils.java | 62 +++++++++++-----------
.../configuration2/io/TestFileLocatorUtils.java | 12 ++---
3 files changed, 44 insertions(+), 44 deletions(-)
diff --git a/src/main/java/org/apache/commons/configuration2/io/FileHandler.java b/src/main/java/org/apache/commons/configuration2/io/FileHandler.java
index 71f3a9be..6bebf47c 100644
--- a/src/main/java/org/apache/commons/configuration2/io/FileHandler.java
+++ b/src/main/java/org/apache/commons/configuration2/io/FileHandler.java
@@ -485,7 +485,7 @@ public class FileHandler {
* @return the used {@code FileSystem}
*/
public FileSystem getFileSystem() {
- return FileLocatorUtils.obtainFileSystem(getFileLocator());
+ return FileLocatorUtils.getFileSystem(getFileLocator());
}
/**
@@ -496,7 +496,7 @@ public class FileHandler {
* @return the {@code FileLocationStrategy} to be used
*/
public FileLocationStrategy getLocationStrategy() {
- return FileLocatorUtils.obtainLocationStrategy(getFileLocator());
+ return FileLocatorUtils.getLocationStrategy(getFileLocator());
}
/**
@@ -509,7 +509,7 @@ public class FileHandler {
public String getPath() {
final FileLocator locator = getFileLocator();
final File file = createFile(locator);
- return FileLocatorUtils.obtainFileSystem(locator).getPath(file, locator.getSourceURL(), locator.getBasePath(), locator.getFileName());
+ return FileLocatorUtils.getFileSystem(locator).getPath(file, locator.getSourceURL(), locator.getBasePath(), locator.getFileName());
}
/**
@@ -687,7 +687,7 @@ public class FileHandler {
InputStream in = null;
try {
- final FileSystem obtainFileSystem = FileLocatorUtils.obtainFileSystem(locator);
+ final FileSystem obtainFileSystem = FileLocatorUtils.getFileSystem(locator);
final URLConnectionOptions urlConnectionOptions = locator.getURLConnectionOptions();
in = urlConnectionOptions == null ? obtainFileSystem.getInputStream(url) : obtainFileSystem.getInputStream(url, urlConnectionOptions);
loadFromStream(in, locator.getEncoding(), url);
@@ -872,7 +872,7 @@ public class FileHandler {
OutputStream out = null;
try {
- out = FileLocatorUtils.obtainFileSystem(locator).getOutputStream(file);
+ out = FileLocatorUtils.getFileSystem(locator).getOutputStream(file);
saveToStream(out, locator.getEncoding(), file.toURI().toURL());
} catch (final MalformedURLException muex) {
throw new ConfigurationException(muex);
@@ -953,7 +953,7 @@ public class FileHandler {
private void save(final String fileName, final FileLocator locator) throws ConfigurationException {
final URL url;
try {
- url = FileLocatorUtils.obtainFileSystem(locator).getURL(locator.getBasePath(), fileName);
+ url = FileLocatorUtils.getFileSystem(locator).getURL(locator.getBasePath(), fileName);
} catch (final MalformedURLException e) {
throw new ConfigurationException(e);
}
@@ -985,7 +985,7 @@ public class FileHandler {
private void save(final URL url, final FileLocator locator) throws ConfigurationException {
OutputStream out = null;
try {
- out = FileLocatorUtils.obtainFileSystem(locator).getOutputStream(url);
+ out = FileLocatorUtils.getFileSystem(locator).getOutputStream(url);
saveToStream(out, locator.getEncoding(), url);
if (out instanceof VerifiableOutputStream) {
try {
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 018afee8..23183557 100644
--- a/src/main/java/org/apache/commons/configuration2/io/FileLocatorUtils.java
+++ b/src/main/java/org/apache/commons/configuration2/io/FileLocatorUtils.java
@@ -98,12 +98,6 @@ public final class FileLocatorUtils {
/** Property key for the source URL. */
private static final String PROP_SOURCE_URL = "sourceURL";
- /**
- * Private constructor so that no instances can be created.
- */
- private FileLocatorUtils() {
- }
-
/**
* Extends a path by another component. The given extension is added to the already existing path adding a separator if
* necessary.
@@ -379,6 +373,30 @@ public final class FileLocatorUtils {
return path.substring(path.lastIndexOf("/") + 1);
}
+ /**
+ * Obtains a non-<b>null</b> {@code FileSystem} object from the passed in {@code FileLocator}. If the passed in
+ * {@code FileLocator} has a {@code FileSystem} object, it is returned. Otherwise, result is the default
+ * {@code FileSystem}.
+ *
+ * @param locator the {@code FileLocator} (may be <b>null</b>)
+ * @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;
+ }
+
+ /**
+ * Gets a non <b>null</b> {@code FileLocationStrategy} object from the passed in {@code FileLocator}. If the
+ * {@code FileLocator} is not <b>null</b> and has a {@code FileLocationStrategy} defined, this strategy is returned.
+ * Otherwise, result is the default {@code FileLocationStrategy}.
+ *
+ * @param locator the {@code FileLocator}
+ * @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;
+ }
+
/**
* Creates the default location strategy. This method creates a combined location strategy as described in the comment
* of the {@link #DEFAULT_LOCATION_STRATEGY} member field.
@@ -438,7 +456,7 @@ public final class FileLocatorUtils {
return null;
}
- return obtainLocationStrategy(locator).locate(obtainFileSystem(locator), locator);
+ return getLocationStrategy(locator).locate(getFileSystem(locator), locator);
}
/**
@@ -486,30 +504,6 @@ public final class FileLocatorUtils {
return url;
}
- /**
- * Obtains a non-<b>null</b> {@code FileSystem} object from the passed in {@code FileLocator}. If the passed in
- * {@code FileLocator} has a {@code FileSystem} object, it is returned. Otherwise, result is the default
- * {@code FileSystem}.
- *
- * @param locator the {@code FileLocator} (may be <b>null</b>)
- * @return the {@code FileSystem} to be used for this {@code FileLocator}
- */
- static FileSystem obtainFileSystem(final FileLocator locator) {
- return locator != null ? ObjectUtils.defaultIfNull(locator.getFileSystem(), DEFAULT_FILE_SYSTEM) : DEFAULT_FILE_SYSTEM;
- }
-
- /**
- * Obtains a non <b>null</b> {@code FileLocationStrategy} object from the passed in {@code FileLocator}. If the
- * {@code FileLocator} is not <b>null</b> and has a {@code FileLocationStrategy} defined, this strategy is returned.
- * Otherwise, result is the default {@code FileLocationStrategy}.
- *
- * @param locator the {@code FileLocator}
- * @return the {@code FileLocationStrategy} for this {@code FileLocator}
- */
- static FileLocationStrategy obtainLocationStrategy(final FileLocator locator) {
- return locator != null ? ObjectUtils.defaultIfNull(locator.getLocationStrategy(), DEFAULT_LOCATION_STRATEGY) : DEFAULT_LOCATION_STRATEGY;
- }
-
/**
* Stores the specified {@code FileLocator} in the given map. With the {@link #fromMap(Map)} method a new
* {@code FileLocator} with the same properties as the original one can be created.
@@ -548,4 +542,10 @@ public final class FileLocatorUtils {
return file.toURI().toURL();
}
+ /**
+ * Private constructor so that no instances can be created.
+ */
+ private FileLocatorUtils() {
+ }
+
}
diff --git a/src/test/java/org/apache/commons/configuration2/io/TestFileLocatorUtils.java b/src/test/java/org/apache/commons/configuration2/io/TestFileLocatorUtils.java
index b51cfd5f..6d512c01 100644
--- a/src/test/java/org/apache/commons/configuration2/io/TestFileLocatorUtils.java
+++ b/src/test/java/org/apache/commons/configuration2/io/TestFileLocatorUtils.java
@@ -404,7 +404,7 @@ public class TestFileLocatorUtils {
*/
@Test
public void testObtainFileSystemNotSetInLocator() {
- assertSame(FileLocatorUtils.DEFAULT_FILE_SYSTEM, FileLocatorUtils.obtainFileSystem(FileLocatorUtils.fileLocator().create()));
+ assertSame(FileLocatorUtils.DEFAULT_FILE_SYSTEM, FileLocatorUtils.getFileSystem(FileLocatorUtils.fileLocator().create()));
}
/**
@@ -412,7 +412,7 @@ public class TestFileLocatorUtils {
*/
@Test
public void testObtainFileSystemNullLocator() {
- assertSame(FileLocatorUtils.DEFAULT_FILE_SYSTEM, FileLocatorUtils.obtainFileSystem(null));
+ assertSame(FileLocatorUtils.DEFAULT_FILE_SYSTEM, FileLocatorUtils.getFileSystem(null));
}
/**
@@ -422,7 +422,7 @@ public class TestFileLocatorUtils {
public void testObtainFileSystemSetInLocator() {
final FileSystem fs = mock(FileSystem.class);
final FileLocator locator = FileLocatorUtils.fileLocator().fileSystem(fs).create();
- assertSame(fs, FileLocatorUtils.obtainFileSystem(locator));
+ assertSame(fs, FileLocatorUtils.getFileSystem(locator));
}
/**
@@ -431,7 +431,7 @@ public class TestFileLocatorUtils {
@Test
public void testObtainLocationStrategyNotSetInLocator() {
final FileLocator locator = FileLocatorUtils.fileLocator().create();
- assertSame(FileLocatorUtils.DEFAULT_LOCATION_STRATEGY, FileLocatorUtils.obtainLocationStrategy(locator));
+ assertSame(FileLocatorUtils.DEFAULT_LOCATION_STRATEGY, FileLocatorUtils.getLocationStrategy(locator));
}
/**
@@ -439,7 +439,7 @@ public class TestFileLocatorUtils {
*/
@Test
public void testObtainLocationStrategyNullLocator() {
- assertSame(FileLocatorUtils.DEFAULT_LOCATION_STRATEGY, FileLocatorUtils.obtainLocationStrategy(null));
+ assertSame(FileLocatorUtils.DEFAULT_LOCATION_STRATEGY, FileLocatorUtils.getLocationStrategy(null));
}
/**
@@ -449,7 +449,7 @@ public class TestFileLocatorUtils {
public void testObtainLocationStrategySetInLocator() {
final FileLocationStrategy strategy = mock(FileLocationStrategy.class);
final FileLocator locator = FileLocatorUtils.fileLocator().locationStrategy(strategy).create();
- assertSame(strategy, FileLocatorUtils.obtainLocationStrategy(locator));
+ assertSame(strategy, FileLocatorUtils.getLocationStrategy(locator));
}
/**