intarsys runtime library

de.intarsys.tools.functor
Class ArgTools

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

public class ArgTools
extends Object

Tool class to ease handling of arguments.


Field Summary
static IFunctor toString
           
 
Constructor Summary
ArgTools()
           
 
Method Summary
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 byte getByte(IArgs args, String name, byte defaultValue)
          The argument value at name as a byte.
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)
          The argument value at name as a Class.
static Date getDate(IArgs args, String name, Date defaultValue)
          The argument value at name as a Date.
static
<T extends EnumItem>
T
getEnumItem(IArgs args, EnumMeta<T> meta, String name)
          The argument value at name as a EnumItem.
static
<T extends EnumItem>
T
getEnumItem(IArgs args, EnumMeta<T> meta, String name, String 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 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 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 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 String prefix(String prefix, String name)
          Create a new argument name from name by prefixing with prefix.
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 String toString(IArgs args, String prefix)
          Create a printable String for args.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

toString

public static final IFunctor toString
Constructor Detail

ArgTools

public ArgTools()
Method Detail

getArgs

public static IArgs getArgs(IArgs args,
                            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,
                              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,
                           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,
                           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,
                                  String name,
                                  char[] defaultValue)
                           throws 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:
IllegalArgumentException - if value is not of type String or char[]

getClass

public static Class getClass(IArgs args,
                             String name,
                             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 Date getDate(IArgs args,
                           String name,
                           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,
                                                 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,
                                                 String name,
                                                 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 File getFile(IArgs args,
                           String name,
                           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,
                             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,
                         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,
                                  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 List<ILocator> getLocators(IArgs args,
                                         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, Collection, Collection

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

getMap

public static Map getMap(IArgs args,
                         String name,
                         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 Object getObject(IArgs args,
                               String name,
                               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 Point2D getPoint(IArgs args,
                               String name,
                               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 String getString(IArgs args,
                               String name,
                               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 String prefix(String prefix,
                            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(Object value)
Cast or convert value to an IArgs.

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

toList

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

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

toMap

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

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

toString

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

Parameters:
args -
prefix -
Returns:

intarsys runtime library

Copyright © 2008 intarsys consulting GmbH. All Rights Reserved.