com.twitter.common.args
Class Arg<T>

java.lang.Object
  extended by com.twitter.common.args.Arg<T>

public class Arg<T>
extends Object

Wrapper class for the value of an argument. For proper behavior, an Arg should always be annotated with CmdLine, which will define the command line interface to the argument.


Constructor Summary
Arg()
          Creates an arg that has no default value, meaning that its value can only ever be retrieved if it has been externally set.
Arg(T defaultValue)
          Creates an arg that has a default value, and may optionally be set.
 
Method Summary
static
<T> Arg<T>
create()
          Convenience factory method to create an arg that has no default value.
static
<T> Arg<T>
create(T value)
          Convenience factory method to create an arg with a default value.
 T get()
          Gets the value of the argument.
 boolean hasAppliedValue()
          Checks whether a value has been applied to the argument (i.e., apart from the default).
 boolean hasDefault()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Arg

public Arg()
Creates an arg that has no default value, meaning that its value can only ever be retrieved if it has been externally set.


Arg

public Arg(@Nullable
           T defaultValue)
Creates an arg that has a default value, and may optionally be set.

Parameters:
defaultValue - The default value for the arg.
Method Detail

hasDefault

public boolean hasDefault()

get

public T get()
Gets the value of the argument. If a value has not yet been applied to the argument, or the argument did not provide a default value, IllegalStateException will be thrown.

Returns:
The argument value.

hasAppliedValue

public boolean hasAppliedValue()
Checks whether a value has been applied to the argument (i.e., apart from the default).

Returns:
true if a value from the command line has been applied to this arg, false otherwise.

create

public static <T> Arg<T> create()
Convenience factory method to create an arg that has no default value.

Type Parameters:
T - Type of arg value.
Returns:
A new arg.

create

public static <T> Arg<T> create(@Nullable
                                T value)
Convenience factory method to create an arg with a default value.

Type Parameters:
T - Type of arg value.
Parameters:
value - Default argument value.
Returns:
A new arg.