diff --git a/base/src/main/java/de/staropensource/sosengine/base/utility/PropertyParser.java b/base/src/main/java/de/staropensource/sosengine/base/utility/PropertyParser.java index e841e89b..12187cba 100644 --- a/base/src/main/java/de/staropensource/sosengine/base/utility/PropertyParser.java +++ b/base/src/main/java/de/staropensource/sosengine/base/utility/PropertyParser.java @@ -19,6 +19,7 @@ package de.staropensource.sosengine.base.utility; +import de.staropensource.sosengine.base.types.Tristate; import de.staropensource.sosengine.base.logging.LoggerInstance; import de.staropensource.sosengine.base.types.CodePart; import de.staropensource.sosengine.base.classes.logging.LogIssuer; @@ -133,6 +134,35 @@ public class PropertyParser { } } + /** + * Parses a property as a {@link Tristate}. + * + * @param name the property name + * @return a {@link Tristate} + * @throws NullPointerException if the specified property does not exist + * @see Tristate + * @since 1-alpha1 + */ + @NotNull + public Tristate getTristate(@NotNull String name) { + if (properties.getProperty(name) == null) { + logger.sarn("Unable to get Tristate from property '" + name + "': Property does not exist"); + throw new NullPointerException("Unable to get Tristate from property '" + name + "': Property does not exist"); + } + + switch (properties.getProperty(name)) { + case "1", "true", "yes", "y" -> { + return Tristate.TRUE; + } + case "0", "false", "no", "n" -> { + return Tristate.FALSE; + } + case null, default -> { + return Tristate.UNSET; + } + } + } + /** * Parses a property as a {@link Byte}. *