Skip to content

Commit e613cb5

Browse files
committed
Added OptionalString#asBoolean
1 parent a4c7d36 commit e613cb5

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/main/java/dev/latvian/apps/tinyserver/OptionalString.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,18 @@ public <T> T as(Function<String, T> mapper) {
5757
return as(mapper, null);
5858
}
5959

60+
public boolean asBoolean() {
61+
return asBoolean(false);
62+
}
63+
64+
public boolean asBoolean(boolean def) {
65+
if (value == null) {
66+
return def;
67+
}
68+
69+
return value.equalsIgnoreCase("true") || value.equalsIgnoreCase("yes") || value.equalsIgnoreCase("on") || value.equalsIgnoreCase("1");
70+
}
71+
6072
public int asInt() {
6173
return asInt(0);
6274
}

0 commit comments

Comments
 (0)