-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.in
52 lines (38 loc) · 1.56 KB
/
README.in
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
## jproperties
Java functions to access values from `java.util.Properties` collections in
a typed manner.
## Features
* Functions to access `java.util.Properties` values as typed values.
* High coverage test suite.
* [OSGi-ready](https://www.osgi.org/)
* [JPMS-ready](https://en.wikipedia.org/wiki/Java_Platform_Module_System)
* ISC license.
## Usage
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"
```