de.intarsys.tools.functor
Class ArgTools

java.lang.Object
  extended by de.intarsys.tools.functor.ArgTools

public class ArgTools
extends java.lang.Object

Tool class to ease handling of arguments.


Field Summary
static IFunctor toString
           
 
Constructor Summary
ArgTools()
           
 
Method Summary
protected static ILocator createLocator(java.lang.Object optionValue, ILocator defaultValue, ILocatorFactory factory)
           
static IArgs getArgs(IArgs args, java.lang.String name, IArgs defaultValue)
          The argument value at name as an IArgs instance.
static boolean getBool(IArgs args, java.lang.String name, boolean defaultValue)
          The argument value at name as a boolean.
static byte getByte(IArgs args, java.lang.String name, byte defaultValue)
          The argument value at name as a byte.
static char getChar(IArgs args, java.lang.String name, char defaultValue)
          The argument value at name as a char.
static char[] getCharArray(IArgs args, java.lang.String name, char[] defaultValue)
          The argument value at name as a char[].
static java.lang.Class getClass(IArgs args, java.lang.String name, java.lang.Class defaultValue)
          The argument value at name as a Class.
static java.util.Date getDate(IArgs args, java.lang.String name, java.util.Date defaultValue)
          The argument value at name as a Date.
static
<T extends EnumItem>
T
getEnumItem(IArgs args, EnumMeta<T> meta, java.lang.String name)
          The argument value at name as a EnumItem.
static
<T extends EnumItem>
T
getEnumItem(IArgs args, EnumMeta<T> meta, java.lang.String name, java.lang.String defaultValue)
          The argument value at name as a EnumItem.
static java.io.File getFile(IArgs args, java.lang.String name, java.io.File defaultValue)
          The argument value at name as a File.
static float getFloat(IArgs args, java.lang.String name, float defaultValue)
          The argument value at name as a float.
static int getInt(IArgs args, java.lang.String name, int defaultValue)
          The argument value at name as a int.
static ILocator getLocator(IArgs args, java.lang.String name, ILocator defaultValue, ILocatorFactory factory)
          The argument value at name as a ILocator.
static java.util.List<ILocator> getLocators(IArgs args, java.lang.String name, ILocatorFactory factory)
          The argument value at name as a List.
static java.util.Map getMap(IArgs args, java.lang.String name, java.util.Map defaultValue)
          The argument value at name as a Map.
static java.lang.Object getObject(IArgs args, java.lang.String name, java.lang.Object defaultValue)
          The argument value at name as a Object.
static java.awt.geom.Point2D getPoint(IArgs args, java.lang.String name, java.awt.geom.Point2D defaultValue)
          The argument value at name as a Point2D.
static java.lang.String getString(IArgs args, java.lang.String name, java.lang.String defaultValue)
          The argument value at name as a String.
static java.lang.String prefix(java.lang.String prefix, java.lang.String name)
          Create a new argument name from name by prefixing with prefix.
static IArgs toArgs(java.lang.Object value)
          Cast or convert value to an IArgs.
static java.util.List toList(IArgs args)
          Convert the args to a List.
static java.util.Map toMap(IArgs args)
          Convert the args to a Map.
static java.lang.String toString(IArgs args, java.lang.String prefix)
          Create a printable String for args.
protected static void toStringArgs(java.lang.String prefix, java.lang.StringBuilder sb, java.lang.String name, IArgs value)
           
protected static void toStringPlain(java.lang.String prefix, java.lang.StringBuilder sb, java.lang.String name, java.lang.Object value)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

toString

public static final IFunctor toString
Constructor Detail

ArgTools

public ArgTools()
Method Detail

createLocator

protected static ILocator createLocator(java.lang.Object optionValue,
                                        ILocator defaultValue,
                                        ILocatorFactory factory)

getArgs

public static IArgs getArgs(IArgs args,
                            java.lang.String name,
                            IArgs defaultValue)
The argument value at 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.

Parameters:
args -
name -
defaultValue -
Returns:
The argument value at name as an IArgs instance.

getBool

public static boolean getBool(IArgs args,
                              java.lang.String name,
                              boolean defaultValue)
The argument value at 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.

Parameters:
args -
name -
defaultValue -
Returns:
The argument value at name as a boolean

getByte

public static byte getByte(IArgs args,
                           java.lang.String name,
                           byte defaultValue)
The argument value at 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.

Parameters:
args -
name -
defaultValue -
Returns:
The argument value at name as a byte.

getChar

public static char getChar(IArgs args,
                           java.lang.String name,
                           char defaultValue)
The argument value at 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.

Parameters:
args -
name -
defaultValue -
Returns:
The argument value at name as a char.

getCharArray

public static char[] getCharArray(IArgs args,
                                  java.lang.String name,
                                  char[] defaultValue)
                           throws java.lang.IllegalArgumentException
The argument value at 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[].

