public final class SystemProperties extends Object
SecurityException
.
Unless otherwise is specified all methods of this class conceal and log any exceptions and
return default value in case of any failure.Modifier and Type | Method and Description |
---|---|
static boolean |
getBooleanProperty(String key,
boolean defValue)
Gets the boolean system property indicated by the specified key.
|
static int |
getIntProperty(String key,
int defValue)
Gets the integer system property indicated by the specified key.
|
static int |
getIntProperty(String key,
int defValue,
int minValue,
int maxValue)
Gets the integer system property indicated by the specified key
and shrinks it into specified range.
|
static long |
getLongProperty(String key,
long defValue)
Gets the long system property indicated by the specified key.
|
static long |
getLongProperty(String key,
long defValue,
long minValue,
long maxValue)
Gets the long system property indicated by the specified key
and shrinks it into specified range.
|
static String |
getProperty(String key,
String defValue)
Gets the string system property indicated by the specified key.
|
static boolean |
parseBooleanValue(String value)
Utility method that parses boolean value from a string.
|
public static String getProperty(String key, String defValue)
System.getProperty(key, defValue)
,
except for the fact that it conceals SecurityException
.key
- system property keydefValue
- default valueSystem.getProperty(key, def)
public static int getIntProperty(String key, int defValue)
Integer.getInteger(key, defValue)
method does).key
- system property keydefValue
- default valuepublic static int getIntProperty(String key, int defValue, int minValue, int maxValue)
getIntProperty(key, defValue)
but if the resulting value is less than
minValue
or greater than maxValue
a warning is logged
and the corresponding boundary value is returned.key
- system property keydefValue
- default valueminValue
- minimum allowable valuemaxValue
- maximum allowable valueIllegalArgumentException
- if minValue≤defValue≤maxValue
condition breakspublic static long getLongProperty(String key, long defValue)
Long.getLong(key, defValue)
method does).key
- system property keydefValue
- default valuepublic static long getLongProperty(String key, long defValue, long minValue, long maxValue)
getLongProperty(key, defValue)
but if the resulting value is less than
minValue
or greater than maxValue
a warning is logged
and the corresponding boundary value is returned.key
- system property keydefValue
- default valueminValue
- minimum allowable valuemaxValue
- maximum allowable valueIllegalArgumentException
- if minValue≤defValue≤maxValue
condition breakspublic static boolean getBooleanProperty(String key, boolean defValue)
Boolean.getBoolean(key)
this method recognizes defined properties with empty values as true
and returns the default value (and logs an error) if the value of a specified
property is neither of "true", "false" or "" (case-insensetively).key
- system property keydefValue
- default valuepublic static boolean parseBooleanValue(String value) throws IllegalArgumentException
true
and "false" as false
(case-insensitively); all other values
are considered invalid.value
- string to parseIllegalArgumentException
- if the string was neither of "", "true" or "false" (case-insensitively)NullPointerException
- if value
is null
Copyright © 2014 Devexperts. All Rights Reserved.