net.sf.xenqtt
Class AppContext

java.lang.Object
  extended by net.sf.xenqtt.AppContext

public final class AppContext
extends Object

Contains the application context for a Xenqtt application


Constructor Summary
AppContext()
          Create a new instance of this class.
AppContext(List<String> flags, Map<String,String> arguments)
          Create a new instance of this class.
AppContext(List<String> flags, Map<String,String> arguments, CountDownLatch latch)
          Create a new instance of this class.
 
Method Summary
 void applicationDone()
          Invoke if your application has finished its work and no longer needs to run.
 boolean getArgAsBoolean(String argument)
          Get an argument value interpreted as a boolean.
 boolean getArgAsBoolean(String argument, boolean defaultValue)
          Get an argument value interpreted as a boolean.
 double getArgAsDouble(String argument)
          Get an argument value interpreted as a double.
 double getArgAsDouble(String argument, double defaultValue)
          Get an argument value interpreted as a double.
 int getArgAsInt(String argument)
          Get an argument value interpreted as an int.
 int getArgAsInt(String argument, int defaultValue)
          Get an argument value interpreted as an int.
 long getArgAsLong(String argument)
          Get an argument value interpreted as a long.
 long getArgAsLong(String argument, long defaultValue)
          Get an argument value interpreted as a long.
 String getArgAsString(String argument)
          Get an argument value interpreted as a string.
 String getArgAsString(String argument, String defaultValue)
          Get an argument value interpreted as a string.
 boolean isEmpty()
           
 boolean isFlagSpecified(String flag)
          Determine if a particular flag was specified.
 boolean wereAllFlagsInterrogated()
          Determine if each of the flags that was specified by the user was interrogated by the application.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AppContext

public AppContext()
Create a new instance of this class.


AppContext

public AppContext(List<String> flags,
                  Map<String,String> arguments)
Create a new instance of this class.

Parameters:
flags - The flags that were specified for the application
arguments - The arguments that were specified for the application

AppContext

public AppContext(List<String> flags,
                  Map<String,String> arguments,
                  CountDownLatch latch)
Create a new instance of this class.

Parameters:
flags - The flags that were specified for the application
arguments - The arguments that were specified for the application
latch - The latch which the main application thread will await on. Trigger this if your application can terminate after performing certain tasks (e.g. a test)
Method Detail

isFlagSpecified

public boolean isFlagSpecified(String flag)
Determine if a particular flag was specified.

Parameters:
flag - The flag to check for
Returns:
true if the specified flag was found in the flags that were given by the user, false if it was not

wereAllFlagsInterrogated

public boolean wereAllFlagsInterrogated()
Determine if each of the flags that was specified by the user was interrogated by the application.

Returns:
true if each user-specified flag was interrogated, false if at least one was not

getArgAsInt

public int getArgAsInt(String argument)
Get an argument value interpreted as an int.

Parameters:
argument - The name of the argument
Returns:
The value associated with the argument interpreted as an int
Throws:
IllegalStateException - If the argument is not found
NumberFormatException - If the argument is found but cannot be interpreted as an int

getArgAsInt

public int getArgAsInt(String argument,
                       int defaultValue)
Get an argument value interpreted as an int.

Parameters:
argument - The name of the argument
defaultValue - The default value to use if the argument is not found
Returns:
The value associated with the argument interpreted as an int
Throws:
NumberFormatException - If the argument is found but cannot be interpreted as an int

getArgAsLong

public long getArgAsLong(String argument)
Get an argument value interpreted as a long.

Parameters:
argument - The name of the argument
Returns:
The value associated with the argument interpreted as a long
Throws:
IllegalStateException - If the argument is not found
NumberFormatException - If the argument is found but cannot be interpreted as a long

getArgAsLong

public long getArgAsLong(String argument,
                         long defaultValue)
Get an argument value interpreted as a long.

Parameters:
argument - The name of the argument
defaultValue - The default value to use if the argument is not found
Returns:
The value associated with the argument interpreted as a long
Throws:
NumberFormatException - If the argument is found but cannot be interpreted as a long

getArgAsDouble

public double getArgAsDouble(String argument)
Get an argument value interpreted as a double.

Parameters:
argument - The name of the argument
Returns:
The value associated with the argument interpreted as a double
Throws:
IllegalStateException - If the argument is not found
NumberFormatException - If the argument is found but cannot be interpreted as a double

getArgAsDouble

public double getArgAsDouble(String argument,
                             double defaultValue)
Get an argument value interpreted as a double.

Parameters:
argument - The name of the argument
defaultValue - The default value to use if the argument is not found
Returns:
The value associated with the argument interpreted as a double
Throws:
NumberFormatException - If the argument is found but cannot be interpreted as a double

getArgAsBoolean

public boolean getArgAsBoolean(String argument)
Get an argument value interpreted as a boolean.

Parameters:
argument - The name of the argument
Returns:
The value associated with the argument interpreted as a boolean
Throws:
IllegalStateException - If the argument is not found
NumberFormatException - If the argument is found but cannot be interpreted as a boolean

getArgAsBoolean

public boolean getArgAsBoolean(String argument,
                               boolean defaultValue)
Get an argument value interpreted as a boolean.

Parameters:
argument - The name of the argument
defaultValue - The default value to use if the argument is not found
Returns:
The value associated with the argument interpreted as a boolean
Throws:
NumberFormatException - If the argument is found but cannot be interpreted as a boolean

getArgAsString

public String getArgAsString(String argument)
Get an argument value interpreted as a string.

Parameters:
argument - The name of the argument
Returns:
The value associated with the argument interpreted as a string
Throws:
IllegalStateException - If the argument is not found

getArgAsString

public String getArgAsString(String argument,
                             String defaultValue)
Get an argument value interpreted as a string.

Parameters:
argument - The name of the argument
defaultValue - The default value to use if the argument is not found
Returns:
The value associated with the argument interpreted as a string

isEmpty

public boolean isEmpty()
Returns:
true if there are no flags or arguments, false if there is at least one flag or argument

applicationDone

public void applicationDone()
Invoke if your application has finished its work and no longer needs to run.



Copyright © 2013. All Rights Reserved.