From commits-return-61419-archive-asf-public=cust-asf.ponee.io@commons.apache.org Mon Feb 12 18:22:10 2018 Return-Path: X-Original-To: archive-asf-public@eu.ponee.io Delivered-To: archive-asf-public@eu.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by mx-eu-01.ponee.io (Postfix) with ESMTP id 80415180652 for ; Mon, 12 Feb 2018 18:22:10 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 7098A160C64; Mon, 12 Feb 2018 17:22:10 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 91D58160C62 for ; Mon, 12 Feb 2018 18:22:09 +0100 (CET) Received: (qmail 10077 invoked by uid 500); 12 Feb 2018 17:22:08 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 9750 invoked by uid 99); 12 Feb 2018 17:22:08 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 12 Feb 2018 17:22:08 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id DD034E9640; Mon, 12 Feb 2018 17:22:07 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: ggregory@apache.org To: commits@commons.apache.org Date: Mon, 12 Feb 2018 17:22:11 -0000 Message-Id: <93e692f0fd004895a47632e943525c6a@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [5/5] [text] [TEXT-114] Add a replacement for StrSubstitutor based on interfaces: StringSubstitutor. [TEXT-114] Add a replacement for StrSubstitutor based on interfaces: StringSubstitutor. Project: http://git-wip-us.apache.org/repos/asf/commons-text/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-text/commit/4b67dd51 Tree: http://git-wip-us.apache.org/repos/asf/commons-text/tree/4b67dd51 Diff: http://git-wip-us.apache.org/repos/asf/commons-text/diff/4b67dd51 Branch: refs/heads/master Commit: 4b67dd516dbb23b31d4b35d3f737f31de86a1cda Parents: 3e649a7 Author: Gary Gregory Authored: Mon Feb 12 10:22:04 2018 -0700 Committer: Gary Gregory Committed: Mon Feb 12 10:22:04 2018 -0700 ---------------------------------------------------------------------- src/changes/changes.xml | 1 + .../commons/text/ExtendedMessageFormat.java | 4 +- .../java/org/apache/commons/text/StrLookup.java | 2 +- .../org/apache/commons/text/StrMatcher.java | 22 +- .../org/apache/commons/text/StrSubstitutor.java | 2663 +++++++++--------- .../apache/commons/text/StringSubstitutor.java | 1359 +++++++++ .../text/lookup/AbstractStringLookup.java | 4 - .../commons/text/lookup/StringLookup.java | 4 - .../commons/text/lookup/package-info.java | 2 +- .../text/matcher/AbstractStringMatcher.java | 256 ++ .../commons/text/matcher/StringMatcher.java | 55 + .../text/matcher/StringMatcherFactory.java | 228 ++ .../commons/text/matcher/package-info.java | 25 + .../apache/commons/text/StrSubstitutorTest.java | 1708 ++++++----- ...titutorWithInterpolatorStringLookupTest.java | 47 - .../commons/text/StringSubstitutorTest.java | 622 ++++ ...titutorWithInterpolatorStringLookupTest.java | 49 + .../commons/text/matcher/StringMatcherTest.java | 219 ++ .../matcher/StringSubstitutorGetSetTest.java | 119 + 19 files changed, 5058 insertions(+), 2331 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/commons-text/blob/4b67dd51/src/changes/changes.xml ---------------------------------------------------------------------- diff --git a/src/changes/changes.xml b/src/changes/changes.xml index eedd7ac..778d77a 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -49,6 +49,7 @@ The type attribute can be add,update,fix,remove. Add Automatic-Module-Name MANIFEST entry for Java 9 compatibility Build failure with java 9-ea+159 Add an interpolator string lookup + Add a replacement for StrSubstitutor based on interfaces: StringSubstitutor http://git-wip-us.apache.org/repos/asf/commons-text/blob/4b67dd51/src/main/java/org/apache/commons/text/ExtendedMessageFormat.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/text/ExtendedMessageFormat.java b/src/main/java/org/apache/commons/text/ExtendedMessageFormat.java index cfe1bf4..612845f 100644 --- a/src/main/java/org/apache/commons/text/ExtendedMessageFormat.java +++ b/src/main/java/org/apache/commons/text/ExtendedMessageFormat.java @@ -27,6 +27,8 @@ import java.util.Locale.Category; import java.util.Map; import java.util.Objects; +import org.apache.commons.text.matcher.StringMatcherFactory; + /** * Extends java.text.MessageFormat to allow pluggable/additional formatting * options for embedded format elements. Client code should specify a registry @@ -490,7 +492,7 @@ public class ExtendedMessageFormat extends MessageFormat { int len = 0; final char[] buffer = pattern.toCharArray(); do { - len = StrMatcher.splitMatcher().isMatch(buffer, pos.getIndex()); + len = StringMatcherFactory.INSTANCE.splitMatcher().isMatch(buffer, pos.getIndex(), 0, buffer.length); pos.setIndex(pos.getIndex() + len); } while (len > 0 && pos.getIndex() < pattern.length()); } http://git-wip-us.apache.org/repos/asf/commons-text/blob/4b67dd51/src/main/java/org/apache/commons/text/StrLookup.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/text/StrLookup.java b/src/main/java/org/apache/commons/text/StrLookup.java index 320e097..6357869 100644 --- a/src/main/java/org/apache/commons/text/StrLookup.java +++ b/src/main/java/org/apache/commons/text/StrLookup.java @@ -36,7 +36,7 @@ import org.apache.commons.text.lookup.StringLookupFactory; * * @param the type of the values supported by the lookup * @since 1.0 - * @deprecated Use {@link StringLookupFactory}. + * @deprecated Use {@link StringLookupFactory}. This class will be removed in 2.0. */ @Deprecated public abstract class StrLookup implements StringLookup { http://git-wip-us.apache.org/repos/asf/commons-text/blob/4b67dd51/src/main/java/org/apache/commons/text/StrMatcher.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/text/StrMatcher.java b/src/main/java/org/apache/commons/text/StrMatcher.java index 161d9a1..466eab4 100644 --- a/src/main/java/org/apache/commons/text/StrMatcher.java +++ b/src/main/java/org/apache/commons/text/StrMatcher.java @@ -18,6 +18,8 @@ package org.apache.commons.text; import java.util.Arrays; +import org.apache.commons.text.matcher.StringMatcherFactory; + /** * A matcher class that can be queried to determine if a character array * portion matches. @@ -26,7 +28,9 @@ import java.util.Arrays; * If these do not suffice, you can subclass and implement your own matcher. * * @since 1.0 + * @deprecated Use {@link StringMatcherFactory}. This class will be removed in 2.0. */ +@Deprecated public abstract class StrMatcher { /** @@ -223,7 +227,7 @@ public abstract class StrMatcher { } /** - * Returns the number of matching characters, zero for no match. + * Returns the number of matching characters, or zero if there is no match. *

