Skip to content

Commit

Permalink
Added OptionalString#asBoolean
Browse files Browse the repository at this point in the history
  • Loading branch information
LatvianModder committed Nov 18, 2024
1 parent a4c7d36 commit e613cb5
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/main/java/dev/latvian/apps/tinyserver/OptionalString.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,18 @@ public <T> T as(Function<String, T> 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);
}
Expand Down

0 comments on commit e613cb5

Please sign in to comment.