From 1090a61f2e4b36eed8ec0c101bda42f7e9028956 Mon Sep 17 00:00:00 2001 From: EpicKnarvik97 Date: Fri, 8 May 2020 19:07:19 +0200 Subject: [PATCH] Moves argument related inner classes to own classes --- .../parser/ConverterArgument.java | 38 +++++++++++++++++++ .../parser/ConverterArgumentValue.java | 8 ++++ 2 files changed, 46 insertions(+) create mode 100644 src/main/java/net/knarcraft/ffmpegconverter/parser/ConverterArgument.java create mode 100644 src/main/java/net/knarcraft/ffmpegconverter/parser/ConverterArgumentValue.java diff --git a/src/main/java/net/knarcraft/ffmpegconverter/parser/ConverterArgument.java b/src/main/java/net/knarcraft/ffmpegconverter/parser/ConverterArgument.java new file mode 100644 index 0000000..81d2c70 --- /dev/null +++ b/src/main/java/net/knarcraft/ffmpegconverter/parser/ConverterArgument.java @@ -0,0 +1,38 @@ +package net.knarcraft.ffmpegconverter.parser; + +/** + * A class representing an argument + */ +public class ConverterArgument { + private final String name; + private final boolean valueRequired; + private final ConverterArgumentValue valueType; + + public ConverterArgument(String name, boolean valueRequired, ConverterArgumentValue valueType) { + this.name = name; + this.valueRequired = valueRequired; + this.valueType = valueType; + } + + private boolean testArgumentValue(String value) { + if (value.length() == 0) { + return !valueRequired; + } + if (valueRequired && value.startsWith("-")) { + return false; + } + switch (valueType) { + case BOOLEAN: + String lower = value.toLowerCase(); + return lower.equals("true") || lower.equals("false"); + case COMMA_SEPARATED_LIST: + return !value.contains(" "); + case SINGLE_VALUE: + return !value.contains(" "); + case INT: + int ignored = Integer.parseInt(value); + return true; + } + return false; + } +} diff --git a/src/main/java/net/knarcraft/ffmpegconverter/parser/ConverterArgumentValue.java b/src/main/java/net/knarcraft/ffmpegconverter/parser/ConverterArgumentValue.java new file mode 100644 index 0000000..1aad0b1 --- /dev/null +++ b/src/main/java/net/knarcraft/ffmpegconverter/parser/ConverterArgumentValue.java @@ -0,0 +1,8 @@ +package net.knarcraft.ffmpegconverter.parser; + +public enum ConverterArgumentValue { + BOOLEAN, + COMMA_SEPARATED_LIST, + SINGLE_VALUE, + INT +}