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-text.git
The following commit(s) were added to refs/heads/master by this push:
new ea6c7947 Make package-private class private in StrMatcher classes
ea6c7947 is described below
commit ea6c79471148557c87b0d644b80bc46f7f531581
Author: Gary Gregory <[email protected]>
AuthorDate: Tue Apr 23 15:58:52 2024 -0400
Make package-private class private in StrMatcher classes
- Make package-private class private: StrMatcher.CharMatcher
- Make package-private class private: StrMatcher.CharSetMatcher
- Make package-private class private: StrMatcher.NoMatcher
- Make package-private class private: StrMatcher.StringMatcher
- Make package-private class private: StrMatcher.TrimMatcher
---
src/changes/changes.xml | 14 ++++-----
.../java/org/apache/commons/text/StrMatcher.java | 10 +++----
.../org/apache/commons/text/StrMatcherTest.java | 17 +++++++++--
.../apache/commons/text/StrSubstitutorTest.java | 33 ++++++++++++++--------
4 files changed, 49 insertions(+), 25 deletions(-)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index c31a9310..b55bb3f8 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -49,14 +49,14 @@ The <action> type attribute can be add,update,fix,remove.
<!-- FIX -->
<action type="fix" dev="ggregory" due-to="Gary Gregory">Fix build on Java
22.</action>
<action type="fix" dev="ggregory" due-to="Gary Gregory">Fix build on Java
23-ea.</action>
- <action type="fix" dev="ggregory" due-to="Gary Gregory">Make internal
constructor private for
org.apache.commons.text.StrLookup.MapStrLookup.MapStrLookup(Map).</action>
- <action type="fix" dev="ggregory" due-to="Gary Gregory">Make internal
constructor private for
org.apache.commons.text.StrLookup.SystemPropertiesStrLookup.SystemPropertiesStrLookup().</action>
+ <action type="fix" dev="ggregory" due-to="Gary Gregory">Make
package-private constructor private:
org.apache.commons.text.StrLookup.MapStrLookup.MapStrLookup(Map).</action>
+ <action type="fix" dev="ggregory" due-to="Gary Gregory">Make
package-private constructor private:
org.apache.commons.text.StrLookup.SystemPropertiesStrLookup.SystemPropertiesStrLookup().</action>
<action type="fix" dev="ggregory" due-to="Gary Gregory">Make
package-private class private and final: MapStrLookup.</action>
- <action type="fix" dev="ggregory" due-to="Gary Gregory">Make
package-private constructor private: StrMatcher.CharMatcher.</action>
- <action type="fix" dev="ggregory" due-to="Gary Gregory">Make
package-private constructor private: StrMatcher.CharSetMatcher.</action>
- <action type="fix" dev="ggregory" due-to="Gary Gregory">Make
package-private constructor private: StrMatcher.NoMatcher.</action>
- <action type="fix" dev="ggregory" due-to="Gary Gregory">Make
package-private constructor private: StrMatcher.StringMatcher.</action>
- <action type="fix" dev="ggregory" due-to="Gary Gregory">Make
package-private constructor private: StrMatcher.TrimMatcher.</action>
+ <action type="fix" dev="ggregory" due-to="Gary Gregory">Make
package-private class private: StrMatcher.CharMatcher.</action>
+ <action type="fix" dev="ggregory" due-to="Gary Gregory">Make
package-private class private: StrMatcher.CharSetMatcher.</action>
+ <action type="fix" dev="ggregory" due-to="Gary Gregory">Make
package-private class private: StrMatcher.NoMatcher.</action>
+ <action type="fix" dev="ggregory" due-to="Gary Gregory">Make
package-private class private: StrMatcher.StringMatcher.</action>
+ <action type="fix" dev="ggregory" due-to="Gary Gregory">Make
package-private class private: StrMatcher.TrimMatcher.</action>
<!-- UPDATE -->
<action type="udpate" dev="ggregory" due-to="Gary Gregory">Bump tests on
Java >= 22 org.graalvm.*:* from 24.0.0 to 24.0.1.</action>
</release>
diff --git a/src/main/java/org/apache/commons/text/StrMatcher.java
b/src/main/java/org/apache/commons/text/StrMatcher.java
index 80be360f..9f35cbf4 100644
--- a/src/main/java/org/apache/commons/text/StrMatcher.java
+++ b/src/main/java/org/apache/commons/text/StrMatcher.java
@@ -38,7 +38,7 @@ public abstract class StrMatcher {
/**
* Class used to define a character for matching purposes.
*/
- static final class CharMatcher extends StrMatcher {
+ private static final class CharMatcher extends StrMatcher {
/** The character to match. */
private final char ch;
@@ -70,7 +70,7 @@ public abstract class StrMatcher {
/**
* Class used to define a set of characters for matching purposes.
*/
- static final class CharSetMatcher extends StrMatcher {
+ private static final class CharSetMatcher extends StrMatcher {
/** The set of characters to match. */
private final char[] chars;
@@ -103,7 +103,7 @@ public abstract class StrMatcher {
/**
* Class used to match no characters.
*/
- static final class NoMatcher extends StrMatcher {
+ private static final class NoMatcher extends StrMatcher {
/**
* Constructs a new instance of {@code NoMatcher}.
@@ -129,7 +129,7 @@ public abstract class StrMatcher {
/**
* Class used to define a set of characters for matching purposes.
*/
- static final class StringMatcher extends StrMatcher {
+ private static final class StringMatcher extends StrMatcher {
/** The string to match, as a character array. */
private final char[] chars;
@@ -176,7 +176,7 @@ public abstract class StrMatcher {
/**
* Class used to match whitespace as per trim().
*/
- static final class TrimMatcher extends StrMatcher {
+ private static final class TrimMatcher extends StrMatcher {
/**
* Constructs a new instance of {@code TrimMatcher}.
diff --git a/src/test/java/org/apache/commons/text/StrMatcherTest.java
b/src/test/java/org/apache/commons/text/StrMatcherTest.java
index afc6e189..d2398538 100644
--- a/src/test/java/org/apache/commons/text/StrMatcherTest.java
+++ b/src/test/java/org/apache/commons/text/StrMatcherTest.java
@@ -17,6 +17,7 @@
package org.apache.commons.text;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;
@@ -32,6 +33,18 @@ public class StrMatcherTest {
private static final char[] BUFFER2 = "abcdef".toCharArray();
+ static void assertStrMatcherImpl(final String internalSimpleName, final
StrMatcher obj) {
+ assertEquals(StrMatcher.class.getName() + "$" + internalSimpleName,
obj.getClass().getName());
+ }
+
+ static void assertStrMatcherPrefixImpl(final String internalSimpleName,
final StrSubstitutor obj) {
+ assertStrMatcherImpl(internalSimpleName,
obj.getVariablePrefixMatcher());
+ }
+
+ static void assertStrMatcherSuffixImpl(final String internalSimpleName,
final StrSubstitutor obj) {
+ assertStrMatcherImpl(internalSimpleName,
obj.getVariableSuffixMatcher());
+ }
+
@Test
public void testCharMatcher_char() {
final StrMatcher matcher = StrMatcher.charMatcher('c');
@@ -54,7 +67,7 @@ public class StrMatcherTest {
assertThat(matcher.isMatch(BUFFER2, 5)).isEqualTo(0);
assertThat(StrMatcher.charSetMatcher()).isSameAs(StrMatcher.noneMatcher());
assertThat(StrMatcher.charSetMatcher((char[])
null)).isSameAs(StrMatcher.noneMatcher());
- assertThat(StrMatcher.charSetMatcher("a".toCharArray()) instanceof
StrMatcher.CharMatcher).isTrue();
+ StrMatcherTest.assertStrMatcherImpl("CharMatcher",
StrMatcher.charSetMatcher("a".toCharArray()));
}
@Test
@@ -68,7 +81,7 @@ public class StrMatcherTest {
assertThat(matcher.isMatch(BUFFER2, 5)).isEqualTo(0);
assertThat(StrMatcher.charSetMatcher("")).isSameAs(StrMatcher.noneMatcher());
assertThat(StrMatcher.charSetMatcher((String)
null)).isSameAs(StrMatcher.noneMatcher());
- assertThat(StrMatcher.charSetMatcher("a") instanceof
StrMatcher.CharMatcher).isTrue();
+ StrMatcherTest.assertStrMatcherImpl("CharMatcher",
StrMatcher.charSetMatcher("a"));
}
@Test
diff --git a/src/test/java/org/apache/commons/text/StrSubstitutorTest.java
b/src/test/java/org/apache/commons/text/StrSubstitutorTest.java
index d532b398..40408fee 100644
--- a/src/test/java/org/apache/commons/text/StrSubstitutorTest.java
+++ b/src/test/java/org/apache/commons/text/StrSubstitutorTest.java
@@ -291,14 +291,18 @@ public class StrSubstitutorTest {
@Test
public void testGetSetPrefix() {
final StrSubstitutor sub = new StrSubstitutor();
- assertTrue(sub.getVariablePrefixMatcher() instanceof
StrMatcher.StringMatcher);
+ StrMatcherTest.assertStrMatcherPrefixImpl("StringMatcher", sub);
+ StrMatcherTest.assertStrMatcherSuffixImpl("StringMatcher", sub);
sub.setVariablePrefix('<');
- assertTrue(sub.getVariablePrefixMatcher() instanceof
StrMatcher.CharMatcher);
+ StrMatcherTest.assertStrMatcherPrefixImpl("CharMatcher", sub);
+ StrMatcherTest.assertStrMatcherSuffixImpl("StringMatcher", sub);
sub.setVariablePrefix("<<");
- assertTrue(sub.getVariablePrefixMatcher() instanceof
StrMatcher.StringMatcher);
+ StrMatcherTest.assertStrMatcherPrefixImpl("StringMatcher", sub);
+ StrMatcherTest.assertStrMatcherSuffixImpl("StringMatcher", sub);
assertThrows(IllegalArgumentException.class, () ->
sub.setVariablePrefix((String) null));
- assertTrue(sub.getVariablePrefixMatcher() instanceof
StrMatcher.StringMatcher);
+ StrMatcherTest.assertStrMatcherPrefixImpl("StringMatcher", sub);
+ StrMatcherTest.assertStrMatcherSuffixImpl("StringMatcher", sub);
final StrMatcher matcher = StrMatcher.commaMatcher();
sub.setVariablePrefixMatcher(matcher);
@@ -313,14 +317,18 @@ public class StrSubstitutorTest {
@Test
public void testGetSetSuffix() {
final StrSubstitutor sub = new StrSubstitutor();
- assertTrue(sub.getVariableSuffixMatcher() instanceof
StrMatcher.StringMatcher);
+ StrMatcherTest.assertStrMatcherPrefixImpl("StringMatcher", sub);
+ StrMatcherTest.assertStrMatcherSuffixImpl("StringMatcher", sub);
sub.setVariableSuffix('<');
- assertTrue(sub.getVariableSuffixMatcher() instanceof
StrMatcher.CharMatcher);
+ StrMatcherTest.assertStrMatcherPrefixImpl("StringMatcher", sub);
+ StrMatcherTest.assertStrMatcherSuffixImpl("CharMatcher", sub);
sub.setVariableSuffix("<<");
- assertTrue(sub.getVariableSuffixMatcher() instanceof
StrMatcher.StringMatcher);
+ StrMatcherTest.assertStrMatcherPrefixImpl("StringMatcher", sub);
+ StrMatcherTest.assertStrMatcherSuffixImpl("StringMatcher", sub);
assertThrows(IllegalArgumentException.class, () ->
sub.setVariableSuffix((String) null));
- assertTrue(sub.getVariableSuffixMatcher() instanceof
StrMatcher.StringMatcher);
+ StrMatcherTest.assertStrMatcherPrefixImpl("StringMatcher", sub);
+ StrMatcherTest.assertStrMatcherSuffixImpl("StringMatcher", sub);
final StrMatcher matcher = StrMatcher.commaMatcher();
sub.setVariableSuffixMatcher(matcher);
@@ -335,12 +343,15 @@ public class StrSubstitutorTest {
@Test
public void testGetSetValueDelimiter() {
final StrSubstitutor sub = new StrSubstitutor();
- assertTrue(sub.getValueDelimiterMatcher() instanceof
StrMatcher.StringMatcher);
+ StrMatcherTest.assertStrMatcherPrefixImpl("StringMatcher", sub);
+ StrMatcherTest.assertStrMatcherSuffixImpl("StringMatcher", sub);
sub.setValueDelimiter(':');
- assertTrue(sub.getValueDelimiterMatcher() instanceof
StrMatcher.CharMatcher);
+ StrMatcherTest.assertStrMatcherPrefixImpl("StringMatcher", sub);
+ StrMatcherTest.assertStrMatcherSuffixImpl("StringMatcher", sub);
sub.setValueDelimiter("||");
- assertTrue(sub.getValueDelimiterMatcher() instanceof
StrMatcher.StringMatcher);
+ StrMatcherTest.assertStrMatcherPrefixImpl("StringMatcher", sub);
+ StrMatcherTest.assertStrMatcherSuffixImpl("StringMatcher", sub);
sub.setValueDelimiter((String) null);
assertNull(sub.getValueDelimiterMatcher());