Repository: commons-text
Updated Branches:
  refs/heads/master b02f37bb0 -> 5d01c5966


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/5d01c596
Tree: http://git-wip-us.apache.org/repos/asf/commons-text/tree/5d01c596
Diff: http://git-wip-us.apache.org/repos/asf/commons-text/diff/5d01c596

Branch: refs/heads/master
Commit: 5d01c5966c3ede23a8ff474dfbd4d076062e2d19
Parents: b02f37b
Author: Gary Gregory <ggreg...@rocketsoftware.com>
Authored: Fri Sep 28 09:21:42 2018 -0600
Committer: Gary Gregory <ggreg...@rocketsoftware.com>
Committed: Fri Sep 28 09:21:42 2018 -0600

----------------------------------------------------------------------
 .../text/lookup/JavaPlatformStringLookup.java   | 333 +++++++++++--------
 .../text/lookup/StringLookupFactory.java        |  34 +-
 2 files changed, 212 insertions(+), 155 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-text/blob/5d01c596/src/main/java/org/apache/commons/text/lookup/JavaPlatformStringLookup.java
----------------------------------------------------------------------
diff --git 
a/src/main/java/org/apache/commons/text/lookup/JavaPlatformStringLookup.java 
b/src/main/java/org/apache/commons/text/lookup/JavaPlatformStringLookup.java
index ee7f556..4155a24 100644
--- a/src/main/java/org/apache/commons/text/lookup/JavaPlatformStringLookup.java
+++ b/src/main/java/org/apache/commons/text/lookup/JavaPlatformStringLookup.java
@@ -1,147 +1,186 @@
-/*
- * 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;
-
-import java.util.Locale;
-
-import org.apache.commons.lang3.StringUtils;
-
-/**
- * Looks up keys related to Java: Java version, JRE version, VM version, and 
so on.
- *
- * @since 1.3
- */
-final class JavaPlatformStringLookup extends AbstractStringLookup {
-
-    /**
-     * Defines the singleton for this class.
-     */
-    static final JavaPlatformStringLookup INSTANCE = new 
JavaPlatformStringLookup();
-
-    /**
-     * No need to build instances for now.
-     */
-    private JavaPlatformStringLookup() {
-        // empty
-    }
-
-    /**
-     * Accessible through the Lookup key {@code hardware}.
-     *
-     * @return hardware processor information.
-     */
-    String getHardware() {
-        return "processors: " + Runtime.getRuntime().availableProcessors() + 
", architecture: "
-                + getSystemProperty("os.arch") + this.getSystemProperty("-", 
"sun.arch.data.model")
-                + this.getSystemProperty(", instruction sets: ", 
"sun.cpu.isalist");
-    }
-
-    /**
-     * Accessible through the Lookup key {@code locale}.
-     *
-     * @return system locale and file encoding information.
-     */
-    String getLocale() {
-        return "default locale: " + Locale.getDefault() + ", platform 
encoding: " + getSystemProperty("file.encoding");
-    }
-
-    /**
-     * Accessible through the Lookup key {@code os}.
-     *
-     * @return operating system information.
-     */
-    String getOperatingSystem() {
-        return getSystemProperty("os.name") + " " + 
getSystemProperty("os.version")
-                + getSystemProperty(" ", "sun.os.patch.level") + ", 
architecture: " + getSystemProperty("os.arch")
-                + getSystemProperty("-", "sun.arch.data.model");
-    }
-
-    /**
-     * Accessible through the Lookup key {@code runtime}.
-     *
-     * @return Java Runtime Environment information.
-     */
-    String getRuntime() {
-        return getSystemProperty("java.runtime.name") + " (build " + 
getSystemProperty("java.runtime.version")
-                + ") from " + getSystemProperty("java.vendor");
-    }
-
-    /**
-     * Gets the given system property.
-     *
-     * @param name
-     *            a system property name.
-     * @return a system property value.
-     */
-    private String getSystemProperty(final String name) {
-        return SystemPropertyStringLookup.INSTANCE.lookup(name);
-    }
-
-    /**
-     * Gets the given system property.
-     *
-     * @param prefix
-     *            the prefix to use for the result string
-     * @param name
-     *            a system property name.
-     * @return the prefix + a system property value.
-     */
-    private String getSystemProperty(final String prefix, final String name) {
-        final String value = getSystemProperty(name);
-        if (StringUtils.isEmpty(value)) {
-            return StringUtils.EMPTY;
-        }
-        return prefix + value;
-    }
-
-    /**
-     * Accessible through the Lookup key {@code vm}.
-     *
-     * @return Java Virtual Machine information.
-     */
-    String getVirtualMachine() {
-        return getSystemProperty("java.vm.name") + " (build " + 
getSystemProperty("java.vm.version") + ", "
-                + getSystemProperty("java.vm.info") + ")";
-    }
-
-    /**
-     * Looks up the value of the Java platform key.
-     *
-     * @param key
-     *            the key to be looked up, may be null
-     * @return The value of the environment variable.
-     */
-    @Override
-    public String lookup(final String key) {
-        switch (key) {
-        case "version":
-            return "Java version " + getSystemProperty("java.version");
-        case "runtime":
-            return getRuntime();
-        case "vm":
-            return getVirtualMachine();
-        case "os":
-            return getOperatingSystem();
-        case "hardware":
-            return getHardware();
-        case "locale":
-            return getLocale();
-        default:
-            throw new IllegalArgumentException(key);
-        }
-    }
-}
+/*
+ * 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;
+
+import java.util.Locale;
+
+import org.apache.commons.lang3.StringUtils;
+
+/**
+ * Looks up keys related to Java: Java version, JRE version, VM version, and 
so on.
+ * <p>
+ * The lookup keys with examples are:
+ * </p>
+ * <ul>
+ * <li><b>version</b>: "Java version 1.8.0_181"</li>
+ * <li><b>runtime</b>: "Java(TM) SE Runtime Environment (build 1.8.0_181-b13) 
from Oracle Corporation"</li>
+ * <li><b>vm</b>: "Java HotSpot(TM) 64-Bit Server VM (build 25.181-b13, mixed 
mode)"</li>
+ * <li><b>os</b>: "Windows 10 10.0, architecture: amd64-64"</li>
+ * <li><b>hardware</b>: "processors: 4, architecture: amd64-64, instruction 
sets: amd64"</li>
+ * <li><b>locale</b>: "default locale: en_US, platform encoding: 
iso-8859-1"</li>
+ * </ul>
+ * 
+ * @since 1.3
+ */
+final class JavaPlatformStringLookup extends AbstractStringLookup {
+
+    private static final String KEY_LOCALE = "locale";
+    private static final String KEY_HARDWARE = "hardware";
+    private static final String KEY_OS = "os";
+    private static final String KEY_VM = "vm";
+    private static final String KEY_RUNTIME = "runtime";
+    private static final String KEY_VERSION = "version";
+
+    /**
+     * Defines the singleton for this class.
+     */
+    static final JavaPlatformStringLookup INSTANCE = new 
JavaPlatformStringLookup();
+
+    public static void main(String[] args) {
+        System.out.println(JavaPlatformStringLookup.class);
+        System.out.printf("%s = %s\n", KEY_VERSION, 
JavaPlatformStringLookup.INSTANCE.lookup(KEY_VERSION));
+        System.out.printf("%s = %s\n", KEY_RUNTIME, 
JavaPlatformStringLookup.INSTANCE.lookup(KEY_RUNTIME));
+        System.out.printf("%s = %s\n", KEY_VM, 
JavaPlatformStringLookup.INSTANCE.lookup(KEY_VM));
+        System.out.printf("%s = %s\n", KEY_OS, 
JavaPlatformStringLookup.INSTANCE.lookup(KEY_OS));
+        System.out.printf("%s = %s\n", KEY_HARDWARE, 
JavaPlatformStringLookup.INSTANCE.lookup(KEY_HARDWARE));
+        System.out.printf("%s = %s\n", KEY_LOCALE, 
JavaPlatformStringLookup.INSTANCE.lookup(KEY_LOCALE));
+    }
+
+    /**
+     * No need to build instances for now.
+     */
+    private JavaPlatformStringLookup() {
+        // empty
+    }
+
+    /**
+     * Accessible through the Lookup key {@code hardware}.
+     *
+     * @return hardware processor information.
+     */
+    String getHardware() {
+        return "processors: " + Runtime.getRuntime().availableProcessors() + 
", architecture: "
+                + getSystemProperty("os.arch") + this.getSystemProperty("-", 
"sun.arch.data.model")
+                + this.getSystemProperty(", instruction sets: ", 
"sun.cpu.isalist");
+    }
+
+    /**
+     * Accessible through the Lookup key {@code locale}.
+     *
+     * @return system locale and file encoding information.
+     */
+    String getLocale() {
+        return "default locale: " + Locale.getDefault() + ", platform 
encoding: " + getSystemProperty("file.encoding");
+    }
+
+    /**
+     * Accessible through the Lookup key {@code os}.
+     *
+     * @return operating system information.
+     */
+    String getOperatingSystem() {
+        return getSystemProperty("os.name") + " " + 
getSystemProperty("os.version")
+                + getSystemProperty(" ", "sun.os.patch.level") + ", 
architecture: " + getSystemProperty("os.arch")
+                + getSystemProperty("-", "sun.arch.data.model");
+    }
+
+    /**
+     * Accessible through the Lookup key {@code runtime}.
+     *
+     * @return Java Runtime Environment information.
+     */
+    String getRuntime() {
+        return getSystemProperty("java.runtime.name") + " (build " + 
getSystemProperty("java.runtime.version")
+                + ") from " + getSystemProperty("java.vendor");
+    }
+
+    /**
+     * Gets the given system property.
+     *
+     * @param name
+     *            a system property name.
+     * @return a system property value.
+     */
+    private String getSystemProperty(final String name) {
+        return SystemPropertyStringLookup.INSTANCE.lookup(name);
+    }
+
+    /**
+     * Gets the given system property.
+     *
+     * @param prefix
+     *            the prefix to use for the result string
+     * @param name
+     *            a system property name.
+     * @return the prefix + a system property value.
+     */
+    private String getSystemProperty(final String prefix, final String name) {
+        final String value = getSystemProperty(name);
+        if (StringUtils.isEmpty(value)) {
+            return StringUtils.EMPTY;
+        }
+        return prefix + value;
+    }
+
+    /**
+     * Accessible through the Lookup key {@code vm}.
+     *
+     * @return Java Virtual Machine information.
+     */
+    String getVirtualMachine() {
+        return getSystemProperty("java.vm.name") + " (build " + 
getSystemProperty("java.vm.version") + ", "
+                + getSystemProperty("java.vm.info") + ")";
+    }
+
+    /**
+     * Looks up the value of the Java platform key.
+     * <p>
+     * The lookup keys with examples are:
+     * </p>
+     * <ul>
+     * <li><b>version</b>: "Java version 1.8.0_181"</li>
+     * <li><b>runtime</b>: "Java(TM) SE Runtime Environment (build 
1.8.0_181-b13) from Oracle Corporation"</li>
+     * <li><b>vm</b>: "Java HotSpot(TM) 64-Bit Server VM (build 25.181-b13, 
mixed mode)"</li>
+     * <li><b>os</b>: "Windows 10 10.0, architecture: amd64-64"</li>
+     * <li><b>hardware</b>: "processors: 4, architecture: amd64-64, 
instruction sets: amd64"</li>
+     * <li><b>locale</b>: "default locale: en_US, platform encoding: 
iso-8859-1"</li>
+     * </ul>
+     *
+     * @param key
+     *            the key to be looked up, may be null
+     * @return The value of the environment variable.
+     */
+    @Override
+    public String lookup(final String key) {
+        switch (key) {
+        case KEY_VERSION:
+            return "Java version " + getSystemProperty("java.version");
+        case KEY_RUNTIME:
+            return getRuntime();
+        case KEY_VM:
+            return getVirtualMachine();
+        case KEY_OS:
+            return getOperatingSystem();
+        case KEY_HARDWARE:
+            return getHardware();
+        case KEY_LOCALE:
+            return getLocale();
+        default:
+            throw new IllegalArgumentException(key);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/commons-text/blob/5d01c596/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 73c3153..86221e6 100644
--- a/src/main/java/org/apache/commons/text/lookup/StringLookupFactory.java
+++ b/src/main/java/org/apache/commons/text/lookup/StringLookupFactory.java
@@ -39,7 +39,7 @@ public final class StringLookupFactory {
     public static void clear() {
         ConstantStringLookup.clear();
     }
-    
+
     /**
      * No need to build instances for now.
      */
@@ -154,7 +154,8 @@ public final class StringLookupFactory {
      * <li>"env" for the {@link EnvironmentVariableStringLookup}.</li>
      * <li>"java" for the {@link JavaPlatformStringLookup}.</li>
      * <li>"date" for the {@link DateStringLookup}.</li>
-     * <li>"localhost" for the {@link LocalHostStringLookup}, see {@link 
#localHostStringLookup()} for key names; since 1.3.</li>
+     * <li>"localhost" for the {@link LocalHostStringLookup}, see {@link 
#localHostStringLookup()} for key names; since
+     * 1.3.</li>
      * <li>"xml" for the {@link XmlStringLookup} since 1.5.</li>
      * <li>"properties" for the {@link PropertiesStringLookup} since 1.5.</li>
      * <li>"script" for the {@link ScriptStringLookup} since 1.5.</li>
@@ -183,7 +184,8 @@ public final class StringLookupFactory {
      * <li>"env" for the {@link EnvironmentVariableStringLookup}.</li>
      * <li>"java" for the {@link JavaPlatformStringLookup}.</li>
      * <li>"date" for the {@link DateStringLookup}.</li>
-     * <li>"localhost" for the {@link LocalHostStringLookup}, see {@link 
#localHostStringLookup()} for key names; since 1.3.</li>
+     * <li>"localhost" for the {@link LocalHostStringLookup}, see {@link 
#localHostStringLookup()} for key names; since
+     * 1.3.</li>
      * <li>"xml" for the {@link XmlStringLookup} since 1.5.</li>
      * <li>"properties" for the {@link PropertiesStringLookup} since 1.5.</li>
      * <li>"script" for the {@link ScriptStringLookup} since 1.5.</li>
@@ -219,7 +221,8 @@ public final class StringLookupFactory {
      * <li>"env" for the {@link EnvironmentVariableStringLookup}.</li>
      * <li>"java" for the {@link JavaPlatformStringLookup}.</li>
      * <li>"date" for the {@link DateStringLookup}.</li>
-     * <li>"localhost" for the {@link LocalHostStringLookup}, see {@link 
#localHostStringLookup()} for key names; since 1.3.</li>
+     * <li>"localhost" for the {@link LocalHostStringLookup}, see {@link 
#localHostStringLookup()} for key names; since
+     * 1.3.</li>
      * <li>"xml" for the {@link XmlStringLookup} since 1.5.</li>
      * <li>"properties" for the {@link PropertiesStringLookup} since 1.5.</li>
      * <li>"script" for the {@link ScriptStringLookup} since 1.5.</li>
@@ -251,7 +254,8 @@ public final class StringLookupFactory {
      * <li>"env" for the {@link EnvironmentVariableStringLookup}.</li>
      * <li>"java" for the {@link JavaPlatformStringLookup}.</li>
      * <li>"date" for the {@link DateStringLookup}.</li>
-     * <li>"localhost" for the {@link LocalHostStringLookup}, see {@link 
#localHostStringLookup()} for key names; since 1.3.</li>
+     * <li>"localhost" for the {@link LocalHostStringLookup}, see {@link 
#localHostStringLookup()} for key names; since
+     * 1.3.</li>
      * <li>"xml" for the {@link XmlStringLookup} since 1.5.</li>
      * <li>"properties" for the {@link PropertiesStringLookup} since 1.5.</li>
      * <li>"script" for the {@link ScriptStringLookup} since 1.5.</li>
@@ -272,8 +276,20 @@ public final class StringLookupFactory {
     }
 
     /**
-     * Returns the JavaPlatformStringLookup singleton instance.
-     *
+     * Returns the JavaPlatformStringLookup singleton instance. Looks up keys 
related to Java: Java version, JRE
+     * version, VM version, and so on.
+     * <p>
+     * The lookup keys with examples are:
+     * </p>
+     * <ul>
+     * <li><b>version</b>: "Java version 1.8.0_181"</li>
+     * <li><b>runtime</b>: "Java(TM) SE Runtime Environment (build 
1.8.0_181-b13) from Oracle Corporation"</li>
+     * <li><b>vm</b>: "Java HotSpot(TM) 64-Bit Server VM (build 25.181-b13, 
mixed mode)"</li>
+     * <li><b>os</b>: "Windows 10 10.0, architecture: amd64-64"</li>
+     * <li><b>hardware</b>: "processors: 4, architecture: amd64-64, 
instruction sets: amd64"</li>
+     * <li><b>locale</b>: "default locale: en_US, platform encoding: 
iso-8859-1"</li>
+     * </ul>
+     * 
      * @return the JavaPlatformStringLookup singleton instance.
      */
     public StringLookup javaPlatformStringLookup() {
@@ -355,7 +371,9 @@ public final class StringLookupFactory {
      * <p>
      * For example: "MyKey".
      * </p>
-     * @param bundleName Only lookup in this bundle. 
+     * 
+     * @param bundleName
+     *            Only lookup in this bundle.
      * @return a ResourceBundleStringLookup instance for the given bundle name.
      * @since 1.5
      */

Reply via email to