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 2019/07/26 21:16:11 UTC

[commons-text] branch master updated (67a6372 -> 8c8155d)

This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/commons-text.git.


    from 67a6372  [TEXT-169] Add helper factory method org.apache.commons.text.StringSubstitutor.createInterpolator().
     new e50bca2  Sort methods.
     new 58b2ec1  Sort members.
     new 84193fe  Simplify.
     new 8c8155d  Fix Javadoc.

The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../commons/text/lookup/DefaultStringLookup.java   |  16 +--
 .../commons/text/lookup/LocalHostStringLookup.java |  31 ++---
 .../apache/commons/text/StringSubstitutorTest.java | 136 ++++++++++-----------
 3 files changed, 87 insertions(+), 96 deletions(-)


[commons-text] 01/04: Sort methods.

Posted by gg...@apache.org.
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

commit e50bca213f0fa181807c2333618b048b71a40946
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Fri Jul 26 13:05:14 2019 -0400

    Sort methods.
---
 .../apache/commons/text/StringSubstitutorTest.java | 136 ++++++++++-----------
 1 file changed, 68 insertions(+), 68 deletions(-)

diff --git a/src/test/java/org/apache/commons/text/StringSubstitutorTest.java b/src/test/java/org/apache/commons/text/StringSubstitutorTest.java
index b4390d8..6f18e7b 100644
--- a/src/test/java/org/apache/commons/text/StringSubstitutorTest.java
+++ b/src/test/java/org/apache/commons/text/StringSubstitutorTest.java
@@ -255,6 +255,74 @@ public class StringSubstitutorTest {
     }
 
     /**
+     * Tests replace with fail on undefined variable.
+     */
+    @Test
+    public void testReplaceFailOnUndefinedVariable() {
+        values.put("animal.1", "fox");
+        values.put("animal.2", "mouse");
+        values.put("species", "2");
+        final StringSubstitutor sub = new StringSubstitutor(values);
+        sub.setEnableUndefinedVariableException(true);
+
+        assertThatIllegalArgumentException().isThrownBy(() ->
+        sub.replace("The ${animal.${species}} jumps over the ${target}.")).
+        withMessage("Cannot resolve variable 'animal.${species' (enableSubstitutionInVariables=false).");
+
+        assertThatIllegalArgumentException().isThrownBy(() ->
+        sub.replace("The ${animal.${species:-1}} jumps over the ${target}.")).
+        withMessage("Cannot resolve variable 'animal.${species:-1' (enableSubstitutionInVariables=false).");
+
+        assertThatIllegalArgumentException().isThrownBy(() ->
+        sub.replace("The ${test:-statement} is a sample for missing ${unknown}.")).
+        withMessage("Cannot resolve variable 'unknown' (enableSubstitutionInVariables=false).");
+
+        //if default value is available, exception will not be thrown
+        assertEquals("The statement is a sample for missing variable.",
+                sub.replace("The ${test:-statement} is a sample for missing ${unknown:-variable}."));
+
+        assertEquals("The fox jumps over the lazy dog.",
+                sub.replace("The ${animal.1} jumps over the ${target}."));
+    }
+
+    /**
+     * Tests whether replace with fail on undefined variable with
+     * substitution in variable names enabled.
+     */
+    @Test
+    public void testReplaceFailOnUndefinedVariableWithReplaceInVariable() {
+        values.put("animal.1", "fox");
+        values.put("animal.2", "mouse");
+        values.put("species", "2");
+        values.put("statement.1", "2");
+        values.put("recursive", "1");
+        values.put("word", "variable");
+        values.put("testok.2", "statement");
+        final StringSubstitutor sub = new StringSubstitutor(values);
+        sub.setEnableUndefinedVariableException(true);
+        sub.setEnableSubstitutionInVariables(true);
+
+        assertEquals("The mouse jumps over the lazy dog.",
+                sub.replace("The ${animal.${species}} jumps over the ${target}."));
+        values.put("species", "1");
+        assertEquals("The fox jumps over the lazy dog.",
+                sub.replace("The ${animal.${species}} jumps over the ${target}."));
+
+        //exception is thrown here because variable with name test.1 is missing
+        assertThatIllegalArgumentException().isThrownBy(() ->
+        sub.replace("The ${test.${statement}} is a sample for missing ${word}.")).
+        withMessage("Cannot resolve variable 'statement' (enableSubstitutionInVariables=true).");
+
+        //exception is thrown here because variable with name test.2 is missing
+        assertThatIllegalArgumentException().isThrownBy(() ->
+        sub.replace("The ${test.${statement.${recursive}}} is a sample for missing ${word}.")).
+        withMessage("Cannot resolve variable 'test.2' (enableSubstitutionInVariables=true).");
+
+        assertEquals("The statement is a sample for missing variable.",
+                sub.replace("The ${testok.${statement.${recursive}}} is a sample for missing ${word}."));
+    }
+
+    /**
      * Tests when no incomplete prefix.
      */
     @Test
