From 47b1a28bbab80dd1a68dc0285d83a1c967b9cb55 Mon Sep 17 00:00:00 2001 From: Pascal Essiembre Date: Wed, 28 Aug 2024 23:52:54 -0400 Subject: [PATCH] Removed some inline XML in javadoc. --- .../commons/lang/bean/BeanMapper.java | 4 +- .../EmptyWithClosingTagXmlFactory.java | 3 +- .../lang/config/ConfigurationLoader.java | 9 +- .../norconex/commons/lang/event/Event.java | 15 +- .../commons/lang/flow/FlowMapperConfig.java | 6 +- .../norconex/commons/lang/jar/JarCopier.java | 6 - .../com/norconex/commons/lang/net/Host.java | 5 - .../commons/lang/net/ProxySettings.java | 119 ++++---------- .../commons/lang/security/Credentials.java | 40 +---- .../com/norconex/commons/lang/text/Regex.java | 35 +---- .../lang/text/RegexFieldValueExtractor.java | 26 ---- .../commons/lang/text/StringUtil.java | 1 + .../commons/lang/text/TextMatcher.java | 41 +---- .../commons/lang/version/SemanticVersion.java | 32 +--- .../lang/version/SemanticVersionParser.java | 43 ++--- .../commons/lang/xml/XMLFormatter.java | 147 +++++++++--------- .../norconex/commons/lang/xml/flow/XMLIf.java | 14 +- .../commons/lang/xml/flow/XMLIfNot.java | 3 +- 18 files changed, 152 insertions(+), 397 deletions(-) diff --git a/src/main/java/com/norconex/commons/lang/bean/BeanMapper.java b/src/main/java/com/norconex/commons/lang/bean/BeanMapper.java index 37dedb2c..dfb324a3 100644 --- a/src/main/java/com/norconex/commons/lang/bean/BeanMapper.java +++ b/src/main/java/com/norconex/commons/lang/bean/BeanMapper.java @@ -142,7 +142,8 @@ * treated as if annotated with {@literal @}valid. That * configuration class will be populated without the need for "configuration" * wrapper elements (automatically adds {@literal @}JsonUnwrapped - * This behavior can be turned off with {@link #configurableDetectionDisabled} + * This behavior can be turned off with + * {@link BeanMapperBuilder#configurableDetectionDisabled(boolean)} *

* @since 3.0.0 */ @@ -486,7 +487,6 @@ public ObjectMapper toObjectMapper(Format format) { }); } - // @JsonIgnoreType // <-- messes up nested object deserializing since update of Jackson abstract static class ConfigurableMixIn { @JsonUnwrapped @Valid diff --git a/src/main/java/com/norconex/commons/lang/bean/jackson/EmptyWithClosingTagXmlFactory.java b/src/main/java/com/norconex/commons/lang/bean/jackson/EmptyWithClosingTagXmlFactory.java index 6a0f76ae..e5e64046 100644 --- a/src/main/java/com/norconex/commons/lang/bean/jackson/EmptyWithClosingTagXmlFactory.java +++ b/src/main/java/com/norconex/commons/lang/bean/jackson/EmptyWithClosingTagXmlFactory.java @@ -25,7 +25,8 @@ import com.fasterxml.jackson.dataformat.xml.util.DefaultXmlPrettyPrinter; /** - * Version of {@link XmlFactory} that configures a {@link XmlPrettyPrinter} + * Version of {@link XmlFactory} that configures a + * {@link com.fasterxml.jackson.dataformat.xml.XmlPrettyPrinter} * to write "empty" objects with a closing tag instead of self-closing. * Self-closing are treated as null and a pair of tags witn * no content is treated as empty. diff --git a/src/main/java/com/norconex/commons/lang/config/ConfigurationLoader.java b/src/main/java/com/norconex/commons/lang/config/ConfigurationLoader.java index 3b482235..6acbc48e 100644 --- a/src/main/java/com/norconex/commons/lang/config/ConfigurationLoader.java +++ b/src/main/java/com/norconex/commons/lang/config/ConfigurationLoader.java @@ -14,7 +14,6 @@ */ package com.norconex.commons.lang.config; -import java.io.IOException; import java.io.Reader; import java.io.StringReader; import java.io.StringWriter; @@ -332,11 +331,9 @@ public XML toXml( * @param type class of the object to create and populate * @param type of returned object * @return new object - * @throws IOException * @since 3.0.0 */ - public T toObject(@NonNull Path configFile, Class type) - throws IOException { + public T toObject(@NonNull Path configFile, Class type) { return beanMapper.read( type, new StringReader(toString(configFile)), @@ -356,11 +353,9 @@ public T toObject(@NonNull Path configFile, Class type) * Loads an XML configuration file and populates a given object. * @param configFile XML configuration file * @param object object to populate - * @throws IOException * @since 3.0.0 */ - public void toObject(@NonNull Path configFile, @NonNull Object object) - throws IOException { + public void toObject(@NonNull Path configFile, @NonNull Object object) { beanMapper.read( object, new StringReader(toString(configFile)), diff --git a/src/main/java/com/norconex/commons/lang/event/Event.java b/src/main/java/com/norconex/commons/lang/event/Event.java index 745da6f4..c14af42c 100644 --- a/src/main/java/com/norconex/commons/lang/event/Event.java +++ b/src/main/java/com/norconex/commons/lang/event/Event.java @@ -39,27 +39,18 @@ public class Event extends EventObjectAdapter { private static final long serialVersionUID = 1L; /** - * Gets the event name (never null). - * @param name the event name - * @return event name + * The event name (never null). */ - @SuppressWarnings("javadoc") @NonNull private final String name; /** - * Gets a message describing the event or giving precision, + * A message describing the event or giving precision, * or null if the event has no message. - * @param message the event message - * @return event message */ - @SuppressWarnings("javadoc") private final String message; /** - * Gets the exception associated with this event, or null. - * @param exception an exception - * @return event message + * The exception associated with this event, or null. */ - @SuppressWarnings("javadoc") private final transient Throwable exception; /** diff --git a/src/main/java/com/norconex/commons/lang/flow/FlowMapperConfig.java b/src/main/java/com/norconex/commons/lang/flow/FlowMapperConfig.java index b2a0246a..883ba323 100644 --- a/src/main/java/com/norconex/commons/lang/flow/FlowMapperConfig.java +++ b/src/main/java/com/norconex/commons/lang/flow/FlowMapperConfig.java @@ -28,12 +28,10 @@ public class FlowMapperConfig { private final FlowPolymorphicType> consumerType = new FlowPolymorphicType<>(); /** - * Provide a custom name to be used when a consumer is being serialized. + * A function that takes a consumer about to be serialize and returns + * a custom name for it. * When not specified or returning null, the default is * "consumer". - * @param consumerNameProvider name provider - * @return consumer name */ - @SuppressWarnings("javadoc") private Function, String> consumerNameProvider; } \ No newline at end of file diff --git a/src/main/java/com/norconex/commons/lang/jar/JarCopier.java b/src/main/java/com/norconex/commons/lang/jar/JarCopier.java index 957f8b48..d2bcfd8b 100644 --- a/src/main/java/com/norconex/commons/lang/jar/JarCopier.java +++ b/src/main/java/com/norconex/commons/lang/jar/JarCopier.java @@ -525,17 +525,11 @@ static TargetAction of(int option) { /** * Action to perform (or not) on source file. - * @param sourceAction source action - * @return {@code this}. */ - @SuppressWarnings("javadoc") private final SourceAction sourceAction; /** * Action to perform (or not) on target file. - * @param targetAction target action - * @return {@code this}. */ - @SuppressWarnings("javadoc") private final TargetAction targetAction; public OnJarConflict() { diff --git a/src/main/java/com/norconex/commons/lang/net/Host.java b/src/main/java/com/norconex/commons/lang/net/Host.java index 43954d55..060eebdb 100644 --- a/src/main/java/com/norconex/commons/lang/net/Host.java +++ b/src/main/java/com/norconex/commons/lang/net/Host.java @@ -28,11 +28,6 @@ /** * Holds a host name and port. - * - * {@nx.xml.usage - * (host name) - * (host port) - * } * @since 2.0.0 */ @EqualsAndHashCode diff --git a/src/main/java/com/norconex/commons/lang/net/ProxySettings.java b/src/main/java/com/norconex/commons/lang/net/ProxySettings.java index 2f7d03b1..c440253e 100644 --- a/src/main/java/com/norconex/commons/lang/net/ProxySettings.java +++ b/src/main/java/com/norconex/commons/lang/net/ProxySettings.java @@ -24,51 +24,44 @@ import com.norconex.commons.lang.bean.BeanUtil; import com.norconex.commons.lang.security.Credentials; -import lombok.AccessLevel; -import lombok.EqualsAndHashCode; -import lombok.ToString; -import lombok.experimental.FieldNameConstants; +import lombok.Data; +import lombok.experimental.Accessors; import lombok.extern.slf4j.Slf4j; /** *