Parameters:
args -
name -
defaultValue -
Returns:
The argument value at name as a String.
Throws:
java.lang.IllegalArgumentException - if value is not of type String or char[]

getClass

public static java.lang.Class getClass(IArgs args,
                                       java.lang.String name,
                                       java.lang.Class defaultValue)
The argument value at 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.

Parameters:
args -
name -
defaultValue -
Returns:
The argument value at name as a Class.

getDate

public static java.util.Date getDate(IArgs args,
                                     java.lang.String name,
                                     java.util.Date defaultValue)
The argument value at 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.

Parameters:
args -
name -
defaultValue -
Returns:
The argument value at name as a Date.

getEnumItem

public static <T extends EnumItem> T getEnumItem(IArgs args,
                                                 EnumMeta<T> meta,
                                                 java.lang.String name)
The argument value at 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.

Parameters:
args -
meta -
name -
Returns:
The argument value at name as a EnumItem.

getEnumItem

public static <T extends EnumItem> T getEnumItem(IArgs args,
                                                 EnumMeta<T> meta,
                                                 java.lang.String name,
                                                 java.lang.String defaultValue)
The argument value at name as a EnumItem. If the argument value is not provided or not convertible, the enumeration item with the id defaultValuee is returned.

This method performs the necessary casts and conversions. Supported input types are null, EnumItem, String.

Parameters:
args -
meta -
name -
Returns:
The argument value at name as a EnumItem.

getFile

public static java.io.File getFile(IArgs args,
                                   java.lang.String name,
                                   java.io.File defaultValue)
The argument value at 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.

Parameters:
args -
name -
defaultValue -
Returns:
The argument value at name as a Date.

getFloat

public static float getFloat(IArgs args,
                             java.lang.String name,
                             float defaultValue)
The argument value at 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.

Parameters:
args -
name -
defaultValue -
Returns:
The argument value at name as a float.

getInt

public static int getInt(IArgs args,
                         java.lang.String name,
                         int defaultValue)
The argument value at 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.

Parameters:
args -
name -
defaultValue -
Returns:
The argument value at name as a int.

getLocator

public static ILocator getLocator(IArgs args,
                                  java.lang.String name,
                                  ILocator defaultValue,
                                  ILocatorFactory factory)
The argument value at 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

Parameters:
args -
name -
defaultValue -
factory -
Returns:
The argument value at name as a ILocator.

getLocators

public static java.util.List<ILocator> getLocators(IArgs args,
                                                   java.lang.String name,
                                                   ILocatorFactory factory)
The argument value at name as a List. If the argument value is not provided, nullis returned.

This method performs the necessary casts and conversions. Supported input types are Collection of ILocator, String and File.

Parameters:
args -
name -
factory -
Returns:
The argument value at name as a List.

getMap

public static java.util.Map getMap(IArgs args,
                                   java.lang.String name,
                                   java.util.Map defaultValue)
The argument value at 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.

Parameters:
args -
name -
defaultValue -
Returns:
The argument value at name as a Map.

getObject

public static java.lang.Object getObject(IArgs args,
                                         java.lang.String name,
                                         java.lang.Object defaultValue)
The argument value at 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.

Parameters:
args -
name -
defaultValue -
Returns:
The argument value at name as a Object.

getPoint

public static java.awt.geom.Point2D getPoint(IArgs args,
                                             java.lang.String name,
                                             java.awt.geom.Point2D defaultValue)
The argument value at 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.

Parameters:
args -
name -
defaultValue -
Returns:
The argument value at name as a Point2D.

getString

public static java.lang.String getString(IArgs args,
                                         java.lang.String name,
                                         java.lang.String defaultValue)
The argument value at 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.

Parameters:
args -
name -
defaultValue -
Returns:
The argument value at name as a String.

prefix

public static java.lang.String prefix(java.lang.String prefix,
                                      java.lang.String name)
Create a new argument name from name by prefixing with prefix.

Parameters:
prefix -
name -
Returns:
The new argument name.

toArgs

public static IArgs toArgs(java.lang.Object value)
Cast or convert value to an IArgs.

Parameters:
value -
Returns:
The IArgs created from value.

toList

public static java.util.List toList(IArgs args)
Convert the args to a List.

Parameters:
args -
Returns:
The List representation of the args

toMap

public static java.util.Map toMap(IArgs args)
Convert the args to a Map.

Parameters:
args -
Returns:
The Map representation of the args

toString

public static java.lang.String toString(IArgs args,
                                        java.lang.String prefix)
Create a printable String for args.

Parameters:
args -
prefix -
Returns:

toStringArgs

protected static void toStringArgs(java.lang.String prefix,
                                   java.lang.StringBuilder sb,
                                   java.lang.String name,
                                   IArgs value)

toStringPlain

protected static void toStringPlain(java.lang.String prefix,
                                    java.lang.StringBuilder sb,
                                    java.lang.String name,
                                    java.lang.Object value)