public class ArgTools extends Object
| Modifier and Type | Class and Description |
|---|---|
static interface |
ArgTools.IBindingProcessor |
| Constructor and Description |
|---|
ArgTools() |
| Modifier and Type | Method and Description |
|---|---|
static IArgs |
createArgs() |
static IArgs |
expandDeep(IArgs args,
IStringEvaluator evaluator)
Expand recursively all string templates in
args using the
evaluator. |
static IArgs |
expandDeep(IArgs args,
String name,
IStringEvaluator evaluator)
Expand recursively all string templates in
args binding for
name using the evaluator. |
static IArgs |
getArgs(IArgs args,
String name,
IArgs defaultValue)
The argument value at
name as an IArgs instance. |
static boolean |
getBool(IArgs args,
String name,
boolean defaultValue)
The argument value at
name as a boolean. |
static boolean |
getBoolean(IArgs args,
String name,
boolean defaultValue)
Synonym for getBool.
|
static byte |
getByte(IArgs args,
String name,
byte defaultValue)
The argument value at
name as a byte. |
static byte[] |
getByteArray(IArgs args,
String name,
byte[] defaultValue)
The argument value at
name as a byte array. |
static char |
getChar(IArgs args,
String name,
char defaultValue)
The argument value at
name as a char. |
static char[] |
getCharArray(IArgs args,
String name,
char[] defaultValue)
The argument value at
name as a char[]. |
static Class |
getClass(IArgs args,
String name,
Class defaultValue,
ClassLoader classLoader)
The argument value at
name as a Class. |
static Color |
getColor(IArgs args,
String name,
Color defaultValue)
The argument value at
name as a Color. |
static Date |
getDate(IArgs args,
String name,
Date defaultValue)
The argument value at
name as a Date. |
static IDigest |
getDigest(IArgs args,
String name)
The argument value at
name as an IDigest. |
static <T extends EnumItem> |
getEnumItem(IArgs args,
EnumMeta<T> meta,
String name)
The argument value at
name as a EnumItem. |
static <T extends EnumItem> |
getEnumItem(IArgs args,
EnumMeta<T> meta,
String name,
String defaultValue)
The argument value at
name as a EnumItem. |
static <T extends EnumItem> |
getEnumItem(IArgs args,
EnumMeta<T> meta,
String name,
T defaultValue)
The argument value at
name as a EnumItem. |
static File |
getFile(IArgs args,
String name,
File defaultValue)
The argument value at
name as a File. |
static float |
getFloat(IArgs args,
String name,
float defaultValue)
The argument value at
name as a float. |
static int |
getInt(IArgs args,
String name,
int defaultValue)
The argument value at
name as a int. |
static List |
getList(IArgs args,
String name,
List defaultValue)
The argument value at
name as a List. |
static ILocator |
getLocator(IArgs args,
String name,
ILocator defaultValue,
ILocatorFactory factory)
The argument value at
name as a ILocator. |
static List<ILocator> |
getLocators(IArgs args,
String name,
ILocatorFactory factory)
The argument value at
name as a List |
static Level |
getLogLevel(IArgs args,
String name,
Level defaultValue)
The argument value at
name as a Level. |
static long |
getLong(IArgs args,
String name,
long defaultValue)
The argument value at
name as a long. |
static Map |
getMap(IArgs args,
String name,
Map defaultValue)
The argument value at
name as a Map. |
static Object |
getObject(IArgs args,
String name,
Object defaultValue)
The argument value at
name as a Object. |
static Object |
getPath(IArgs args,
String path)
|
static Point2D |
getPoint(IArgs args,
String name,
Point2D defaultValue)
The argument value at
name as a Point2D. |
static String |
getString(IArgs args,
String name,
String defaultValue)
The argument value at
name as a String. |
static <T> T |
getValue(IArgs args,
String name,
Class<T> clazz,
Object defaultValue)
The argument value at
name converted to clazz. |
static boolean |
isDefined(IArgs args,
String path)
Interpret
path as a "." separated sequence of arg names,
descend (and lazy create) the tree of IArgs objects and return
true if all bindings in the path are defined. |
static String |
prefix(String prefix,
String name)
Create a new camel case argument name from
name by prefixing
with prefix. |
static IArgs |
putAll(IArgs args,
IArgs other)
Put all named top level entries in
other into
args. |
static IArgs |
putAll(IArgs args,
Map map)
Put all top level entries in
map into args. |
static IArgs |
putAllDeep(IArgs args,
IArgs other)
Merge recursively all entries from
other into args. |
static IArgs |
putAllDeep(IArgs args,
List list)
Merge recursively all entries from
list into args. |
static IArgs |
putAllDeep(IArgs args,
Map map)
Merge recursively all entries from
map into args. |
static IArgs |
putAllIfAbsent(IArgs args,
IArgs other)
Put all named top level entries in
other that are not
already defined into args. |
static IArgs |
putAllIfAbsent(IArgs args,
Map map)
Put all top level entries in
map that are not already
defined into args. |
static IArgs |
putAllIfAbsentDeep(IArgs args,
IArgs other)
Merge recursively all named entries from
other that are not
already defined in args into args. |
static void |
putDefinition(IArgs args,
String definition)
Add a String based definition to args.
|
static IArgs |
putMapped(IArgs args,
IArgs other,
String[] argsNames,
String[] otherNames)
Shovel arguments from other to args, mapping the argument names from
otherNames to argsNames.
|
static IArgs |
putPath(IArgs args,
String path,
Object value)
|
static IArgs |
toArgs(Object value)
Cast or convert
value to an IArgs. |
static List |
toList(IArgs args)
Convert the
args to a List. |
static Map |
toMap(IArgs args)
Convert the
args to a Map. |
static Map |
toMapDeep(IArgs args)
Convert the
args to a Map. |
static Map<String,Object> |
toMapDeepFlat(IArgs args)
Convert the
args to a Map. |
static Map<String,Object> |
toMapDeepFlat(IArgs args,
String prefix,
Map<String,Object> map)
Convert the
args to a Map. |
static String |
toString(IArgs args,
String prefix)
Create a printable
String for args. |
static void |
undefinePath(IArgs args,
String path)
Interpret
path as a "." separated sequence of arg names,
descend the tree of IArgs objects and undefine the leave name. |
static void |
visitNamedBindings(String prefix,
IArgs args,
ArgTools.IBindingProcessor processor)
For all named argument bindings perform the
ArgTools.IBindingProcessor. |
public static IArgs createArgs()
public static IArgs expandDeep(IArgs args, IStringEvaluator evaluator)
args using the
evaluator.
args is modified to contain the result of the expansion process and returned to ease call chaining.
args - evaluator - public static IArgs expandDeep(IArgs args, String name, IStringEvaluator evaluator)
args binding for
name using the evaluator.
args is modified to contain the result of the expansion process and returned to ease call chaining.
args - evaluator - public static IArgs getArgs(IArgs args, String name, IArgs defaultValue)
name as an IArgs instance. If
the argument value is not provided or not convertible,
defaultValueis returned.
This method performs the necessary casts and conversions. Supported input
types are null, IArgs, String, Map
and List.
args - name - defaultValue - name as an IArgs
instance.public static boolean getBool(IArgs args, String name, boolean defaultValue)
name as a boolean. If the argument
value is not provided or not convertible, defaultValueis
returned.
This method performs the necessary casts and conversions. Supported input
types are null, Boolean, String.
args - name - defaultValue - name as a booleanpublic static boolean getBoolean(IArgs args, String name, boolean defaultValue)
args - name - defaultValue - public static byte getByte(IArgs args, String name, byte defaultValue)
name as a byte. If the argument value
is not provided or not convertible, defaultValueis returned.
This method performs the necessary casts and conversions. Supported input
types are null, Number, String.
args - name - defaultValue - name as a byte.public static byte[] getByteArray(IArgs args, String name, byte[] defaultValue)
name as a byte array. If the argument
value is not provided or not convertible, defaultValueis
returned.args - name - defaultValue - name as a byte array.public static char getChar(IArgs args, String name, char defaultValue)
name as a char. If the argument value
is not provided or not convertible, defaultValueis returned.
This method performs the necessary casts and conversions. Supported input
types are null, Character, String.
args - name - defaultValue - name as a char.public static char[] getCharArray(IArgs args, String name, char[] defaultValue) throws IllegalArgumentException
name as a char[]. If the argument
value is not provided or not convertible, defaultValueis
returned.
This method performs the necessary casts and conversions. Supported input
types are null, String, char[]. Unlike the other
conversion methods, this one throws an IllegalArgumentException, if the
value is not of type String or char[].
args - name - defaultValue - name as a String.IllegalArgumentException - if value is not of type String or
char[]public static Class getClass(IArgs args, String name, Class defaultValue, ClassLoader classLoader)
name as a Class. If the
argument value is not provided or not convertible,
defaultValueis returned.
This method performs the necessary casts and conversions. Supported input
types are null, Boolean, String.
args - name - defaultValue - name as a Class.public static Color getColor(IArgs args, String name, Color defaultValue)
name as a Color. If the
argument value is not provided or not convertible,
defaultValueis returned.args - name - defaultValue - name as a Color.public static Date getDate(IArgs args, String name, Date defaultValue)
name as a Date. If the
argument value is not provided or not convertible,
defaultValueis returned.
This method performs the necessary casts and conversions. Supported input
types are null, Date, String.
args - name - defaultValue - name as a Date.public static IDigest getDigest(IArgs args, String name) throws IOException
name as an IDigest.args - name - name as an IDigest.IOExceptionpublic static <T extends EnumItem> T getEnumItem(IArgs args, EnumMeta<T> meta, String name)
name as a EnumItem. If the
argument value is not provided or not convertible, the enumeration
default value is returned.
This method performs the necessary casts and conversions. Supported input
types are null, EnumItem, String.
args - meta - name - name as a EnumItem.public static <T extends EnumItem> T getEnumItem(IArgs args, EnumMeta<T> meta, String name, String defaultValue)
name as a EnumItem. If the
argument value is not provided or not convertible, the enumeration item
with the id defaultValue is returned.
This method performs the necessary casts and conversions. Supported input
types are null, EnumItem, String.
args - meta - name - name as a EnumItem.public static <T extends EnumItem> T getEnumItem(IArgs args, EnumMeta<T> meta, String name, T defaultValue)
name as a EnumItem. If the
argument value is not provided or not convertible, the
defaultValue is returned.args - meta - name - name as a EnumItem.public static File getFile(IArgs args, String name, File defaultValue)
name as a File. If the
argument value is not provided or not convertible,
defaultValueis returned.
This method performs the necessary casts and conversions. Supported input
types are null, File, String,
ILocator.
args - name - defaultValue - name as a Date.public static float getFloat(IArgs args, String name, float defaultValue)
name as a float. If the argument value
is not provided or not convertible, defaultValueis returned.
This method performs the necessary casts and conversions. Supported input
types are null, Number, String.
args - name - defaultValue - name as a float.public static int getInt(IArgs args, String name, int defaultValue)
name as a int. If the argument value
is not provided or not convertible, defaultValueis returned.
This method performs the necessary casts and conversions. Supported input
types are null, Number, String.
args - name - defaultValue - name as a int.public static List getList(IArgs args, String name, List defaultValue)
name as a List. If the
argument value is not provided or not convertible,
defaultValueis returned.args - name - defaultValue - name as a List.public static ILocator getLocator(IArgs args, String name, ILocator defaultValue, ILocatorFactory factory)
name as a ILocator. If the
argument value is not provided or not convertible,
defaultValueis returned.
This method performs the necessary casts and conversions. Supported input
types are null, ILocator, String,
File
args - name - defaultValue - factory - name as a ILocator.public static List<ILocator> getLocators(IArgs args, String name, ILocatorFactory factory)
name as a Listnullis returned.
This method performs the necessary casts and conversions. Supported input
types are Collection of ILocator, String and
File.
args - name - factory - name as a List.public static Level getLogLevel(IArgs args, String name, Level defaultValue)
name as a Level. If the
argument value is not provided or not convertible,
defaultValueis returned.args - name - defaultValue - name as a Level.public static long getLong(IArgs args, String name, long defaultValue)
name as a long. If the argument value
is not provided or not convertible, defaultValueis returned.
This method performs the necessary casts and conversions. Supported input
types are null, Number, String.
args - name - defaultValue - name as a int.public static Map getMap(IArgs args, String name, Map defaultValue)
name as a Map. If the argument
value is not provided or not convertible, defaultValueis
returned.
This method performs the necessary casts and conversions. Supported input
types are null, Map, String.
args - name - defaultValue - name as a Map.public static Object getObject(IArgs args, String name, Object defaultValue)
name as a Object. If the
argument value is not provided or not convertible,
defaultValueis returned.
This method performs the necessary casts and conversions. Supported input
types are null, Object.
args - name - defaultValue - name as a Object.public static Object getPath(IArgs args, String path)
path as a "." separated sequence of arg names,
descend (and lazy create) the tree of IArgs objects and return
the value in the leaf IArgs instance or null.args - path - public static Point2D getPoint(IArgs args, String name, Point2D defaultValue)
name as a Point2D. If the
argument value is not provided or not convertible,
defaultValueis returned.
This method performs the necessary casts and conversions. Supported input
types are null, Point2D, String.
args - name - defaultValue - name as a Point2D.public static String getString(IArgs args, String name, String defaultValue)
name as a String. If the
argument value is not provided or not convertible,
defaultValueis returned.
This method performs the necessary casts and conversions. Supported input
types are null, String, Object.
args - name - defaultValue - name as a String.public static <T> T getValue(IArgs args, String name, Class<T> clazz, Object defaultValue)
name converted to clazz. If the
argument value is not provided or not convertible,
defaultValueis returned.args - name - clazz - defaultValue - name converted to clazz.public static boolean isDefined(IArgs args, String path)
path as a "." separated sequence of arg names,
descend (and lazy create) the tree of IArgs objects and return
true if all bindings in the path are defined.args - path - public static String prefix(String prefix, String name)
name by prefixing
with prefix.prefix - name - public static IArgs putAll(IArgs args, IArgs other)
other into
args.
args is modified to contain the result of the merge process and returned to ease call chaining.
args - other - public static IArgs putAll(IArgs args, Map map)
map into args. The
map keys are interpreted as a path expression ("." separated).
args is modified to contain the result of the merge process and returned to ease call chaining.
args - map - public static IArgs putAllDeep(IArgs args, IArgs other)
other into args. If an
IArgs.IBinding in other is already contained in args, args is
overwritten.
args is modified to contain the result of the merge process and returned to ease call chaining.
args - other - public static IArgs putAllDeep(IArgs args, List list)
list into args.
args is modified to contain the result of the merge process and returned to ease call chaining.
args - map - public static IArgs putAllDeep(IArgs args, Map map)
map into args.
args is modified to contain the result of the merge process and returned to ease call chaining.
args - map - public static IArgs putAllIfAbsent(IArgs args, IArgs other)
other that are not
already defined into args.
args is modified to contain the result of the merge process and returned to ease call chaining.
args - other - public static IArgs putAllIfAbsent(IArgs args, Map map)
map that are not already
defined into args. The map keys are interpreted as a path
expression ("." separated).
args is modified to contain the result of the merge process and returned to ease call chaining.
args - map - public static IArgs putAllIfAbsentDeep(IArgs args, IArgs other)
other that are not
already defined in args into args.
args is modified to contain the result of the merge process and returned to ease call chaining.
args - other - public static void putDefinition(IArgs args, String definition)
args - definition - public static IArgs putMapped(IArgs args, IArgs other, String[] argsNames, String[] otherNames)
args - other - argsNames - otherNames - public static IArgs putPath(IArgs args, String path, Object value)
path as a "." separated sequence of arg names,
descend (and lazy create) the tree of IArgs objects and set
value in the leaf IArgs instance.args - path - value - public static IArgs toArgs(Object value)
value to an IArgs.value - IArgs created from value.public static List toList(IArgs args)
args to a List.args - List representation of the argspublic static Map toMap(IArgs args)
args to a Map. This is done 1 level
deep, i.e. the immediate children of args are now members of the map. If
args contains nested args, these are left alone.
Example, where {} denotes an IArgs structure and [] a Map
.
{
a = "b"
x = {
i = 12
j = {
last = "nn"
}
}
}
will result in
[
a -> "b"
x -> {
i = 12
j = {
last = "nn"
}
}
]
args - Map representation of the argspublic static Map toMapDeep(IArgs args)
args to a Map. This is done recursively,
i.e. all IArgs substructures are converted to maps. The result is a
nested map as well.
Example, where {} denotes an IArgs structure and [] a Map
.
{
a = "b"
x = {
i = 12
j = {
last = "nn"
}
}
}
will result in
[
a -> "b"
x -> [
i -> 12
j -> [
last -> "nn"
]
]
]
args - Map representation of the argspublic static Map<String,Object> toMapDeepFlat(IArgs args)
args to a Map. This is done recursively,
i.e. all IArgs substructures are converted, too. The result is a map
where the keys are path names.
Example, where {} denotes an IArgs structure and [] a Map
.
{
a = "b"
x = {
i = 12
j = {
last = "nn"
}
}
}
will result in
[ a -> "b" x.i -> 12 x.j.last -> "nn" ]
args - Map representation of the argspublic static Map<String,Object> toMapDeepFlat(IArgs args, String prefix, Map<String,Object> map)
args to a Map. This is done recursively,
i.e. all IArgs substructures are converted, too. The result is a map
where the keys are path names.
Example, where {} denotes an IArgs structure and [] a Map
.
{
a = "b"
x = {
i = 12
j = {
last = "nn"
}
}
}
will result in
[ a -> "b" x.i -> 12 x.j.last -> "nn" ]
args - Map representation of the argspublic static String toString(IArgs args, String prefix)
String for args.args - prefix - public static void undefinePath(IArgs args, String path)
path as a "." separated sequence of arg names,
descend the tree of IArgs objects and undefine the leave name.args - path - public static void visitNamedBindings(String prefix, IArgs args, ArgTools.IBindingProcessor processor)
ArgTools.IBindingProcessor.
This method performs a depth first enumeration and call the binding
processor for each leaf element in the argument tree.prefix - args - processor - Copyright © 2013 intarsys consulting GmbH. All Rights Reserved.