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(Class<?> c,
String propName,
boolean defValue)
Gets the boolean system property indicated by the specified class and property name.
|
static boolean |
getBooleanProperty(String key,
boolean defValue)
Gets the boolean system property indicated by the specified key.
|
static int |
getIntProperty(Class<?> c,
String propName,
int defValue)
Gets the integer system property indicated by the specified class and property name.
|
static int |
getIntProperty(Class<?> c,
String propName,
int defValue,
int minValue,
int maxValue)
Gets the integer system property indicated by the specified class and property name
and shrinks it into specified range.
|
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(Class<?> c,
String propName,
long defValue)
Gets the long system property indicated by the specified class and property name.
|
static long |
getLongProperty(Class<?> c,
String propName,
long defValue,
long minValue,
long maxValue)
Gets the long system property indicated by the specified class and property name
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(Class<?> c,
String propName,
String defValue)
Gets the string system property indicated by the specified class and property name.
|
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)
This method behaves as System.getProperty(key, defValue)
,
except for the fact that it conceals SecurityException
.
key
- system property keydefValue
- default valueSystem.getProperty(key, def)
public static String getProperty(Class<?> c, String propName, String defValue)
c.getName() + "." + propName
.
This method behaves as System.getProperty(key, defValue)
,
except for the fact that it conceals SecurityException
.
c
- the class that the property is part ofpropName
- property name in the class. Use camelCase naming starting with lowercase first letterdefValue
- default valueSystem.getProperty(key, def)
public static int getIntProperty(String key, int defValue)
This method can parse numbers in decimal, hexadecimal, and octal radix
(the same way as Integer.getInteger(key, defValue)
method does).
key
- system property keydefValue
- default valuepublic static int getIntProperty(Class<?> c, String propName, int defValue)
c.getName() + "." + propName
.
This method can parse numbers in decimal, hexadecimal, and octal radix
(the same way as Integer.getInteger(key, defValue)
method does).
c
- the class that the property is part ofpropName
- property name in the class. Use camelCase naming starting with lowercase first letterdefValue
- default valuepublic static int getIntProperty(String key, int defValue, int minValue, int maxValue)
This methods behaves likely to 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 int getIntProperty(Class<?> c, String propName, int defValue, int minValue, int maxValue)
c.getName() + "." + propName
.
This methods behaves likely to 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.
c
- the class that the property is part ofpropName
- property name in the class. Use camelCase naming starting with lowercase first letterdefValue
- default valueminValue
- minimum allowable valuemaxValue
- maximum allowable valueIllegalArgumentException
- if minValue≤defValue≤maxValue
condition breakspublic static long getLongProperty(String key, long defValue)
This method can parse numbers in decimal, hexadecimal, and octal radix
(the same way as Long.getLong(key, defValue)
method does).
key
- system property keydefValue
- default valuepublic static long getLongProperty(Class<?> c, String propName, long defValue)
c.getName() + "." + propName
.
This method can parse numbers in decimal, hexadecimal, and octal radix
(the same way as Long.getLong(key, defValue)
method does).
c
- the class that the property is part ofpropName
- property name in the class. Use camelCase naming starting with lowercase first letterdefValue
- default valuepublic static long getLongProperty(String key, long defValue, long minValue, long maxValue)
This methods behaves likely to 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 long getLongProperty(Class<?> c, String propName, long defValue, long minValue, long maxValue)
c.getName() + "." + propName
.
This methods behaves likely to 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.
c
- the class that the property is part ofpropName
- property name in the class. Use camelCase naming starting with lowercase first letterdefValue
- default valueminValue
- minimum allowable valuemaxValue
- maximum allowable valueIllegalArgumentException
- if minValue≤defValue≤maxValue
condition breakspublic static boolean getBooleanProperty(String key, boolean defValue)
Unlike 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 getBooleanProperty(Class<?> c, String propName, boolean defValue)
c.getName() + "." + propName
.
Unlike 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).
c
- the class that the property is part ofpropName
- property name in the class. Use camelCase naming starting with lowercase first letterdefValue
- 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 © 2002–2025 Devexperts LLC. All rights reserved.