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 95744ebbea5442859af869e8d7169317ef4592bc Author: Gary Gregory <garydgreg...@gmail.com> AuthorDate: Fri Sep 18 16:47:09 2020 -0400 Sort members. --- .../commons/configuration2/io/FileLocator.java | 388 ++++++++++----------- 1 file changed, 194 insertions(+), 194 deletions(-) diff --git a/src/main/java/org/apache/commons/configuration2/io/FileLocator.java b/src/main/java/org/apache/commons/configuration2/io/FileLocator.java index f0d02f7..bb7932c 100644 --- a/src/main/java/org/apache/commons/configuration2/io/FileLocator.java +++ b/src/main/java/org/apache/commons/configuration2/io/FileLocator.java @@ -56,6 +56,150 @@ import org.apache.commons.lang3.builder.ToStringBuilder; */ public final class FileLocator { + /** + * A typical <em>builder</em> implementation for creating + * {@code FileLocator} objects. An instance of this class is returned by the + * {@code fileLocator()} method of {link FileLocatorUtils}. It can be used + * to define the various components of the {@code FileLocator} object. By + * calling {@code create()} the new immutable {@code FileLocator} instance + * is created. + */ + public static final class FileLocatorBuilder + { + /** The file name. */ + private String fileName; + + /** The base path. */ + private String basePath; + + /** The source URL. */ + private URL sourceURL; + + /** The encoding. */ + private String encoding; + + /** The file system. */ + private FileSystem fileSystem; + + /** The location strategy. */ + private FileLocationStrategy locationStrategy; + + /** + * Creates a new instance of {@code FileLocatorBuilder} and initializes + * the builder's properties from the passed in {@code FileLocator} + * object. + * + * @param src the source {@code FileLocator} (may be <b>null</b>) + */ + FileLocatorBuilder(final FileLocator src) + { + if (src != null) + { + initBuilder(src); + } + } + + /** + * Specifies the base path of the new {@code FileLocator}. + * + * @param path the base path + * @return a reference to this builder for method chaining + */ + public FileLocatorBuilder basePath(final String path) + { + basePath = path; + return this; + } + + /** + * Creates a new immutable {@code FileLocatorImpl} object based on the + * properties set so far for this builder. + * + * @return the newly created {@code FileLocator} object + */ + public FileLocator create() + { + return new FileLocator(this); + } + + /** + * Specifies the encoding of the new {@code FileLocator}. + * + * @param enc the encoding + * @return a reference to this builder for method chaining + */ + public FileLocatorBuilder encoding(final String enc) + { + encoding = enc; + return this; + } + + /** + * Specifies the file name of the new {@code FileLocator}. + * + * @param name the file name + * @return a reference to this builder for method chaining + */ + public FileLocatorBuilder fileName(final String name) + { + fileName = name; + return this; + } + + /** + * Specifies the {@code FileSystem} of the new {@code FileLocator}. + * + * @param fs the {@code FileSystem} + * @return a reference to this builder for method chaining + */ + public FileLocatorBuilder fileSystem(final FileSystem fs) + { + fileSystem = fs; + return this; + } + + /** + * Initializes the properties of this builder from the passed in locator + * object. + * + * @param src the source {@code FileLocator} + */ + private void initBuilder(final FileLocator src) + { + basePath = src.getBasePath(); + fileName = src.getFileName(); + sourceURL = src.getSourceURL(); + encoding = src.getEncoding(); + fileSystem = src.getFileSystem(); + locationStrategy = src.getLocationStrategy(); + } + + /** + * Specifies the {@code FileLocationStrategy} to be used when the + * referenced file is to be located. + * + * @param strategy the {@code FileLocationStrategy} + * @return a reference to this builder for method chaining + */ + public FileLocatorBuilder locationStrategy(final FileLocationStrategy strategy) + { + locationStrategy = strategy; + return this; + } + + /** + * Specifies the source URL of the new {@code FileLocator}. + * + * @param url the source URL + * @return a reference to this builder for method chaining + */ + public FileLocatorBuilder sourceURL(final URL url) + { + sourceURL = url; + return this; + } + } + /** The file name. */ private final String fileName; @@ -91,14 +235,33 @@ public final class FileLocator } /** - * Returns the file name stored in this locator or <b>null</b> if it is - * undefined. + * Compares this object with another one. Two instances of + * {@code FileLocatorImpl} are considered equal if all of their properties + * are equal. * - * @return the file name + * @param obj the object to compare to + * @return a flag whether these objects are equal */ - public String getFileName() + @Override + public boolean equals(final Object obj) { - return fileName; + if (this == obj) + { + return true; + } + if (!(obj instanceof FileLocator)) + { + return false; + } + + final FileLocator c = (FileLocator) obj; + return new EqualsBuilder().append(getFileName(), c.getFileName()) + .append(getBasePath(), c.getBasePath()) + .append(sourceURLAsString(), c.sourceURLAsString()) + .append(getEncoding(), c.getEncoding()) + .append(getFileSystem(), c.getFileSystem()) + .append(getLocationStrategy(), c.getLocationStrategy()) + .isEquals(); } /** @@ -113,25 +276,25 @@ public final class FileLocator } /** - * Returns the URL pointing to the referenced source file or <b>null</b> if - * it is undefined. + * Returns the encoding stored in this locator or <b>null</b> if it is + * undefined. * - * @return the source URL + * @return the encoding */ - public URL getSourceURL() + public String getEncoding() { - return sourceURL; + return encoding; } /** - * Returns the encoding stored in this locator or <b>null</b> if it is + * Returns the file name stored in this locator or <b>null</b> if it is * undefined. * - * @return the encoding + * @return the file name */ - public String getEncoding() + public String getFileName() { - return encoding; + return fileName; } /** @@ -159,6 +322,17 @@ public final class FileLocator } /** + * Returns the URL pointing to the referenced source file or <b>null</b> if + * it is undefined. + * + * @return the source URL + */ + public URL getSourceURL() + { + return sourceURL; + } + + /** * Returns a hash code for this object. * * @return a hash code for this object @@ -173,33 +347,15 @@ public final class FileLocator } /** - * Compares this object with another one. Two instances of - * {@code FileLocatorImpl} are considered equal if all of their properties - * are equal. + * Returns the source URL as a string. Result is never null. Comparisons are + * done on this string to avoid blocking network calls. * - * @param obj the object to compare to - * @return a flag whether these objects are equal + * @return the source URL as a string (not null) */ - @Override - public boolean equals(final Object obj) + private String sourceURLAsString() { - if (this == obj) - { - return true; - } - if (!(obj instanceof FileLocator)) - { - return false; - } - - final FileLocator c = (FileLocator) obj; - return new EqualsBuilder().append(getFileName(), c.getFileName()) - .append(getBasePath(), c.getBasePath()) - .append(sourceURLAsString(), c.sourceURLAsString()) - .append(getEncoding(), c.getEncoding()) - .append(getFileSystem(), c.getFileSystem()) - .append(getLocationStrategy(), c.getLocationStrategy()) - .isEquals(); + return sourceURL != null ? sourceURL.toExternalForm() + : StringUtils.EMPTY; } /** @@ -218,160 +374,4 @@ public final class FileLocator .append("fileSystem", getFileSystem()) .append("locationStrategy", getLocationStrategy()).toString(); } - - /** - * Returns the source URL as a string. Result is never null. Comparisons are - * done on this string to avoid blocking network calls. - * - * @return the source URL as a string (not null) - */ - private String sourceURLAsString() - { - return sourceURL != null ? sourceURL.toExternalForm() - : StringUtils.EMPTY; - } - - /** - * A typical <em>builder</em> implementation for creating - * {@code FileLocator} objects. An instance of this class is returned by the - * {@code fileLocator()} method of {link FileLocatorUtils}. It can be used - * to define the various components of the {@code FileLocator} object. By - * calling {@code create()} the new immutable {@code FileLocator} instance - * is created. - */ - public static final class FileLocatorBuilder - { - /** The file name. */ - private String fileName; - - /** The base path. */ - private String basePath; - - /** The source URL. */ - private URL sourceURL; - - /** The encoding. */ - private String encoding; - - /** The file system. */ - private FileSystem fileSystem; - - /** The location strategy. */ - private FileLocationStrategy locationStrategy; - - /** - * Creates a new instance of {@code FileLocatorBuilder} and initializes - * the builder's properties from the passed in {@code FileLocator} - * object. - * - * @param src the source {@code FileLocator} (may be <b>null</b>) - */ - FileLocatorBuilder(final FileLocator src) - { - if (src != null) - { - initBuilder(src); - } - } - - /** - * Specifies the encoding of the new {@code FileLocator}. - * - * @param enc the encoding - * @return a reference to this builder for method chaining - */ - public FileLocatorBuilder encoding(final String enc) - { - encoding = enc; - return this; - } - - /** - * Specifies the {@code FileSystem} of the new {@code FileLocator}. - * - * @param fs the {@code FileSystem} - * @return a reference to this builder for method chaining - */ - public FileLocatorBuilder fileSystem(final FileSystem fs) - { - fileSystem = fs; - return this; - } - - /** - * Specifies the base path of the new {@code FileLocator}. - * - * @param path the base path - * @return a reference to this builder for method chaining - */ - public FileLocatorBuilder basePath(final String path) - { - basePath = path; - return this; - } - - /** - * Specifies the file name of the new {@code FileLocator}. - * - * @param name the file name - * @return a reference to this builder for method chaining - */ - public FileLocatorBuilder fileName(final String name) - { - fileName = name; - return this; - } - - /** - * Specifies the source URL of the new {@code FileLocator}. - * - * @param url the source URL - * @return a reference to this builder for method chaining - */ - public FileLocatorBuilder sourceURL(final URL url) - { - sourceURL = url; - return this; - } - - /** - * Specifies the {@code FileLocationStrategy} to be used when the - * referenced file is to be located. - * - * @param strategy the {@code FileLocationStrategy} - * @return a reference to this builder for method chaining - */ - public FileLocatorBuilder locationStrategy(final FileLocationStrategy strategy) - { - locationStrategy = strategy; - return this; - } - - /** - * Creates a new immutable {@code FileLocatorImpl} object based on the - * properties set so far for this builder. - * - * @return the newly created {@code FileLocator} object - */ - public FileLocator create() - { - return new FileLocator(this); - } - - /** - * Initializes the properties of this builder from the passed in locator - * object. - * - * @param src the source {@code FileLocator} - */ - private void initBuilder(final FileLocator src) - { - basePath = src.getBasePath(); - fileName = src.getFileName(); - sourceURL = src.getSourceURL(); - encoding = src.getEncoding(); - fileSystem = src.getFileSystem(); - locationStrategy = src.getLocationStrategy(); - } - } }