forked from StarOpenSource/Engine
Add PropertyParser#getTristate
This commit is contained in:
parent
74d8978f20
commit
72a13adbcd
1 changed files with 30 additions and 0 deletions
|
@ -19,6 +19,7 @@
|
||||||
|
|
||||||
package de.staropensource.sosengine.base.utility;
|
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.logging.LoggerInstance;
|
||||||
import de.staropensource.sosengine.base.types.CodePart;
|
import de.staropensource.sosengine.base.types.CodePart;
|
||||||
import de.staropensource.sosengine.base.classes.logging.LogIssuer;
|
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}.
|
* Parses a property as a {@link Byte}.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in a new issue