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 2018/02/11 16:51:21 UTC

[text] [TEXT-113] Add an interpolator string lookup. No long needs to subclass StrLookup. Fix class cast ex. Fix checkstyle. Javadoc.

Repository: commons-text
Updated Branches:
  refs/heads/master 29f1108c3 -> 6afbdc8a4


[TEXT-113] Add an interpolator string lookup. No long needs to subclass
StrLookup. Fix class cast ex. Fix checkstyle. Javadoc.

Project: http://git-wip-us.apache.org/repos/asf/commons-text/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-text/commit/6afbdc8a
Tree: http://git-wip-us.apache.org/repos/asf/commons-text/tree/6afbdc8a
Diff: http://git-wip-us.apache.org/repos/asf/commons-text/diff/6afbdc8a

Branch: refs/heads/master
Commit: 6afbdc8a494047bac49080a26d1b60984c72f745
Parents: 29f1108
Author: Gary Gregory <ga...@gmail.com>
Authored: Sun Feb 11 09:51:18 2018 -0700
Committer: Gary Gregory <ga...@gmail.com>
Committed: Sun Feb 11 09:51:18 2018 -0700

----------------------------------------------------------------------
 .../org/apache/commons/text/StrSubstitutor.java | 15 ++++-
 .../text/lookup/InterpolatorStringLookup.java   |  6 +-
 .../text/lookup/StringLookupFactory.java        | 58 ++++++++++++++++++++
 3 files changed, 74 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-text/blob/6afbdc8a/src/main/java/org/apache/commons/text/StrSubstitutor.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/text/StrSubstitutor.java b/src/main/java/org/apache/commons/text/StrSubstitutor.java
