Moves argument related inner classes to own classes

This commit is contained in:
Kristian Knarvik 2020-05-08 19:07:19 +02:00
parent a5e14b4ee5
commit 1090a61f2e
2 changed files with 46 additions and 0 deletions

View File

@ -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;
}
}

View File

@ -0,0 +1,8 @@
package net.knarcraft.ffmpegconverter.parser;
public enum ConverterArgumentValue {
BOOLEAN,
COMMA_SEPARATED_LIST,
SINGLE_VALUE,
INT
}