added converters
This commit is contained in:
@ -0,0 +1,21 @@
|
|||||||
|
package net.locusworks.argparser.converters;
|
||||||
|
|
||||||
|
import net.locusworks.argparser.interfaces.IParameterConverter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a DataDiodeProperty value into a boolean value
|
||||||
|
* @author Isaac Parenteau
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class BooleanConverter implements IParameterConverter<Boolean> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Boolean convert(String value) {
|
||||||
|
if (value == null || value.trim().isEmpty()) return false;
|
||||||
|
|
||||||
|
if (value.trim().toLowerCase().equals("yes")) return true;
|
||||||
|
|
||||||
|
boolean retVal = Boolean.parseBoolean(value.trim());
|
||||||
|
return retVal;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
package net.locusworks.argparser.converters;
|
||||||
|
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
|
import net.locusworks.argparser.interfaces.IParameterConverter;
|
||||||
|
|
||||||
|
public class ByteArrayConverter implements IParameterConverter<byte[]> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] convert(String value) {
|
||||||
|
return value.getBytes(StandardCharsets.UTF_8);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
package net.locusworks.argparser.converters;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
import net.locusworks.argparser.interfaces.IParameterConverter;
|
||||||
|
|
||||||
|
public class DirectoryConverter implements IParameterConverter<File> {
|
||||||
|
|
||||||
|
public File convert(String value) {
|
||||||
|
File file = new File(value);
|
||||||
|
return file;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,25 @@
|
|||||||
|
package net.locusworks.argparser.converters;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
import net.locusworks.argparser.interfaces.IParameterConverter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a command line argument to a File with verification that the file
|
||||||
|
* exists and is a file nothing else
|
||||||
|
* @author Isaac Parenteau
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class DirectoryExistConverter implements IParameterConverter<File>{
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public File convert(String value) {
|
||||||
|
File f = new File(value);
|
||||||
|
|
||||||
|
if (!f.exists()) throw new IllegalArgumentException(value + " does not exist");
|
||||||
|
if (!f.isDirectory()) throw new IllegalArgumentException(value + " is not a directory");
|
||||||
|
|
||||||
|
return new File(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,12 @@
|
|||||||
|
package net.locusworks.argparser.converters;
|
||||||
|
|
||||||
|
import net.locusworks.argparser.interfaces.IParameterConverter;
|
||||||
|
|
||||||
|
public class DoubleConverter implements IParameterConverter<Double> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Double convert(String value) {
|
||||||
|
return Double.parseDouble(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,25 @@
|
|||||||
|
package net.locusworks.argparser.converters;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
import net.locusworks.argparser.interfaces.IParameterConverter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a command line argument to a File with verification that the file
|
||||||
|
* exists and is a file nothing else
|
||||||
|
* @author Isaac Parenteau
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class FileExistConverter implements IParameterConverter<File>{
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public File convert(String value) {
|
||||||
|
File f = new File(value);
|
||||||
|
|
||||||
|
if (!f.exists()) throw new IllegalArgumentException(value + " does not exist");
|
||||||
|
if (!f.isFile()) throw new IllegalArgumentException(value + " is not a file");
|
||||||
|
|
||||||
|
return new File(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,12 @@
|
|||||||
|
package net.locusworks.argparser.converters;
|
||||||
|
|
||||||
|
import net.locusworks.argparser.interfaces.IParameterConverter;
|
||||||
|
|
||||||
|
public class FloatConverter implements IParameterConverter<Float> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Float convert(String value) {
|
||||||
|
return Float.parseFloat(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,12 @@
|
|||||||
|
package net.locusworks.argparser.converters;
|
||||||
|
|
||||||
|
import net.locusworks.argparser.interfaces.IParameterConverter;
|
||||||
|
|
||||||
|
public class LongConverter implements IParameterConverter<Long> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Long convert(String value) {
|
||||||
|
return Long.parseLong(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,12 @@
|
|||||||
|
package net.locusworks.argparser.converters;
|
||||||
|
|
||||||
|
import net.locusworks.argparser.interfaces.IParameterConverter;
|
||||||
|
|
||||||
|
public class ShortConverter implements IParameterConverter<Short> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Short convert(String value) {
|
||||||
|
return Short.parseShort(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Reference in New Issue
Block a user