Add PropertyParser#getTristate

This commit is contained in:
JeremyStar™ 2024-06-27 20:10:15 +02:00
parent 74d8978f20
commit 72a13adbcd
Signed by: JeremyStarTM
GPG key ID: E366BAEF67E4704D

View file

@ -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}.
*