Package adams.core.management
Class EnvVar
- java.lang.Object
-
- adams.core.management.EnvVar
-
public class EnvVar extends Object
Helper class for environment variables. UsesSystem.getenv(String)
under the hood.- Author:
- fracpete (fracpete at waikato dot ac dot nz)
-
-
Field Summary
Fields Modifier and Type Field Description static String
SEPARATOR_LIST
the default list separator (;).static String
SEPARATOR_PAIR
the default pair separator (=).
-
Constructor Summary
Constructors Constructor Description EnvVar()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static String
convert(String name, boolean dotsToUnderscores, boolean checkUppercase)
Generates the actual environment variable name.static String
find(String name, boolean dotsToUnderscores, boolean checkUppercase)
Locates the actual environment variable.static Map<String,String>
get()
Returns the current mapping of environment variables.static String
get(String name)
Returns the value of the specified environment variable.static String
get(String name, String defValue)
Returns the value of the specified environment variable.static String
get(String name, String defValue, boolean dotsToUnderscores, boolean checkUppercase)
Returns the value of the specified environment variable.static Map<String,String>
getKeyValuePairs(String name)
Obtains key=value pairs from the specified environment variable.static Map<String,String>
getKeyValuePairs(String name, boolean dotsToUnderscores, boolean checkUppercase)
Obtains key=value pairs from the specified environment variable.static Map<String,String>
getKeyValuePairs(String name, boolean dotsToUnderscores, boolean checkUppercase, String listSep, String pairSep, boolean info)
Obtains key=value pairs from the specified environment variable.static Map<String,String>
getKeyValuePairs(String name, String listSep, String pairSep, boolean info)
Obtains key=value pairs from the specified environment variable.static boolean
has(String name)
Returns whether the specified environment variable is present.
-
-
-
Field Detail
-
SEPARATOR_LIST
public static final String SEPARATOR_LIST
the default list separator (;).- See Also:
- Constant Field Values
-
SEPARATOR_PAIR
public static final String SEPARATOR_PAIR
the default pair separator (=).- See Also:
- Constant Field Values
-
-
Method Detail
-
get
public static Map<String,String> get()
Returns the current mapping of environment variables.- Returns:
- the mapping
- See Also:
System.getenv()
-
has
public static boolean has(String name)
Returns whether the specified environment variable is present.- Parameters:
name
- the env var to check- Returns:
- true if present
- See Also:
System.getenv(String)
-
convert
public static String convert(String name, boolean dotsToUnderscores, boolean checkUppercase)
Generates the actual environment variable name.- Parameters:
name
- the input namedotsToUnderscores
- whether to convert underscores with dotscheckUppercase
- whether to convert to uppercase- Returns:
- the converted name
-
find
public static String find(String name, boolean dotsToUnderscores, boolean checkUppercase)
Locates the actual environment variable.- Parameters:
name
- the env var to retrievedotsToUnderscores
- whether to check presence of name with underscores replacing dotscheckUppercase
- whether to check presence of uppercased name- Returns:
- the actual variable name, null if not present
- See Also:
System.getenv(String)
-
get
public static String get(String name)
Returns the value of the specified environment variable.- Parameters:
name
- the env var to retrieve- Returns:
- the associated value or null if not present
- See Also:
System.getenv(String)
-
get
public static String get(String name, String defValue)
Returns the value of the specified environment variable.- Parameters:
name
- the env var to retrievedefValue
- the default value to use if not set- Returns:
- the associated value or the default value if not present
- See Also:
System.getenv(String)
-
get
public static String get(String name, String defValue, boolean dotsToUnderscores, boolean checkUppercase)
Returns the value of the specified environment variable.- Parameters:
name
- the env var to retrievedefValue
- the default value to use if not setdotsToUnderscores
- whether to check presence of name with underscores replacing dotscheckUppercase
- whether to check presence of uppercased name- Returns:
- the associated value or the default value if not present
- See Also:
System.getenv(String)
-
getKeyValuePairs
public static Map<String,String> getKeyValuePairs(String name)
Obtains key=value pairs from the specified environment variable. Uses semi-colon (;) as list separator and equals (=) as pair separator.- Parameters:
name
- the environment variable to check- Returns:
- the generated mapping of key=value pairs
-
getKeyValuePairs
public static Map<String,String> getKeyValuePairs(String name, boolean dotsToUnderscores, boolean checkUppercase)
Obtains key=value pairs from the specified environment variable.- Parameters:
name
- the environment variable to checkdotsToUnderscores
- whether to convert check presence of name with underscores replacing dotscheckUppercase
- whether to convert check presence of uppercased name- Returns:
- the generated mapping of key=value pairs
-
getKeyValuePairs
public static Map<String,String> getKeyValuePairs(String name, String listSep, String pairSep, boolean info)
Obtains key=value pairs from the specified environment variable.- Parameters:
name
- the environment variable to checklistSep
- the separator to use for splitting the list of pairspairSep
- the separator to use for splitting a pair into key and valueinfo
- whether to output some info in the console on stdout- Returns:
- the generated mapping of key=value pairs
-
getKeyValuePairs
public static Map<String,String> getKeyValuePairs(String name, boolean dotsToUnderscores, boolean checkUppercase, String listSep, String pairSep, boolean info)
Obtains key=value pairs from the specified environment variable.- Parameters:
name
- the environment variable to checklistSep
- the separator to use for splitting the list of pairspairSep
- the separator to use for splitting a pair into key and valueinfo
- whether to output some info in the console on stdoutdotsToUnderscores
- whether to convert check presence of name with underscores replacing dotscheckUppercase
- whether to convert check presence of uppercased name- Returns:
- the generated mapping of key=value pairs
-
-