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 2020/06/26 19:15:41 UTC
[commons-text] branch master updated: Move isMatch(char[],
int) from the package private AbstractStringMatcher to the public
StringMatcher.
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 212e62a Move isMatch(char[], int) from the package private AbstractStringMatcher to the public StringMatcher.
212e62a is described below
commit 212e62aad166ee731d4c114319b17de7c55189fb
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Fri Jun 26 15:15:35 2020 -0400
Move isMatch(char[], int) from the package private
AbstractStringMatcher to the public StringMatcher.
---
.../text/matcher/AbstractStringMatcher.java | 24 ---------------------
.../apache/commons/text/matcher/StringMatcher.java | 25 ++++++++++++++++++++++
.../commons/text/matcher/StringMatcherTest.java | 7 ++++++
3 files changed, 32 insertions(+), 24 deletions(-)
diff --git a/src/main/java/org/apache/commons/text/matcher/AbstractStringMatcher.java b/src/main/java/org/apache/commons/text/matcher/AbstractStringMatcher.java
index 69e3955..e3cd696 100644
--- a/src/main/java/org/apache/commons/text/matcher/AbstractStringMatcher.java
+++ b/src/main/java/org/apache/commons/text/matcher/AbstractStringMatcher.java
@@ -263,30 +263,6 @@ abstract class AbstractStringMatcher implements StringMatcher {
super();
}
- /**
- * Returns the number of matching characters, zero for no match.
- * <p>
- * This method is called to check for a match. The parameter {@code pos} represents the current position to be
- * checked in the string {@code buffer} (a character array which must not be changed). The API guarantees that
- * {@code pos} is a valid index for {@code buffer}.
- * </p>
- * <p>
- * The matching code may check one character or many. It may check characters preceding {@code pos} as well as those
- * after.
- * </p>
- * <p>
- * It must return zero for no match, or a positive number if a match was found. The number indicates the number of
- * characters that matched.
- * </p>
- *
- * @param buffer the text content to match against, do not change
- * @param pos the starting position for the match, valid for buffer
- * @return The number of matching characters, zero for no match
- */
- public int isMatch(final char[] buffer, final int pos) {
- return isMatch(buffer, pos, 0, buffer.length);
- }
-
// /**
// * Validates indices for {@code bufferStart <= start < bufferEnd}.
// *
diff --git a/src/main/java/org/apache/commons/text/matcher/StringMatcher.java b/src/main/java/org/apache/commons/text/matcher/StringMatcher.java
index 4d5226f..9d14ffd 100644
--- a/src/main/java/org/apache/commons/text/matcher/StringMatcher.java
+++ b/src/main/java/org/apache/commons/text/matcher/StringMatcher.java
@@ -53,6 +53,31 @@ public interface StringMatcher {
int isMatch(char[] buffer, int start, int bufferStart, int bufferEnd);
/**
+ * Returns the number of matching characters, zero for no match.
+ * <p>
+ * This method is called to check for a match. The parameter {@code pos} represents the current position to be
+ * checked in the string {@code buffer} (a character array which must not be changed). The API guarantees that
+ * {@code pos} is a valid index for {@code buffer}.
+ * </p>
+ * <p>
+ * The matching code may check one character or many. It may check characters preceding {@code pos} as well as those
+ * after.
+ * </p>
+ * <p>
+ * It must return zero for no match, or a positive number if a match was found. The number indicates the number of
+ * characters that matched.
+ * </p>
+ *
+ * @param buffer the text content to match against, do not change
+ * @param pos the starting position for the match, valid for buffer
+ * @return The number of matching characters, zero for no match
+ * @since 1.9
+ */
+ default int isMatch(final char[] buffer, final int pos) {
+ return isMatch(buffer, pos, 0, buffer.length);
+ }
+
+ /**
* Returns the size of the matching string. Defaults to 0.
*
* @return the size of the matching string.
diff --git a/src/test/java/org/apache/commons/text/matcher/StringMatcherTest.java b/src/test/java/org/apache/commons/text/matcher/StringMatcherTest.java
index 22bf989..c96aa75 100644
--- a/src/test/java/org/apache/commons/text/matcher/StringMatcherTest.java
+++ b/src/test/java/org/apache/commons/text/matcher/StringMatcherTest.java
@@ -40,6 +40,13 @@ public class StringMatcherTest {
assertThat(matcher.isMatch(BUFFER2, 3, 0, BUFFER2.length)).isEqualTo(0);
assertThat(matcher.isMatch(BUFFER2, 4, 0, BUFFER2.length)).isEqualTo(0);
assertThat(matcher.isMatch(BUFFER2, 5, 0, BUFFER2.length)).isEqualTo(0);
+ //
+ assertThat(matcher.isMatch(BUFFER2, 0)).isEqualTo(0);
+ assertThat(matcher.isMatch(BUFFER2, 1)).isEqualTo(0);
+ assertThat(matcher.isMatch(BUFFER2, 2)).isEqualTo(1);
+ assertThat(matcher.isMatch(BUFFER2, 3)).isEqualTo(0);
+ assertThat(matcher.isMatch(BUFFER2, 4)).isEqualTo(0);
+ assertThat(matcher.isMatch(BUFFER2, 5)).isEqualTo(0);
}
@Test