Package org.apache.commons.text.lookup
Class JavaPlatformStringLookup
- java.lang.Object
-
- org.apache.commons.text.lookup.AbstractStringLookup
-
- org.apache.commons.text.lookup.JavaPlatformStringLookup
-
- All Implemented Interfaces:
StringLookup
final class JavaPlatformStringLookup extends AbstractStringLookup
Looks up keys related to Java: Java version, JRE version, VM version, and so on.The lookup keys with examples are:
- version: "Java version 1.8.0_181"
- runtime: "Java(TM) SE Runtime Environment (build 1.8.0_181-b13) from Oracle Corporation"
- vm: "Java HotSpot(TM) 64-Bit Server VM (build 25.181-b13, mixed mode)"
- os: "Windows 10 10.0, architecture: amd64-64"
- hardware: "processors: 4, architecture: amd64-64, instruction sets: amd64"
- locale: "default locale: en_US, platform encoding: iso-8859-1"
Using a
StringLookup
from theStringLookupFactory
:StringLookupFactory.INSTANCE.javaPlatformStringLookup().lookup("version");
Using a
StringSubstitutor
:StringSubstitutor.createInterpolator().replace("... ${java:version} ..."));
The above examples convert
"version"
to the current VM version, for example,"Java version 1.8.0_181"
.- Since:
- 1.3
-
-
Field Summary
Fields Modifier and Type Field Description (package private) static JavaPlatformStringLookup
INSTANCE
Defines the singleton for this class.private static java.lang.String
KEY_HARDWARE
hardware
key for drivinglookup(String)
.private static java.lang.String
KEY_LOCALE
locale
key for drivinglookup(String)
.private static java.lang.String
KEY_OS
os
key for drivinglookup(String)
.private static java.lang.String
KEY_RUNTIME
runtime
key for drivinglookup(String)
.private static java.lang.String
KEY_VERSION
version
key for drivinglookup(String)
.private static java.lang.String
KEY_VM
vm
key for drivinglookup(String)
.-
Fields inherited from class org.apache.commons.text.lookup.AbstractStringLookup
SPLIT_CH, SPLIT_STR
-
-
Constructor Summary
Constructors Modifier Constructor Description private
JavaPlatformStringLookup()
No need to build instances for now.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) java.lang.String
getHardware()
Accessible through the Lookup keyhardware
.(package private) java.lang.String
getLocale()
Accessible through the Lookup keylocale
.(package private) java.lang.String
getOperatingSystem()
Accessible through the Lookup keyos
.(package private) java.lang.String
getRuntime()
Accessible through the Lookup keyruntime
.private java.lang.String
getSystemProperty(java.lang.String name)
Gets the given system property.private java.lang.String
getSystemProperty(java.lang.String prefix, java.lang.String name)
Gets the given system property.(package private) java.lang.String
getVirtualMachine()
Accessible through the Lookup keyvm
.java.lang.String
lookup(java.lang.String key)
Looks up the value of the Java platform key.static void
main(java.lang.String[] args)
The main method for running the JavaPlatformStringLookup.-
Methods inherited from class org.apache.commons.text.lookup.AbstractStringLookup
substringAfter, substringAfter, substringAfterLast, toLookupKey, toLookupKey
-
-
-
-
Field Detail
-
INSTANCE
static final JavaPlatformStringLookup INSTANCE
Defines the singleton for this class.
-
KEY_HARDWARE
private static final java.lang.String KEY_HARDWARE
hardware
key for drivinglookup(String)
.- See Also:
- Constant Field Values
-
KEY_LOCALE
private static final java.lang.String KEY_LOCALE
locale
key for drivinglookup(String)
.- See Also:
- Constant Field Values
-
KEY_OS
private static final java.lang.String KEY_OS
os
key for drivinglookup(String)
.- See Also:
- Constant Field Values
-
KEY_RUNTIME
private static final java.lang.String KEY_RUNTIME
runtime
key for drivinglookup(String)
.- See Also:
- Constant Field Values
-
KEY_VERSION
private static final java.lang.String KEY_VERSION
version
key for drivinglookup(String)
.- See Also:
- Constant Field Values
-
KEY_VM
private static final java.lang.String KEY_VM
vm
key for drivinglookup(String)
.- See Also:
- Constant Field Values
-
-
Method Detail
-
main
public static void main(java.lang.String[] args)
The main method for running the JavaPlatformStringLookup.- Parameters:
args
- the standard java main method parameter which is unused for our running of this class.
-
getHardware
java.lang.String getHardware()
Accessible through the Lookup keyhardware
.- Returns:
- hardware processor information.
-
getLocale
java.lang.String getLocale()
Accessible through the Lookup keylocale
.- Returns:
- system locale and file encoding information.
-
getOperatingSystem
java.lang.String getOperatingSystem()
Accessible through the Lookup keyos
.- Returns:
- operating system information.
-
getRuntime
java.lang.String getRuntime()
Accessible through the Lookup keyruntime
.- Returns:
- Java Runtime Environment information.
-
getSystemProperty
private java.lang.String getSystemProperty(java.lang.String name)
Gets the given system property.- Parameters:
name
- a system property name.- Returns:
- a system property value.
-
getSystemProperty
private java.lang.String getSystemProperty(java.lang.String prefix, java.lang.String name)
Gets the given system property.- Parameters:
prefix
- the prefix to use for the result stringname
- a system property name.- Returns:
- The prefix + a system property value.
-
getVirtualMachine
java.lang.String getVirtualMachine()
Accessible through the Lookup keyvm
.- Returns:
- Java Virtual Machine information.
-
lookup
public java.lang.String lookup(java.lang.String key)
Looks up the value of the Java platform key.The lookup keys with examples are:
- version: "Java version 1.8.0_181"
- runtime: "Java(TM) SE Runtime Environment (build 1.8.0_181-b13) from Oracle Corporation"
- vm: "Java HotSpot(TM) 64-Bit Server VM (build 25.181-b13, mixed mode)"
- os: "Windows 10 10.0, architecture: amd64-64"
- hardware: "processors: 4, architecture: amd64-64, instruction sets: amd64"
- locale: "default locale: en_US, platform encoding: iso-8859-1"
- Parameters:
key
- the key to be looked up, may be null- Returns:
- The value of the environment variable.
-
-