@@ -338,74 +406,6 @@ public class StringSubstitutorTest {
     }
 
     /**
-     * Tests replace with fail on undefined variable.
-     */
-    @Test
-    public void testReplaceFailOnUndefinedVariable() {
-        values.put("animal.1", "fox");
-        values.put("animal.2", "mouse");
-        values.put("species", "2");
-        final StringSubstitutor sub = new StringSubstitutor(values);
-        sub.setEnableUndefinedVariableException(true);
-
-        assertThatIllegalArgumentException().isThrownBy(() ->
-        sub.replace("The ${animal.${species}} jumps over the ${target}.")).
-        withMessage("Cannot resolve variable 'animal.${species' (enableSubstitutionInVariables=false).");
-
-        assertThatIllegalArgumentException().isThrownBy(() ->
-        sub.replace("The ${animal.${species:-1}} jumps over the ${target}.")).
-        withMessage("Cannot resolve variable 'animal.${species:-1' (enableSubstitutionInVariables=false).");
-
-        assertThatIllegalArgumentException().isThrownBy(() ->
-        sub.replace("The ${test:-statement} is a sample for missing ${unknown}.")).
-        withMessage("Cannot resolve variable 'unknown' (enableSubstitutionInVariables=false).");
-
-        //if default value is available, exception will not be thrown
-        assertEquals("The statement is a sample for missing variable.",
-                sub.replace("The ${test:-statement} is a sample for missing ${unknown:-variable}."));
-
-        assertEquals("The fox jumps over the lazy dog.",
-                sub.replace("The ${animal.1} jumps over the ${target}."));
-    }
-
-    /**
-     * Tests whether replace with fail on undefined variable with
-     * substitution in variable names enabled.
-     */
-    @Test
-    public void testReplaceFailOnUndefinedVariableWithReplaceInVariable() {
-        values.put("animal.1", "fox");
-        values.put("animal.2", "mouse");
-        values.put("species", "2");
-        values.put("statement.1", "2");
-        values.put("recursive", "1");
-        values.put("word", "variable");
-        values.put("testok.2", "statement");
-        final StringSubstitutor sub = new StringSubstitutor(values);
-        sub.setEnableUndefinedVariableException(true);
-        sub.setEnableSubstitutionInVariables(true);
-
-        assertEquals("The mouse jumps over the lazy dog.",
-                sub.replace("The ${animal.${species}} jumps over the ${target}."));
-        values.put("species", "1");
-        assertEquals("The fox jumps over the lazy dog.",
-                sub.replace("The ${animal.${species}} jumps over the ${target}."));
-
-        //exception is thrown here because variable with name test.1 is missing
-        assertThatIllegalArgumentException().isThrownBy(() ->
-        sub.replace("The ${test.${statement}} is a sample for missing ${word}.")).
-        withMessage("Cannot resolve variable 'statement' (enableSubstitutionInVariables=true).");
-
-        //exception is thrown here because variable with name test.2 is missing
-        assertThatIllegalArgumentException().isThrownBy(() ->
-        sub.replace("The ${test.${statement.${recursive}}} is a sample for missing ${word}.")).
-        withMessage("Cannot resolve variable 'test.2' (enableSubstitutionInVariables=true).");
-
-        assertEquals("The statement is a sample for missing variable.",
-                sub.replace("The ${testok.${statement.${recursive}}} is a sample for missing ${word}."));
-    }
-
-    /**
      * Tests complex and recursive substitution in variable names.
      */
     @Test


[commons-text] 03/04: Simplify.

Posted by gg...@apache.org.
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

commit 84193fef76ad3efa2c2e7c93aca8a6c944aeb07f
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Fri Jul 26 13:52:46 2019 -0400

    Simplify.