* Convenience class for implementation requiring proxy settings. *

- * - * {@nx.include com.norconex.commons.lang.security.Credentials#doc} - * - * {@nx.xml.usage - * - * {@nx.include com.norconex.commons.lang.net.Host@nx.xml.usage} - * - * (Default is "http") - * (Authentication realm. Default is any.) - * - * {@nx.include com.norconex.commons.lang.security.Credentials@nx.xml.usage} - * - * } - *

The above can be found under any parent tag. See consuming class - * documentation for exact usage.

- * * @since 1.14.0 */ -@SuppressWarnings("javadoc") -@ToString -@EqualsAndHashCode -@FieldNameConstants(level = AccessLevel.PRIVATE) @Slf4j @JsonAutoDetect( fieldVisibility = Visibility.ANY, getterVisibility = Visibility.NONE, isGetterVisibility = Visibility.NONE ) +@Data +@Accessors(chain = true) public class ProxySettings implements Serializable { private static final long serialVersionUID = 1L; + /** Proxy host (name and port), or null when not set. */ private Host host; + /** + * Proxy scheme (default is "http"). + * @since 2.0.0 + */ private String scheme; + /** + * Proxy credentials, when required or applicable. Never null. + * @since 2.0.0 + */ private final Credentials credentials = new Credentials(); + /** + * Proxy authentication realm, when required or applicable. + * @since 2.0.0 + */ private String realm; public ProxySettings() { @@ -82,54 +75,6 @@ public ProxySettings(Host host) { this.host = host; } - /** - * Gets the proxy host. - * @return proxy host or null if not set - * @see #isSet() - */ - public Host getHost() { - return host; - } - - /** - * Sets the proxy host. - * @param host proxy host - * @return this - */ - public ProxySettings setHost(Host host) { - this.host = host; - return this; - } - - /** - * Gets the proxy scheme. - * @return proxy scheme - * @since 2.0.0 - */ - public String getScheme() { - return scheme; - } - - /** - * Sets the proxy scheme. - * @param scheme proxy scheme - * @return this - * @since 2.0.0 - */ - public ProxySettings setScheme(String scheme) { - this.scheme = scheme; - return this; - } - - /** - * Gets the proxy credentials. - * @return proxy credentials (never null) - * @since 2.0.0 - */ - public Credentials getCredentials() { - return credentials; - } - /** * Sets the proxy credentials. * @param credentials proxy credentials @@ -142,33 +87,27 @@ public ProxySettings setCredentials(Credentials credentials) { } /** - * Gets the proxy realm. - * @return proxy realm - * @since 2.0.0 + * Wether this proxy is configured. That is, if the host is not + * null and also configured. + * @return true if set + * @see Host#isSet() */ - public String getRealm() { - return realm; - } - - /** - * Sets the proxy realm. - * @param realm proxy realm - * @return this - * @since 2.0.0 - */ - public ProxySettings setRealm(String realm) { - this.realm = realm; - return this; - } - public boolean isSet() { return host != null && host.isSet(); } + /** + * Copy properties of this instance to the supplied instance. + * @param another another proxy settings instance + */ public void copyTo(ProxySettings another) { BeanUtil.copyProperties(another, this); } + /** + * Copy properties of the supplied instance to this instance. + * @param another another proxy settings instance + */ public void copyFrom(ProxySettings another) { BeanUtil.copyProperties(this, another); } diff --git a/src/main/java/com/norconex/commons/lang/security/Credentials.java b/src/main/java/com/norconex/commons/lang/security/Credentials.java index 63db13fd..0c92f2b4 100644 --- a/src/main/java/com/norconex/commons/lang/security/Credentials.java +++ b/src/main/java/com/norconex/commons/lang/security/Credentials.java @@ -73,39 +73,10 @@ *

* } * - * {@nx.xml.usage - * (the username) - * (the optionally encrypted password) - * - * (The actual password encryption key or a reference to it.) - * [key|file|environment|property] - * (Size in bits of encryption key. Default is 128.) - * - * } - *

- * The expected parent tag name is defined by the consuming classes. - *

- * - * {@nx.xml.example - * - * goldorak - * 3ncryp73d - * - * /path/to/my.key - * file - * - * - * } - *

- * The above example has the password encrypted with a key. The encryption - * key is stored in a file (required to decrypt the password). - *

- * * @since 2.0.0 * @see EncryptionKey * @see EncryptionUtil */ -@SuppressWarnings("javadoc") @FieldNameConstants(level = AccessLevel.PRIVATE) @Data @Accessors(chain = true) @@ -120,21 +91,15 @@ public class Credentials implements Serializable { /** * Credential user name. - * @param username user name - * @return {@code this}. */ private String username; /** * Credential password. - * @param password password - * @return {@code this}. */ private String password; /** * Credential password encryption key pointer (provided the password is * encrypted). - * @param passwordKey password key - * @return {@code this}. */ private EncryptionKey passwordKey; @@ -175,6 +140,11 @@ public Credentials(Credentials copy) { copyFrom(copy); } + /** + * Whether this credentials instance is set. That is, if any of + * user name and password is not blank. + * @return true if set + */ public boolean isSet() { return !isEmpty(); } diff --git a/src/main/java/com/norconex/commons/lang/text/Regex.java b/src/main/java/com/norconex/commons/lang/text/Regex.java index adf7a92b..0d5f34ea 100644 --- a/src/main/java/com/norconex/commons/lang/text/Regex.java +++ b/src/main/java/com/norconex/commons/lang/text/Regex.java @@ -52,37 +52,6 @@ * behaves as if the value is an empty string. *

* - * {@nx.xml.usage #attributes - * ignoreCase="[false|true]" - * ignoreDiacritic="[false|true]" - * dotAll="[false|true]" - * unixLines="[false|true]" - * literal="[false|true]" - * comments="[false|true]" - * multiline="[false|true]" - * canonEq="[false|true]" - * unicodeCase="[false|true]" - * unicodeCharacterClass="[false|true]" - * trim="[false|true]" - * matchEmpty="[false|true]" - * } - *

- * The above are configurable attributes consuming classes can expect. - * The actual regular expression is expected to be the tag content. - * Many of the available attributes on XML configuration represent the - * regular expression flags as defined in {@link Pattern}. - *

- * - * {@nx.xml.example - * - * ^start.*end$ - * - * } - *

- * The above will match any text that starts with "start" and ends with "ends", - * regardless if there are new line characters in between. - *

- * * @since 2.0.0 * @see Pattern */ @@ -352,7 +321,7 @@ public String getPattern() { *

*

* For text-matching with diacritical mark insensitivity support enabled, - * or for {@link #trim} and {@link #matchEmpty} support, + * or for {@link #trim()} and {@link #matchEmpty()} support, * use {@link #matcher(CharSequence)} instead. *

* @return compiled pattern @@ -368,7 +337,7 @@ public Pattern compile() { *

*

* For text-matching with diacritical mark insensitivity support enabled, - * or for {@link #trim} and {@link #matchEmpty} support, + * or for {@link #trim()} and {@link #matchEmpty()} support, * use {@link #matcher(String, CharSequence)} instead. *

* @param pattern the pattern to compile diff --git a/src/main/java/com/norconex/commons/lang/text/RegexFieldValueExtractor.java b/src/main/java/com/norconex/commons/lang/text/RegexFieldValueExtractor.java index 7d56658e..ed4890b6 100644 --- a/src/main/java/com/norconex/commons/lang/text/RegexFieldValueExtractor.java +++ b/src/main/java/com/norconex/commons/lang/text/RegexFieldValueExtractor.java @@ -19,7 +19,6 @@ import java.util.Map.Entry; import java.util.Objects; import java.util.regex.Matcher; -import java.util.regex.Pattern; import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.StringUtils; @@ -53,31 +52,6 @@ * case insensitivity and dots matching any character. *

* - * {@nx.xml.usage #attributes - * toField="(toField name)" - * fieldGroup="(toField name match group index)" - * valueGroup="(value match group index)" - * {@nx.include com.norconex.commons.lang.map.PropertySetter#attributes} - * {@nx.include com.norconex.commons.lang.text.Regex#attributes} - * } - * - *

- * The above are configurable attributes consuming classes can expect. - * The actual regular expression is expected to be the tag content. - * Many of the available attributes on XML configuration represent the - * regular expression flags as defined in {@link Pattern}. - *

- * - * {@nx.xml.example - * - * (DocNo):(\d+) - * - * } - *

- * The above is configured to extract "DocNo" as the toField, and the following - * numeric characters will make up the value. - *

- * * @since 2.0.0 (moved from Norconex Importer RegexKeyValueExtractor) */ @SuppressWarnings("javadoc") diff --git a/src/main/java/com/norconex/commons/lang/text/StringUtil.java b/src/main/java/com/norconex/commons/lang/text/StringUtil.java index 86f5c74a..2c8b80ff 100644 --- a/src/main/java/com/norconex/commons/lang/text/StringUtil.java +++ b/src/main/java/com/norconex/commons/lang/text/StringUtil.java @@ -379,6 +379,7 @@ public static String singular(String plural) { * singular variant. You are encouraged to used a more sophisticated * approach if accuracy is important. * @param plural plural word + * @param defaultValue default value if singular can't be resolved * @return singular word or null * @since 3.0.0 */ diff --git a/src/main/java/com/norconex/commons/lang/text/TextMatcher.java b/src/main/java/com/norconex/commons/lang/text/TextMatcher.java index b15ffa89..b5ea8697 100644 --- a/src/main/java/com/norconex/commons/lang/text/TextMatcher.java +++ b/src/main/java/com/norconex/commons/lang/text/TextMatcher.java @@ -74,44 +74,6 @@ * {@link #replace(String, String)}. *

* - * {@nx.xml.usage #attributes - * method="[basic|csv|wildcard|regex]" - * ignoreCase="[false|true]" - * ignoreDiacritic="[false|true]" - * replaceAll="[false|true]" - * partial="[false|true]" - * trim="[false|true]" - * matchEmpty="[false|true]" - * } - * - *

- * The above are configurable attributes consuming classes can expect. - * The actual expression is expected to be the tag content. - *

- * - *

- * When simply matching (no replacements) the attributes are the same, - * minus the "replaceAll" (which is simply ignored): - *

- * {@nx.xml #matchAttributes - * method="[basic|csv|wildcard|regex]" - * ignoreCase="[false|true]" - * ignoreDiacritic="[false|true]" - * partial="[false|true]" - * trim="[false|true]" - * matchEmpty="[false|true]" - * } - * - * {@nx.xml.example - * - * paul*mar? - * - * } - *

- * Given a text of "It seems Paul and Marc are friends" and a replacement of - * "they", the above will result in "It seems they are friends.". - *

- * * @since 2.0.0 */ @ToString @@ -356,7 +318,7 @@ public boolean isNegateMatches() { * Sets whether to negates the result of invoking * {@link #matches(CharSequence)}. * Note: only applies to the {@link #matches(CharSequence)} method. - * @parm negateMatches true to negate matches + * @param negateMatches true to negate matches * @return this * @since 3.0.0 */ @@ -382,6 +344,7 @@ public TextMatcher negateMatches() { * Sets whether to negates the result of invoking * {@link #matches(CharSequence)} on a copy of this instance. * Note: only applies to the {@link #matches(CharSequence)} method. + * @param negateMatches true to negate matches * @return this * @since 3.0.0 */ diff --git a/src/main/java/com/norconex/commons/lang/version/SemanticVersion.java b/src/main/java/com/norconex/commons/lang/version/SemanticVersion.java index de694b76..adaca742 100644 --- a/src/main/java/com/norconex/commons/lang/version/SemanticVersion.java +++ b/src/main/java/com/norconex/commons/lang/version/SemanticVersion.java @@ -20,7 +20,6 @@ import java.util.Comparator; import java.util.Objects; import java.util.function.Predicate; -import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.stream.Stream; @@ -97,38 +96,23 @@ static PreRelease of(String preRelease) { /** * Major version number. The first number of a semantic version. - * @param major major number - * @return {@code this}. */ - @SuppressWarnings("javadoc") private final int major; /** * Minor version number. The second number of a semantic version. - * @param minor minor number - * @return {@code this}. */ - @SuppressWarnings("javadoc") private final int minor; /** * Patch version number. The third number of a semantic version. - * @param patch patch number - * @return {@code this}. */ - @SuppressWarnings("javadoc") private final int patch; /** * Optional pre-release indicator (M1, RC1, etc.). - * @param preRelease pre-release indicator - * @return {@code this}. */ - @SuppressWarnings("javadoc") private final String preRelease; /** * Optional metadata associated with a build. - * @param buildMetadata build metadata - * @return {@code this}. */ - @SuppressWarnings("javadoc") private final String buildMetadata; /** @@ -209,7 +193,7 @@ public int compareTo(SemanticVersion o) { } // Compare major.minor.patch - int result = new CompareToBuilder() + var result = new CompareToBuilder() .append(major, o.major) .append(minor, o.minor) .append(patch, o.patch) @@ -219,8 +203,8 @@ public int compareTo(SemanticVersion o) { } // Compare pre-release - String thisPrTxt = lowerCase(trimToNull(preRelease)); - String thatPrTxt = lowerCase(trimToNull(o.preRelease)); + var thisPrTxt = lowerCase(trimToNull(preRelease)); + var thatPrTxt = lowerCase(trimToNull(o.preRelease)); if (Objects.equals(thisPrTxt, thatPrTxt)) { return 0; @@ -231,16 +215,16 @@ public int compareTo(SemanticVersion o) { } // both pre-releases can't be null at this point - PreRelease thisPr = PreRelease.of(thisPrTxt); - PreRelease thatPr = PreRelease.of(thatPrTxt); + var thisPr = PreRelease.of(thisPrTxt); + var thatPr = PreRelease.of(thatPrTxt); result = Integer.compare(thisPr.weight, thatPr.weight); if (result != 0) { return result; } // extract numerical values (if any) and compare them. - Matcher thisMatcher = numberPattern.matcher(thisPrTxt); - Matcher thatMatcher = numberPattern.matcher(thatPrTxt); + var thisMatcher = numberPattern.matcher(thisPrTxt); + var thatMatcher = numberPattern.matcher(thatPrTxt); while (thisMatcher.find()) { // if this matcher has more numbers, it is higher if (!thatMatcher.find()) { @@ -316,7 +300,7 @@ public boolean isLowerOrEquivalentTo(SemanticVersion other) { */ @Override public String toString() { - StringBuilder b = new StringBuilder() + var b = new StringBuilder() .append(major).append('.') .append(minor).append('.') .append(patch); diff --git a/src/main/java/com/norconex/commons/lang/version/SemanticVersionParser.java b/src/main/java/com/norconex/commons/lang/version/SemanticVersionParser.java index f45292b8..3a7f1942 100644 --- a/src/main/java/com/norconex/commons/lang/version/SemanticVersionParser.java +++ b/src/main/java/com/norconex/commons/lang/version/SemanticVersionParser.java @@ -17,7 +17,6 @@ import java.util.Arrays; import java.util.List; import java.util.Objects; -import java.util.regex.Matcher; import java.util.regex.Pattern; import org.apache.commons.lang3.StringUtils; @@ -37,9 +36,10 @@ *

* The maximum string length supported by this parser is 255 characters. * Longer strings will throw a {@link SemanticVersionParserException} - * except when {@link #ignoreLeadingCharacters} is true. In such - * case, it will try parsing longer strings, but will only - * consider the last 255 characters. + * except when + * {@link SemanticVersionParserBuilder#ignoreLeadingCharacters(boolean)} is + * true. In such case, it will try parsing longer strings, but + * will only consider the last 255 characters. *

* @since 3.0.0 */ @@ -107,11 +107,7 @@ public class SemanticVersionParser { *
  • 1.2 is interpreted as 1.2.0
  • *
  • 3 is interpreted as 3.0.0
  • * - * @param optionalMinorAndPatch true if minor and patch - * numbers are optional - * @return {@code this}. */ - @SuppressWarnings("javadoc") private final boolean optionalMinorAndPatch; /** *

    @@ -123,11 +119,7 @@ public class SemanticVersionParser { *

  • 1.2.3RC1 is interpreted as 1.2.3-RC1
  • *
  • 1.2.3_M3 is interpreted as 1.2.3-M3
  • * - * @param optionalPreReleasePrefix true if pre-release prefix - * presence is optional - * @return {@code this}. */ - @SuppressWarnings("javadoc") private final boolean optionalPreReleasePrefix; /** *

    @@ -139,11 +131,7 @@ public class SemanticVersionParser { *

  • v1.2.3 is interpreted as 1.2.3
  • *
  • some-library-1.2.3 is interpreted as 1.2.3
  • * - * @param ignoreLeadingCharacters true if ignoring leading - * characters - * @return {@code this}. */ - @SuppressWarnings("javadoc") private final boolean ignoreLeadingCharacters; /** *

    @@ -155,10 +143,7 @@ public class SemanticVersionParser { *

      *
    • 1.2.3.jar is interpreted as 1.2.3
    • *
    - * @param ignoreSuffixes suffixes to be ignored when extracting version - * @return {@code this}. */ - @SuppressWarnings("javadoc") @Singular(ignoreNullCollections = true, value = "ignoreSuffix") private List ignoreSuffixes; @@ -169,7 +154,7 @@ public class SemanticVersionParser { * @throws SemanticVersionParserException if the version can't be parsed. */ public SemanticVersion parse(String version) { - String v = StringUtils.trimToNull(version); + var v = StringUtils.trimToNull(version); if (v == null) { throw new SemanticVersionParserException( @@ -183,26 +168,26 @@ public SemanticVersion parse(String version) { v = v.replaceFirst("^.*[^\\w\\.\\+-](.*)$", "$1"); } for (String suffix : ignoreSuffixes) { - String before = v; + var before = v; v = StringUtils.removeEnd(v, suffix); if (Objects.equals(before, v)) { break; } } - Matcher m = semverPattern.matcher(v); + var m = semverPattern.matcher(v); if (!m.matches()) { throw new SemanticVersionParserException( "Could not parse: " + version); } - String leadingChars = m.group("leadingchars"); - String major = m.group("major"); - String minor = m.group("minor"); - String patch = m.group("patch"); - String preReleasePrefix = m.group("prereleaseprefix"); - String preRelease = m.group("prerelease"); - String metadata = m.group("buildmetadata"); + var leadingChars = m.group("leadingchars"); + var major = m.group("major"); + var minor = m.group("minor"); + var patch = m.group("patch"); + var preReleasePrefix = m.group("prereleaseprefix"); + var preRelease = m.group("prerelease"); + var metadata = m.group("buildmetadata"); if (!ignoreLeadingCharacters && StringUtils.isNotBlank(leadingChars)) { throw new SemanticVersionParserException( diff --git a/src/main/java/com/norconex/commons/lang/xml/XMLFormatter.java b/src/main/java/com/norconex/commons/lang/xml/XMLFormatter.java index de23dfbd..02cd09fb 100644 --- a/src/main/java/com/norconex/commons/lang/xml/XMLFormatter.java +++ b/src/main/java/com/norconex/commons/lang/xml/XMLFormatter.java @@ -26,7 +26,6 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; -import java.util.regex.Matcher; import java.util.regex.Pattern; import org.apache.commons.collections4.map.ListOrderedMap; @@ -79,7 +78,7 @@ public String format(XML xml) { } public String format(String xml) { - StringWriter w = new StringWriter(); + var w = new StringWriter(); try { format(new StringReader(xml), w); } catch (IOException e) { @@ -92,10 +91,10 @@ public String format(String xml) { public void format(Reader reader, Writer writer) throws IOException { Writer w = IOUtils.buffer(writer); - int depth = 0; - TokenReader tokenReader = new TokenReader(reader, cfg); + var depth = 0; + var tokenReader = new TokenReader(reader, cfg); Token token = null; - boolean first = true; + var first = true; while ((token = tokenReader.next()) != null) { if (!first) { w.append('\n'); @@ -119,7 +118,7 @@ static class TokenReader { final Builder cfg; TokenReader(Reader reader, Builder cfg) { - this.r = IOUtils.buffer(reader); + r = IOUtils.buffer(reader); this.cfg = cfg; } @@ -128,7 +127,7 @@ Token next() throws IOException { skipWhiteSpaces(r); r.mark(1); - int ch = r.read(); + var ch = r.read(); r.reset(); if (ch == -1) { return null; @@ -191,7 +190,7 @@ public Element(Builder cfg) { @Override void read(Reader r) throws IOException { - final StringBuilder b = new StringBuilder(); + final var b = new StringBuilder(); skipWhiteSpaces(r); r.skip(1); // '<' @@ -204,13 +203,13 @@ void read(Reader r) throws IOException { b.setLength(0); IOUtil.consumeUntil(r, c -> c == '>', b); - String attribsStr = b.toString().trim(); + var attribsStr = b.toString().trim(); if (attribsStr.endsWith("/")) { closed = true; selfClosed = true; } attribsStr = StringUtils.removeEnd(attribsStr, "/"); - Matcher m = ATTRIB_PATTERN.matcher(attribsStr); + var m = ATTRIB_PATTERN.matcher(attribsStr); while (m.find()) { attribs.put(m.group(1).trim(), m.group(2).trim()); } @@ -221,14 +220,14 @@ void read(Reader r) throws IOException { if (!closed) { b.setLength(0); IOUtil.consumeUntil(r, c -> c == '<', b); - String txt = b.toString(); + var txt = b.toString(); flIndent = firstLineIndentSize(txt); directContent = txt.trim(); } //--- Possible closing Tag --- r.mark(name.length() + 3); - char[] chars = new char[name.length() + 3]; + var chars = new char[name.length() + 3]; r.read(chars); if (("").equals(new String(chars))) { closed = true; @@ -245,7 +244,7 @@ void read(Reader r) throws IOException { @Override void write(Appendable w, String margin) throws IOException { - boolean attribsWrapped = false; + var attribsWrapped = false; // name w.append(margin).append('<').append(name); @@ -267,11 +266,11 @@ void write(Appendable w, String margin) throws IOException { // possible direct content // we "nest" on any the following conditions: - boolean nestContent = !closed || attribsWrapped; + var nestContent = !closed || attribsWrapped; if (StringUtils.isNotBlank(directContent)) { - String trimmedContent = directContent.trim(); + var trimmedContent = directContent.trim(); // line length = margin + '' + content + '' - int lineLength = margin.length() + (name.length() * 2) + 5 + var lineLength = margin.length() + (name.length() * 2) + 5 + trimmedContent.length(); nestContent = nestContent || StringUtils.containsAny(trimmedContent, "\n\r") @@ -298,18 +297,21 @@ void write(Appendable w, String margin) throws IOException { // returns whether it wrapped private boolean writeAttributes(Appendable w, String margin) throws IOException { - switch (cfg.attributeWrap) { - case NONE: + return switch (cfg.attributeWrap) { + case NONE: { writeAttribsWrapNone(w); - return false; + yield false; + } case AT_MAX: - return writeAttribsWrapAtMax(w, margin); + yield writeAttribsWrapAtMax(w, margin); case AT_MAX_ALL: - return writeAttribsWrapAtMaxAll(w, margin); + yield writeAttribsWrapAtMaxAll(w, margin); default: // ALL + { writeAttribsWarpAll(w, margin); - return true; - } + yield true; + } + }; } private void writeAttribsWrapNone(Appendable w) @@ -335,7 +337,7 @@ private boolean writeAttribsWrapAtMaxAll(Appendable w, String margin) return false; } - int tagEndLength = 0; + var tagEndLength = 0; if (!cfg.closeWrappingTagOnOwnLine) { // '/>' vs '>' tagEndLength = (selfClosed) ? 2 : 1; @@ -343,7 +345,7 @@ private boolean writeAttribsWrapAtMaxAll(Appendable w, String margin) // Calculate the potential text length: // '<' + name length + all attribs length + '>' or '/>' - int txtLength = 1 + name.length() + var txtLength = 1 + name.length() + attribs.entrySet().stream() .mapToInt(en -> en.getKey().length() + en.getValue().length() + 4) @@ -354,28 +356,27 @@ private boolean writeAttribsWrapAtMaxAll(Appendable w, String margin) && txtLength >= cfg.minTextLength) { writeAttribsWarpAll(w, margin); return true; - } else { - writeAttribsWrapNone(w); - return false; } + writeAttribsWrapNone(w); + return false; } private boolean writeAttribsWrapAtMax(Appendable w, String margin) throws IOException { - boolean wrapped = false; - int tagEndLength = 0; + var wrapped = false; + var tagEndLength = 0; if (!cfg.closeWrappingTagOnOwnLine) { // '/>' vs '>' tagEndLength = (selfClosed) ? 2 : 1; } // we start the text length at '<' + name length - int txtLength = name.length() + 1; + var txtLength = name.length() + 1; for (Entry en : attribs.entrySet()) { - String attribute = en.getKey() + "=\"" + en.getValue() + "\""; + var attribute = en.getKey() + "=\"" + en.getValue() + "\""; // ' ' + attribute txtLength += attribute.length() + 1; - int lineLength = margin.length() + txtLength + tagEndLength; + var lineLength = margin.length() + txtLength + tagEndLength; if (lineLength > cfg.maxLineLength && txtLength >= cfg.minTextLength) { // wrap and indent @@ -405,9 +406,9 @@ public FreeContent(Builder cfg) { @Override void read(Reader r) throws IOException { - StringBuilder b = new StringBuilder(); + var b = new StringBuilder(); IOUtil.consumeUntil(r, c -> c == '<', b); - String txt = b.toString(); + var txt = b.toString(); flIndent = firstLineIndentSize(txt); text = b.toString().trim(); } @@ -430,7 +431,7 @@ public CloserTag(Builder cfg) { @Override void read(Reader r) throws IOException { - StringBuilder b = new StringBuilder(); + var b = new StringBuilder(); r.skip(2); // ' c == '>', b); name = b.toString().trim(); @@ -454,7 +455,7 @@ public CData(Builder cfg) { @Override void read(Reader r) throws IOException { - StringBuilder b = new StringBuilder(); + var b = new StringBuilder(); IOUtil.consumeUntil(r, "]]>", b); text = b.toString().trim(); } @@ -475,12 +476,12 @@ public Comment(Builder cfg) { @Override void read(Reader r) throws IOException { - StringBuilder b = new StringBuilder(); + var b = new StringBuilder(); r.skip(4); // '", b); b.setLength(b.length() - 3); - String txt = b.toString(); + var txt = b.toString(); flIndent = firstLineIndentSize(txt); text = txt.trim(); } @@ -498,9 +499,9 @@ void write(Appendable w, String margin) throws IOException { w.append(margin).append("