From e613cb57118a3b0bf56e417abf3e1a2f5f5e7cf1 Mon Sep 17 00:00:00 2001 From: LatvianModder Date: Tue, 19 Nov 2024 01:48:09 +0200 Subject: [PATCH] Added OptionalString#asBoolean --- .../dev/latvian/apps/tinyserver/OptionalString.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/main/java/dev/latvian/apps/tinyserver/OptionalString.java b/src/main/java/dev/latvian/apps/tinyserver/OptionalString.java index f4324fc..9364886 100644 --- a/src/main/java/dev/latvian/apps/tinyserver/OptionalString.java +++ b/src/main/java/dev/latvian/apps/tinyserver/OptionalString.java @@ -57,6 +57,18 @@ public T as(Function mapper) { return as(mapper, null); } + public boolean asBoolean() { + return asBoolean(false); + } + + public boolean asBoolean(boolean def) { + if (value == null) { + return def; + } + + return value.equalsIgnoreCase("true") || value.equalsIgnoreCase("yes") || value.equalsIgnoreCase("on") || value.equalsIgnoreCase("1"); + } + public int asInt() { return asInt(0); }