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 d0e9ad75e800988604f3b0d927fde90e0eed4e17
Author: Gary Gregory <garydgreg...@gmail.com>
AuthorDate: Sat Jun 27 10:33:32 2020 -0400

    Replace internal NullStringLookup with a FunctionStringLookup.
---
 .../commons/text/lookup/NullStringLookup.java      | 47 ----------------------
 .../commons/text/lookup/StringLookupFactory.java   |  9 ++++-
 .../commons/text/lookup/NullStringLookupTest.java  |  5 ++-
 .../text/lookup/StringLookupFactoryTest.java       |  2 +-
 4 files changed, 11 insertions(+), 52 deletions(-)

diff --git a/src/main/java/org/apache/commons/text/lookup/NullStringLookup.java 
b/src/main/java/org/apache/commons/text/lookup/NullStringLookup.java
deleted file mode 100644
index f873e55..0000000
--- a/src/main/java/org/apache/commons/text/lookup/NullStringLookup.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache license, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the license for the specific language governing permissions and
- * limitations under the license.
- */
-
-package org.apache.commons.text.lookup;
-
-/**
- * Always returns null.
- *
- * @since 1.3
- */
-final class NullStringLookup extends AbstractStringLookup {
-
-    /**
-     * Defines the singleton for this class.
-     */
-    static final NullStringLookup INSTANCE = new NullStringLookup();
-
-    /**
-     * No need to build instances for now.
-     */
-    private NullStringLookup() {
-        // empty
-    }
-
-    /**
-     * Always returns null.
-     */
-    @Override
-    public String lookup(final String key) {
-        return null;
-    }
-
-}
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 5233fc6..3cced40 100644
--- a/src/main/java/org/apache/commons/text/lookup/StringLookupFactory.java
+++ b/src/main/java/org/apache/commons/text/lookup/StringLookupFactory.java
@@ -149,7 +149,12 @@ public final class StringLookupFactory {
     public static final StringLookupFactory INSTANCE = new 
StringLookupFactory();
 
     /**
-     * Defines the singleton for this class.
+     * Defines the FunctionStringLookup singleton that always returns null.
+     */
+    static final FunctionStringLookup<String> INSTANCE_NULL = 
FunctionStringLookup.on(key -> null);
+
+    /**
+     * Defines the FunctionStringLookup singleton for looking up system 
properties.
      */
     static final FunctionStringLookup<String> INSTANCE_SYSTEM_PROPERTY = 
FunctionStringLookup.on(key -> System.getProperty(key));
 
@@ -712,7 +717,7 @@ public final class StringLookupFactory {
      * @return The NullStringLookup singleton instance.
      */
     public StringLookup nullStringLookup() {
-        return NullStringLookup.INSTANCE;
+        return StringLookupFactory.INSTANCE_NULL;
     }
 
     /**
diff --git 
a/src/test/java/org/apache/commons/text/lookup/NullStringLookupTest.java 
b/src/test/java/org/apache/commons/text/lookup/NullStringLookupTest.java
index fa5fc47..cb2feb5 100644
--- a/src/test/java/org/apache/commons/text/lookup/NullStringLookupTest.java
+++ b/src/test/java/org/apache/commons/text/lookup/NullStringLookupTest.java
@@ -21,13 +21,14 @@ import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.Test;
 
 /**
- * Tests {@link NullStringLookup}.
+ * Tests {@link StringLookupFactory#INSTANCE_NULL}.
  */
 public class NullStringLookupTest {
 
     @Test
     public void test() {
-        Assertions.assertEquals(null, 
NullStringLookup.INSTANCE.lookup("EverythingIsNull"));
+        Assertions.assertEquals(null, 
StringLookupFactory.INSTANCE_NULL.lookup("EverythingIsNull"));
+        Assertions.assertEquals(null, 
StringLookupFactory.INSTANCE_NULL.lookup(null));
     }
 
 }
diff --git 
a/src/test/java/org/apache/commons/text/lookup/StringLookupFactoryTest.java 
b/src/test/java/org/apache/commons/text/lookup/StringLookupFactoryTest.java
index 3f209cb..f4b23b1 100644
--- a/src/test/java/org/apache/commons/text/lookup/StringLookupFactoryTest.java
+++ b/src/test/java/org/apache/commons/text/lookup/StringLookupFactoryTest.java
@@ -78,7 +78,7 @@ public class StringLookupFactoryTest {
         Assertions.assertSame(InterpolatorStringLookup.INSTANCE, 
stringLookupFactory.interpolatorStringLookup());
         Assertions.assertSame(JavaPlatformStringLookup.INSTANCE, 
stringLookupFactory.javaPlatformStringLookup());
         Assertions.assertSame(LocalHostStringLookup.INSTANCE, 
stringLookupFactory.localHostStringLookup());
-        Assertions.assertSame(NullStringLookup.INSTANCE, 
stringLookupFactory.nullStringLookup());
+        Assertions.assertSame(StringLookupFactory.INSTANCE_NULL, 
stringLookupFactory.nullStringLookup());
         Assertions.assertSame(ResourceBundleStringLookup.INSTANCE, 
stringLookupFactory.resourceBundleStringLookup());
         Assertions.assertSame(ScriptStringLookup.INSTANCE, 
stringLookupFactory.scriptStringLookup());
         Assertions.assertSame(StringLookupFactory.INSTANCE_SYSTEM_PROPERTY, 
stringLookupFactory.systemPropertyStringLookup());

Reply via email to