---
 .../commons/text/lookup/LocalHostStringLookup.java | 29 ++++++++--------------
 1 file changed, 10 insertions(+), 19 deletions(-)

diff --git a/src/main/java/org/apache/commons/text/lookup/LocalHostStringLookup.java b/src/main/java/org/apache/commons/text/lookup/LocalHostStringLookup.java
index ab4681e..2a0f144 100644
--- a/src/main/java/org/apache/commons/text/lookup/LocalHostStringLookup.java
+++ b/src/main/java/org/apache/commons/text/lookup/LocalHostStringLookup.java
@@ -49,8 +49,7 @@ final class LocalHostStringLookup extends AbstractStringLookup {
     /**
      * Looks up the value of the Java platform key.
      *
-     * @param key
-     *            the key to be looked up, may be null
+     * @param key the key to be looked up, may be null
      * @return The value of the environment variable.
      */
     @Override
@@ -58,27 +57,19 @@ final class LocalHostStringLookup extends AbstractStringLookup {
         if (key == null) {
             return null;
         }
-        switch (key) {
-        case "name":
-            try {
+        try {
+            switch (key) {
+            case "name":
                 return InetAddress.getLocalHost().getHostName();
-            } catch (final UnknownHostException e) {
-                return null;
-            }
-        case "canonical-name":
-            try {
+            case "canonical-name":
                 return InetAddress.getLocalHost().getCanonicalHostName();
-            } catch (final UnknownHostException e) {
-                return null;
-            }
-        case "address":
-            try {
+            case "address":
                 return InetAddress.getLocalHost().getHostAddress();
-            } catch (final UnknownHostException e) {
-                return null;
+            default:
+                throw new IllegalArgumentException(key);
             }
-        default:
-            throw new IllegalArgumentException(key);
+        } catch (UnknownHostException e) {
+            return null;
         }
     }
 }


[commons-text] 02/04: Sort members.

Posted by gg...@apache.org.
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

commit 58b2ec145fca98ac0c7ecb51d994bd21f2043654
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Fri Jul 26 13:48:27 2019 -0400

    Sort members.
---
 .../apache/commons/text/lookup/DefaultStringLookup.java  | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/src/main/java/org/apache/commons/text/lookup/DefaultStringLookup.java b/src/main/java/org/apache/commons/text/lookup/DefaultStringLookup.java
index 7fe39e1..ba57578 100644
--- a/src/main/java/org/apache/commons/text/lookup/DefaultStringLookup.java
+++ b/src/main/java/org/apache/commons/text/lookup/DefaultStringLookup.java
@@ -128,20 +128,20 @@ public enum DefaultStringLookup {
     }
 
     /**
-     * Returns the standard {@link StringLookup} instance of this kind.
+     * Returns the standard prefix for the lookup object of this kind.
      *
-     * @return the associated {@link StringLookup} object
+     * @return the prefix
      */
-    public StringLookup getStringLookup() {
-        return lookup;
+    public String getKey() {
+        return key;
     }
 
     /**
-     * Returns the standard prefix for the lookup object of this kind.
+     * Returns the standard {@link StringLookup} instance of this kind.
      *
-     * @return the prefix
+     * @return the associated {@link StringLookup} object
      */
-    public String getKey() {
-        return key;
+    public StringLookup getStringLookup() {
+        return lookup;
     }
 }


[commons-text] 04/04: Fix Javadoc.

Posted by gg...@apache.org.
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

commit 8c8155ddaaa0c0144143a80197088643afde61d6
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Fri Jul 26 13:53:27 2019 -0400

    Fix Javadoc.
---
 .../java/org/apache/commons/text/lookup/LocalHostStringLookup.java    | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/main/java/org/apache/commons/text/lookup/LocalHostStringLookup.java b/src/main/java/org/apache/commons/text/lookup/LocalHostStringLookup.java
index 2a0f144..9f4ee34 100644
--- a/src/main/java/org/apache/commons/text/lookup/LocalHostStringLookup.java
+++ b/src/main/java/org/apache/commons/text/lookup/LocalHostStringLookup.java
@@ -47,9 +47,9 @@ final class LocalHostStringLookup extends AbstractStringLookup {
     }
 
     /**
-     * Looks up the value of the Java platform key.
+     * Looks up the value of a local host key.
      *
-     * @param key the key to be looked up, may be null
+     * @param key the key to be looked up, may be null.
      * @return The value of the environment variable.
      */
     @Override