Rename PropertyParser -> PropertiesReader
This commit is contained in:
parent
611d4b823e
commit
9db7f20c2e
8 changed files with 53 additions and 54 deletions
|
@ -27,7 +27,7 @@ import de.staropensource.sosengine.base.logging.Logger;
|
|||
import de.staropensource.sosengine.base.types.EngineState;
|
||||
import de.staropensource.sosengine.base.types.logging.LogLevel;
|
||||
import de.staropensource.sosengine.base.types.vectors.Vec2f;
|
||||
import de.staropensource.sosengine.base.utility.parser.PropertyParser;
|
||||
import de.staropensource.sosengine.base.utility.PropertiesReader;
|
||||
import lombok.Getter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
@ -298,7 +298,7 @@ public final class EngineConfiguration extends Configuration {
|
|||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
protected void matchProperty(@NotNull PropertyParser parser, @NotNull String property) {
|
||||
protected void matchProperty(@NotNull PropertiesReader parser, @NotNull String property) {
|
||||
try {
|
||||
switch (property) {
|
||||
case "debug" -> debug = parser.getBoolean(group + property);
|
||||
|
@ -336,7 +336,7 @@ public final class EngineConfiguration extends Configuration {
|
|||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
protected void processSettings(@NotNull PropertyParser parser) {
|
||||
protected void processSettings(@NotNull PropertiesReader parser) {
|
||||
// Disable all debugging switches if 'debug' is disabled
|
||||
if (!debug) {
|
||||
debugEvents = false;
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
package de.staropensource.sosengine.base.classes;
|
||||
|
||||
import de.staropensource.sosengine.base.logging.LoggerInstance;
|
||||
import de.staropensource.sosengine.base.utility.parser.PropertyParser;
|
||||
import de.staropensource.sosengine.base.utility.PropertiesReader;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
|
@ -68,7 +68,7 @@ public abstract class Configuration {
|
|||
* @since v1-alpha2
|
||||
*/
|
||||
public void loadConfiguration(@NotNull Properties properties) {
|
||||
PropertyParser parser = new PropertyParser(properties);
|
||||
PropertiesReader parser = new PropertiesReader(properties);
|
||||
|
||||
// Loop through all properties
|
||||
for (String property : properties.stringPropertyNames()) {
|
||||
|
@ -121,20 +121,20 @@ public abstract class Configuration {
|
|||
* Matches the given {@code property} against all settings.
|
||||
* If a match has been found, the setting will be overwritten with the property's value.
|
||||
*
|
||||
* @param parser matching {@link PropertyParser}
|
||||
* @param parser matching {@link PropertiesReader}
|
||||
* @param property property to match
|
||||
* @since v1-alpha2
|
||||
*/
|
||||
protected abstract void matchProperty(@NotNull PropertyParser parser, @NotNull String property);
|
||||
protected abstract void matchProperty(@NotNull PropertiesReader parser, @NotNull String property);
|
||||
|
||||
/**
|
||||
* Allows the implementor to process all settings and potentially
|
||||
* modify them before {@link #loadConfiguration(Properties)} returns.
|
||||
*
|
||||
* @param parser matching {@link PropertyParser}
|
||||
* @param parser matching {@link PropertiesReader}
|
||||
* @since v1-alpha2
|
||||
*/
|
||||
protected abstract void processSettings(@NotNull PropertyParser parser);
|
||||
protected abstract void processSettings(@NotNull PropertiesReader parser);
|
||||
|
||||
/**
|
||||
* Returns a configuration setting.
|
||||
|
|
|
@ -22,7 +22,7 @@ package de.staropensource.sosengine.base.data.information;
|
|||
import de.staropensource.sosengine.base.Engine;
|
||||
import de.staropensource.sosengine.base.logging.LoggerInstance;
|
||||
import de.staropensource.sosengine.base.types.VersionType;
|
||||
import de.staropensource.sosengine.base.utility.parser.PropertyParser;
|
||||
import de.staropensource.sosengine.base.utility.PropertiesReader;
|
||||
import de.staropensource.sosengine.base.utility.parser.StackTraceParser;
|
||||
import lombok.Getter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
@ -373,8 +373,8 @@ public final class EngineInformation {
|
|||
}
|
||||
|
||||
// Create new PropertyParsers
|
||||
PropertyParser gradleParser = new PropertyParser(gradleProperties);
|
||||
PropertyParser gitParser = new PropertyParser(gitProperties);
|
||||
PropertiesReader gradleParser = new PropertiesReader(gradleProperties);
|
||||
PropertiesReader gitParser = new PropertiesReader(gitProperties);
|
||||
|
||||
// Apply properties to fields
|
||||
versioningCodename = gradleParser.getString("versioningCodename");
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.sosengine.base.utility.parser;
|
||||
package de.staropensource.sosengine.base.utility;
|
||||
|
||||
import de.staropensource.sosengine.base.logging.LoggerInstance;
|
||||
import de.staropensource.sosengine.base.types.Tristate;
|
||||
|
@ -27,13 +27,13 @@ import org.jetbrains.annotations.NotNull;
|
|||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* Allows parsing and converting properties into various other data types.
|
||||
* Allows reading and converting properties into various other data types.
|
||||
*
|
||||
* @see Properties
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
@SuppressWarnings({ "unused", "JavadocDeclaration" })
|
||||
public final class PropertyParser {
|
||||
public final class PropertiesReader {
|
||||
/**
|
||||
* Contains an instance providing access to the system properties.
|
||||
*
|
||||
|
@ -47,7 +47,7 @@ public final class PropertyParser {
|
|||
* @since v1-alpha0
|
||||
*/
|
||||
@Getter
|
||||
private static final @NotNull PropertyParser instance = new PropertyParser(System.getProperties());
|
||||
private static final @NotNull PropertiesReader instance = new PropertiesReader(System.getProperties());
|
||||
|
||||
/**
|
||||
* Contains the {@link LoggerInstance} for this instance.
|
||||
|
@ -65,7 +65,7 @@ public final class PropertyParser {
|
|||
* -- GETTER --
|
||||
* Returns the {@link Properties} used by this parser instance to read properties.
|
||||
*
|
||||
* @return {@link Properties} associated with this parser instance
|
||||
* @return {@link Properties} associated with this reader instance
|
||||
* @see Properties
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
|
@ -73,12 +73,12 @@ public final class PropertyParser {
|
|||
private final @NotNull Properties properties;
|
||||
|
||||
/**
|
||||
* Creates a new {@link PropertyParser} instance.
|
||||
* Creates a new {@link PropertiesReader} instance.
|
||||
*
|
||||
* @param properties {@link Properties} to use
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
public PropertyParser(@NotNull Properties properties) {
|
||||
public PropertiesReader(@NotNull Properties properties) {
|
||||
this.properties = properties;
|
||||
this.logger = new LoggerInstance.Builder().setClazz(getClass()).setOrigin("ENGINE").setMetadata(String.valueOf(properties.hashCode())).build();
|
||||
}
|
||||
|
@ -88,7 +88,7 @@ public final class PropertyParser {
|
|||
*
|
||||
* @param name property name
|
||||
* @return a {@link String}
|
||||
* @throws NullPointerException if the specified property does not exist
|
||||
* @throws NullPointerException if the specified property could not be found
|
||||
* @see String
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
|
@ -105,11 +105,11 @@ public final class PropertyParser {
|
|||
*
|
||||
* @param name property name
|
||||
* @return a {@link Boolean}
|
||||
* @throws NullPointerException if the specified property does not exist
|
||||
* @throws NullPointerException if the specified property could not be found
|
||||
* @see Boolean
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
public boolean getBoolean(@NotNull String name) {
|
||||
public boolean getBoolean(@NotNull String name) throws NullPointerException {
|
||||
if (properties.getProperty(name) == null) {
|
||||
logger.sarn("Unable to get Boolean from property '" + name + "': Property does not exist");
|
||||
throw new NullPointerException("Unable to get Boolean from property '" + name + "': Property does not exist");
|
||||
|
@ -130,11 +130,11 @@ public final class PropertyParser {
|
|||
*
|
||||
* @param name property name
|
||||
* @return a {@link Tristate}
|
||||
* @throws NullPointerException if the specified property does not exist
|
||||
* @throws NullPointerException if the specified property could not be found
|
||||
* @see Tristate
|
||||
* @since v1-alpha1
|
||||
*/
|
||||
public @NotNull Tristate getTristate(@NotNull String name) {
|
||||
public @NotNull Tristate getTristate(@NotNull String name) throws NullPointerException {
|
||||
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");
|
||||
|
@ -158,7 +158,7 @@ public final class PropertyParser {
|
|||
*
|
||||
* @param name property name
|
||||
* @return a {@link Byte}
|
||||
* @throws NullPointerException if the specified property does not exist
|
||||
* @throws NullPointerException if the specified property could not be found
|
||||
* @throws NumberFormatException if the specified property cannot be parsed as a {@link Byte}
|
||||
* @see Byte
|
||||
* @since v1-alpha0
|
||||
|
@ -182,12 +182,12 @@ public final class PropertyParser {
|
|||
*
|
||||
* @param name property name
|
||||
* @return a {@link Short}
|
||||
* @throws NullPointerException if the specified property does not exist
|
||||
* @throws NullPointerException if the specified property could not be found
|
||||
* @throws NumberFormatException if the specified property cannot be parsed as a {@link Short}
|
||||
* @see Short
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
public short getShort(@NotNull String name) throws NumberFormatException {
|
||||
public short getShort(@NotNull String name) throws NullPointerException, NumberFormatException {
|
||||
if (properties.getProperty(name) == null) {
|
||||
logger.sarn("Unable to get Short from property '" + name + "': Property does not exist");
|
||||
throw new NullPointerException("Unable to get Short from property '" + name + "': Property does not exist");
|
||||
|
@ -207,12 +207,12 @@ public final class PropertyParser {
|
|||
* @param name property name
|
||||
* @param unsigned determines if the {@link Integer} is unsigned
|
||||
* @return an {@link Integer}
|
||||
* @throws NullPointerException if the specified property does not exist
|
||||
* @throws NullPointerException if the specified property could not be found
|
||||
* @throws NumberFormatException if the specified property cannot be parsed as an {@link Integer}
|
||||
* @see Integer
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
public int getInteger(@NotNull String name, boolean unsigned) throws NumberFormatException {
|
||||
public int getInteger(@NotNull String name, boolean unsigned) throws NullPointerException, NumberFormatException {
|
||||
if (properties.getProperty(name) == null) {
|
||||
logger.sarn("Unable to get Integer from property '" + name + "': Property does not exist");
|
||||
throw new NullPointerException("Unable to get Integer from property '" + name + "': Property does not exist");
|
||||
|
@ -235,12 +235,12 @@ public final class PropertyParser {
|
|||
* @param name property name
|
||||
* @param unsigned determines if the {@link Long} is unsigned
|
||||
* @return a {@link Long}
|
||||
* @throws NullPointerException if the specified property does not exist
|
||||
* @throws NullPointerException if the specified property could not be found
|
||||
* @throws NumberFormatException if the specified property cannot be parsed as an {@link Long}
|
||||
* @see Long
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
public long getLong(@NotNull String name, boolean unsigned) throws NumberFormatException {
|
||||
public long getLong(@NotNull String name, boolean unsigned) throws NullPointerException, NumberFormatException {
|
||||
if (properties.getProperty(name) == null) {
|
||||
logger.sarn("Unable to get Long from property '" + name + "': Property does not exist");
|
||||
throw new NullPointerException("Unable to get Long from property '" + name + "': Property does not exist");
|
||||
|
@ -262,7 +262,7 @@ public final class PropertyParser {
|
|||
*
|
||||
* @param name property name
|
||||
* @return a {@link Float}
|
||||
* @throws NullPointerException if the specified property does not exist
|
||||
* @throws NullPointerException if the specified property could not be found
|
||||
* @throws NumberFormatException if the specified property cannot be parsed as an {@link Float}
|
||||
* @see Float
|
||||
* @since v1-alpha0
|
||||
|
@ -286,7 +286,7 @@ public final class PropertyParser {
|
|||
*
|
||||
* @param name property name
|
||||
* @return a {@link Double}
|
||||
* @throws NullPointerException if the specified property does not exist
|
||||
* @throws NullPointerException if the specified property could not be found
|
||||
* @throws NumberFormatException if the specified property cannot be parsed as an {@link Double}
|
||||
* @see Double
|
||||
* @since v1-alpha0
|
|
@ -22,6 +22,7 @@ module sosengine.base {
|
|||
exports de.staropensource.sosengine.base.exceptions.dependency;
|
||||
exports de.staropensource.sosengine.base.exceptions.reflection;
|
||||
exports de.staropensource.sosengine.base.exceptions.versioning;
|
||||
exports de.staropensource.sosengine.base.internal.events; // Internal: Required for subsystems
|
||||
exports de.staropensource.sosengine.base.logging;
|
||||
exports de.staropensource.sosengine.base.logging.implementation;
|
||||
exports de.staropensource.sosengine.base.reflection;
|
||||
|
@ -34,9 +35,6 @@ module sosengine.base {
|
|||
exports de.staropensource.sosengine.base.utility.converter;
|
||||
exports de.staropensource.sosengine.base.utility.parser;
|
||||
exports de.staropensource.sosengine.unittests;
|
||||
// -> Internal
|
||||
// These are required for subsystems to function correctly
|
||||
exports de.staropensource.sosengine.base.internal.events;
|
||||
|
||||
// Reflection access
|
||||
opens de.staropensource.sosengine.base;
|
||||
|
@ -50,6 +48,7 @@ module sosengine.base {
|
|||
opens de.staropensource.sosengine.base.exceptions.dependency;
|
||||
opens de.staropensource.sosengine.base.exceptions.reflection;
|
||||
opens de.staropensource.sosengine.base.exceptions.versioning;
|
||||
opens de.staropensource.sosengine.base.internal.events; // Internal: Required for subsystems
|
||||
opens de.staropensource.sosengine.base.logging;
|
||||
opens de.staropensource.sosengine.base.logging.implementation;
|
||||
opens de.staropensource.sosengine.base.reflection;
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
package de.staropensource.sosengine.base.srctests.utility;
|
||||
|
||||
import de.staropensource.sosengine.base.srctests.TestBase;
|
||||
import de.staropensource.sosengine.base.utility.parser.PropertyParser;
|
||||
import de.staropensource.sosengine.base.utility.PropertiesReader;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.CsvSource;
|
||||
|
@ -30,10 +30,10 @@ import java.util.Properties;
|
|||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
/**
|
||||
* Tests the class {@link PropertyParser}.
|
||||
* Tests the class {@link PropertiesReader}.
|
||||
*/
|
||||
@DisplayName("PropertyParser")
|
||||
class PropertyParserTest extends TestBase {
|
||||
@DisplayName("PropertiesReader")
|
||||
class PropertiesReaderTest extends TestBase {
|
||||
/**
|
||||
* Tests the method {@code getString}.
|
||||
*/
|
||||
|
@ -51,7 +51,7 @@ class PropertyParserTest extends TestBase {
|
|||
Properties properties = new Properties();
|
||||
properties.setProperty(propertyName, propertyValue);
|
||||
|
||||
String result = new PropertyParser(properties).getString(propertyName);
|
||||
String result = new PropertiesReader(properties).getString(propertyName);
|
||||
assertEquals(propertyValue, result, "Result \"" + result + "\" does not match expected output \"" + propertyValue + "\"");
|
||||
}
|
||||
|
||||
|
@ -75,7 +75,7 @@ class PropertyParserTest extends TestBase {
|
|||
Properties properties = new Properties();
|
||||
properties.setProperty(propertyName, propertyValue);
|
||||
|
||||
Boolean result = new PropertyParser(properties).getBoolean(propertyName);
|
||||
Boolean result = new PropertiesReader(properties).getBoolean(propertyName);
|
||||
assertEquals(expected, result, "Result \"" + result + "\" does not match expected output \"" + expected + "\"");
|
||||
}
|
||||
|
||||
|
@ -99,7 +99,7 @@ class PropertyParserTest extends TestBase {
|
|||
Properties properties = new Properties();
|
||||
properties.setProperty(propertyName, propertyValue);
|
||||
|
||||
Byte result = new PropertyParser(properties).getByte(propertyName);
|
||||
Byte result = new PropertiesReader(properties).getByte(propertyName);
|
||||
assertEquals(expected, result, "Result \"" + result + "\" does not match expected output \"" + expected + "\"");
|
||||
}
|
||||
|
||||
|
@ -123,7 +123,7 @@ class PropertyParserTest extends TestBase {
|
|||
Properties properties = new Properties();
|
||||
properties.setProperty(propertyName, propertyValue);
|
||||
|
||||
Short result = new PropertyParser(properties).getShort(propertyName);
|
||||
Short result = new PropertiesReader(properties).getShort(propertyName);
|
||||
assertEquals(expected, result, "Result \"" + result + "\" does not match expected output \"" + expected + "\"");
|
||||
}
|
||||
|
||||
|
@ -148,7 +148,7 @@ class PropertyParserTest extends TestBase {
|
|||
Properties properties = new Properties();
|
||||
properties.setProperty(propertyName, propertyValue);
|
||||
|
||||
Integer result = new PropertyParser(properties).getInteger(propertyName, false);
|
||||
Integer result = new PropertiesReader(properties).getInteger(propertyName, false);
|
||||
assertEquals(expected, result, "Result \"" + result + "\" does not match expected output \"" + expected + "\"");
|
||||
}
|
||||
|
||||
|
@ -173,7 +173,7 @@ class PropertyParserTest extends TestBase {
|
|||
Properties properties = new Properties();
|
||||
properties.setProperty(propertyName, propertyValue);
|
||||
|
||||
Long result = new PropertyParser(properties).getLong(propertyName, false);
|
||||
Long result = new PropertiesReader(properties).getLong(propertyName, false);
|
||||
assertEquals(expected, result, "Result \"" + result + "\" does not match expected output \"" + expected + "\"");
|
||||
}
|
||||
|
||||
|
@ -199,7 +199,7 @@ class PropertyParserTest extends TestBase {
|
|||
Properties properties = new Properties();
|
||||
properties.setProperty(propertyName, propertyValue);
|
||||
|
||||
Float result = new PropertyParser(properties).getFloat(propertyName);
|
||||
Float result = new PropertiesReader(properties).getFloat(propertyName);
|
||||
assertEquals(expected, result, "Result \"" + result + "\" does not match expected output \"" + expected + "\"");
|
||||
}
|
||||
|
||||
|
@ -223,7 +223,7 @@ class PropertyParserTest extends TestBase {
|
|||
Properties properties = new Properties();
|
||||
properties.setProperty(propertyName, propertyValue);
|
||||
|
||||
Double result = new PropertyParser(properties).getDouble(propertyName);
|
||||
Double result = new PropertiesReader(properties).getDouble(propertyName);
|
||||
assertEquals(expected, result, "Result \"" + result + "\" does not match expected output \"" + expected + "\"");
|
||||
}
|
||||
}
|
|
@ -20,7 +20,7 @@
|
|||
package de.staropensource.sosengine.graphics.glfw;
|
||||
|
||||
import de.staropensource.sosengine.base.classes.Configuration;
|
||||
import de.staropensource.sosengine.base.utility.parser.PropertyParser;
|
||||
import de.staropensource.sosengine.base.utility.PropertiesReader;
|
||||
import de.staropensource.sosengine.graphics.glfw.types.GlfwPlatform;
|
||||
import lombok.Getter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
@ -109,7 +109,7 @@ public final class GlfwSubsystemConfiguration extends Configuration {
|
|||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
protected void matchProperty(@NotNull PropertyParser parser, @NotNull String property) {
|
||||
protected void matchProperty(@NotNull PropertiesReader parser, @NotNull String property) {
|
||||
switch (property) {
|
||||
case "platform" -> {
|
||||
try {
|
||||
|
@ -124,7 +124,7 @@ public final class GlfwSubsystemConfiguration extends Configuration {
|
|||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
protected void processSettings(@NotNull PropertyParser parser) {}
|
||||
protected void processSettings(@NotNull PropertiesReader parser) {}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
package de.staropensource.sosengine.graphics;
|
||||
|
||||
import de.staropensource.sosengine.base.classes.Configuration;
|
||||
import de.staropensource.sosengine.base.utility.parser.PropertyParser;
|
||||
import de.staropensource.sosengine.base.utility.PropertiesReader;
|
||||
import de.staropensource.sosengine.graphics.events.GraphicsErrorEvent;
|
||||
import de.staropensource.sosengine.graphics.types.window.VsyncMode;
|
||||
import lombok.Getter;
|
||||
|
@ -169,7 +169,7 @@ public final class GraphicsSubsystemConfiguration extends Configuration {
|
|||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
protected void matchProperty(@NotNull PropertyParser parser, @NotNull String property) {
|
||||
protected void matchProperty(@NotNull PropertiesReader parser, @NotNull String property) {
|
||||
switch (property) {
|
||||
case "debug" -> debug = parser.getBoolean(group + property);
|
||||
case "debugInput" -> debugInput = parser.getBoolean(group + property);
|
||||
|
@ -190,7 +190,7 @@ public final class GraphicsSubsystemConfiguration extends Configuration {
|
|||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
protected void processSettings(@NotNull PropertyParser parser) {
|
||||
protected void processSettings(@NotNull PropertiesReader parser) {
|
||||
// Disable all debug options if 'debug' is disabled
|
||||
if (!debug) {
|
||||
debugInput = false;
|
||||
|
|
Loading…
Reference in a new issue