index 9a39b66..9fc5aa6 100644
--- a/src/main/java/org/apache/commons/text/StrSubstitutor.java
+++ b/src/main/java/org/apache/commons/text/StrSubstitutor.java
@@ -1026,7 +1026,7 @@ public class StrSubstitutor {
      * Writers of subclasses can override this method if they need to alter
      * how each substitution occurs. The method is passed the variable's name
      * and must return the corresponding value. This implementation uses the
-     * {@link #getVariableResolver()} with the variable's name as the key.
+     * {@link #getStringLookup()} with the variable's name as the key.
      *
      * @param variableName  the name of the variable, not null
      * @param buf  the buffer where the substitution is occurring, not null
@@ -1038,7 +1038,7 @@ public class StrSubstitutor {
                                      final StrBuilder buf,
                                      final int startPos,
                                      final int endPos) {
-        final StrLookup<?> resolver = getVariableResolver();
+        final StringLookup resolver = getStringLookup();
         if (resolver == null) {
             return null;
         }
@@ -1262,10 +1262,21 @@ public class StrSubstitutor {
     // Resolver
     //-----------------------------------------------------------------------
     /**
+     * Gets the StringLookup that is used to lookup variables.
+     *
+     * @return the StringLookup
+     */
+    public StringLookup getStringLookup() {
+        return this.variableResolver;
+    }
+
+    /**
      * Gets the VariableResolver that is used to lookup variables.
      *
      * @return the VariableResolver
+     * @deprecated Use {@link #getStringLookup()}.
      */
+    @Deprecated
     public StrLookup<?> getVariableResolver() {
         return (StrLookup<?>) this.variableResolver;
     }

http://git-wip-us.apache.org/repos/asf/commons-text/blob/6afbdc8a/src/main/java/org/apache/commons/text/lookup/InterpolatorStringLookup.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/text/lookup/InterpolatorStringLookup.java b/src/main/java/org/apache/commons/text/lookup/InterpolatorStringLookup.java
index b8e4d37..c175f67 100644
--- a/src/main/java/org/apache/commons/text/lookup/InterpolatorStringLookup.java
+++ b/src/main/java/org/apache/commons/text/lookup/InterpolatorStringLookup.java
@@ -44,7 +44,7 @@ class InterpolatorStringLookup extends AbstractStringLookup {
      * <li>"date" for the DateStringLookup.</li>
      * </ul>
      */
-    public InterpolatorStringLookup() {
+    InterpolatorStringLookup() {
         this((Map<String, String>) null);
     }
 
@@ -63,7 +63,7 @@ class InterpolatorStringLookup extends AbstractStringLookup {
      * @param defaultMap
      *            the default map for string lookups.
      */
-    public <V> InterpolatorStringLookup(final Map<String, V> defaultMap) {
+    <V> InterpolatorStringLookup(final Map<String, V> defaultMap) {
         this(MapStringLookup.on(defaultMap == null ? new HashMap<String, V>() : defaultMap));
         // TODO: Use a service loader
         stringLookupMap.put("sys", SystemPropertyStringLookup.INSTANCE);
@@ -78,7 +78,7 @@ class InterpolatorStringLookup extends AbstractStringLookup {
      * @param defaultStringLookup
      *            the default lookup.
      */
-    public InterpolatorStringLookup(final StringLookup defaultStringLookup) {
+    InterpolatorStringLookup(final StringLookup defaultStringLookup) {
         this.defaultStringLookup = defaultStringLookup;
     }
 

http://git-wip-us.apache.org/repos/asf/commons-text/blob/6afbdc8a/src/main/java/org/apache/commons/text/lookup/StringLookupFactory.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/text/lookup/StringLookupFactory.java b/src/main/java/org/apache/commons/text/lookup/StringLookupFactory.java
index 7dbea93..58b0f3b 100644
--- a/src/main/java/org/apache/commons/text/lookup/StringLookupFactory.java
+++ b/src/main/java/org/apache/commons/text/lookup/StringLookupFactory.java
@@ -38,42 +38,100 @@ public class StringLookupFactory {
         // empty
     }
 
+    /**
+     * Returns the DateStringLookup singleton instance.
+     *
+     * @return the DateStringLookup singleton instance.
+     */
     public StringLookup dateStringLookup() {
         return DateStringLookup.INSTANCE;
     }
 
+    /**
+     * Returns the EnvironmentVariableStringLookup singleton instance.
+     *
+     * @return the EnvironmentVariableStringLookup singleton instance.
+     */
     public StringLookup environmentVariableStringLookup() {
         return EnvironmentVariableStringLookup.INSTANCE;
     }
 
+    /**
+     * Returns a new InterpolatorStringLookup.
+     *
+     * @return a new InterpolatorStringLookup.
+     */
     public StringLookup interpolatorStringLookup() {
         return new InterpolatorStringLookup();
     }
 
+    /**
+     * Returns a new InterpolatorStringLookup.
+     *
+     * @param <V> the value type the default string lookup's map.
+     * @param map
+     *            the default map for string lookups.
+     * @return a new InterpolatorStringLookup.
+     */
     public <V> StringLookup interpolatorStringLookup(final Map<String, V> map) {
         return new InterpolatorStringLookup(map);
     }
 
+    /**
+     * Returns a new InterpolatorStringLookup.
+     *
+     * @param defaultStringLookup
+     *            the default string lookup.
+     * @return a new InterpolatorStringLookup.
+     */
     public StringLookup interpolatorStringLookup(final StringLookup defaultStringLookup) {
         return new InterpolatorStringLookup(defaultStringLookup);
     }
 
+    /**
+     * Returns the JavaPlatformStringLookup singleton instance.
+     *
+     * @return the JavaPlatformStringLookup singleton instance.
+     */
     public StringLookup javaPlatformStringLookup() {
         return JavaPlatformStringLookup.INSTANCE;
     }
 
+    /**
+     * Returns a new MapStringLookup.
+     *
+     * @param <V> the map value type.
+     * @param map
+     *            the map.
+     * @return a new MapStringLookup.
+     */
     public <V> StringLookup mapStringLookup(final Map<String, V> map) {
         return MapStringLookup.on(map);
     }
 
+    /**
+     * Returns the NullStringLookup singleton instance.
+     *
+     * @return the NullStringLookup singleton instance.
+     */
     public StringLookup nullStringLookup() {
         return NullStringLookup.INSTANCE;
     }
 
+    /**
+     * Returns the ResourceBundleStringLookup singleton instance.
+     *
+     * @return the ResourceBundleStringLookup singleton instance.
+     */
     public StringLookup resourceBundleStringLookup() {
         return ResourceBundleStringLookup.INSTANCE;
     }
 
+    /**
+     * Returns the SystemPropertyStringLookup singleton instance.
+     *
+     * @return the SystemPropertyStringLookup singleton instance.
+     */
     public StringLookup systemPropertyStringLookup() {
         return SystemPropertyStringLookup.INSTANCE;
     }