* This method is called to check for a match. * The parameter pos represents the current position to be @@ -245,12 +249,12 @@ public abstract class StrMatcher { * @param pos the starting position for the match, valid for buffer * @param bufferStart the first active index in the buffer, valid for buffer * @param bufferEnd the end index (exclusive) of the active buffer, valid for buffer - * @return the number of matching characters, zero for no match + * @return the number of matching characters, or zero if there is no match */ public abstract int isMatch(char[] buffer, int pos, int bufferStart, int bufferEnd); /** - * Returns the number of matching characters, zero for no match. + * Returns the number of matching characters, or zero if there is no match. *

* This method is called to check for a match. * The parameter pos represents the current position to be @@ -266,7 +270,7 @@ public abstract class StrMatcher { * * @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 + * @return the number of matching characters, or zero if there is no match */ public int isMatch(final char[] buffer, final int pos) { return isMatch(buffer, pos, 0, buffer.length); @@ -298,7 +302,7 @@ public abstract class StrMatcher { * @param pos the starting position for the match, valid for buffer * @param bufferStart the first active index in the buffer, valid for buffer * @param bufferEnd the end index of the active buffer, valid for buffer - * @return the number of matching characters, zero for no match + * @return the number of matching characters, or zero if there is no match */ @Override public int isMatch(final char[] buffer, final int pos, final int bufferStart, final int bufferEnd) { @@ -331,7 +335,7 @@ public abstract class StrMatcher { * @param pos the starting position for the match, valid for buffer * @param bufferStart the first active index in the buffer, valid for buffer * @param bufferEnd the end index of the active buffer, valid for buffer - * @return the number of matching characters, zero for no match + * @return the number of matching characters, or zero if there is no match */ @Override public int isMatch(final char[] buffer, final int pos, final int bufferStart, final int bufferEnd) { @@ -364,7 +368,7 @@ public abstract class StrMatcher { * @param pos the starting position for the match, valid for buffer * @param bufferStart the first active index in the buffer, valid for buffer * @param bufferEnd the end index of the active buffer, valid for buffer - * @return the number of matching characters, zero for no match + * @return the number of matching characters, or zero if there is no match */ @Override public int isMatch(final char[] buffer, int pos, final int bufferStart, final int bufferEnd) { @@ -407,7 +411,7 @@ public abstract class StrMatcher { * @param pos the starting position for the match, valid for buffer * @param bufferStart the first active index in the buffer, valid for buffer * @param bufferEnd the end index of the active buffer, valid for buffer - * @return the number of matching characters, zero for no match + * @return the number of matching characters, or zero if there is no match */ @Override public int isMatch(final char[] buffer, final int pos, final int bufferStart, final int bufferEnd) { @@ -435,7 +439,7 @@ public abstract class StrMatcher { * @param pos the starting position for the match, valid for buffer * @param bufferStart the first active index in the buffer, valid for buffer * @param bufferEnd the end index of the active buffer, valid for buffer - * @return the number of matching characters, zero for no match + * @return the number of matching characters, or zero if there is no match */ @Override public int isMatch(final char[] buffer, final int pos, final int bufferStart, final int bufferEnd) {