JVM | Platform | Status |
---|---|---|
OpenJDK (Temurin) Current | Linux | |
OpenJDK (Temurin) LTS | Linux | |
OpenJDK (Temurin) Current | Windows | |
OpenJDK (Temurin) LTS | Windows |
Java functions to access values from java.util.Properties
collections in
a typed manner.
- Functions to access
java.util.Properties
values as typed values. - High coverage test suite.
- OSGi-ready
- JPMS-ready
- ISC license.
The JProperties
class contains numerous functions to extract typed values
from a Properties
collection:
final var p = new Properties();
p.setProperty("int0", "23");
p.setProperty("b0", "true");
JProperties.getBoolean(p, "b0"); // ⇒ true
JProperties.getBigInteger(p, "int0"); // ⇒ new BigInteger(23)
If a property is not present, or has a value that cannot be parsed as a value
of the requested type, a JPropertyException
is raised.
JProperties.getBigInteger(p, "nonexistent") // ⇒ JPropertyNonexistent
JProperties.getBigInteger(p, "b0"); // ⇒ JPropertyIncorrectType
Functions typically have an optional variant that returns an Optional.empty()
value on missing keys (but an exception will still be raised on type errors).
JProperties.getStringOptional(p, "nonexistent") // ⇒ Optional.empty()
JProperties.getStringOptional(p, "b0"); // ⇒ "true"
Functions typically also have a default
variant that can return a given
default value if a property is not present (but an exception will still be
raised on type errors).
JProperties.getStringWithDefault(p, "nonexistent", "z") // ⇒ "z"
JProperties.getStringWithDefault(p, "b0", "z"); // ⇒ "true"