A flag without a default value.
A flag without a default value.
_declaration
In order to declare a new GlobalFlag in Java, it can be done with a bit of ceremony by following a few steps:
1. the flag's class name must end with "$", e.g. javaGlobalWithDefault$
.
This is done to mimic the behavior of Scala's singleton object
.
1. the class must have a method, public static Flag<?> globalFlagInstance()
,
that returns the singleton instance of the Flag.
1. the class should have a static final
field holding the singleton
instance of the flag.
1. the class should extend JavaGlobalFlag
.
1. to avoid extraneous creation of instances, thus forcing users to only
access the singleton, the constructor should be private
and the class
should be public final
.
An example of a GlobalFlag declared in Java:
import com.twitter.app.Flag; import com.twitter.app.Flaggable; import com.twitter.app.JavaGlobalFlag; public final class exampleJavaGlobalFlag$ extends JavaGlobalFlag<String> { private exampleJavaGlobalFlag() { super("The default value", "The help string", Flaggable.ofString()); } public static final Flag<String> Flag = new exampleJavaGlobalFlag(); public static Flag<?> globalFlagInstance() { return Flag; } }
_declaration
documentation regarding usage of this flag.
the type of the flag
A flag with a default value.
A flag with a default value.
_declaration
In order to declare a new GlobalFlag in Java, it can be done with a bit of ceremony by following a few steps:
1. the flag's class name must end with "$", e.g. javaGlobalWithDefault$
.
This is done to mimic the behavior of Scala's singleton object
.
1. the class must have a method, public static Flag<?> globalFlagInstance()
,
that returns the singleton instance of the Flag.
1. the class should have a static final
field holding the singleton
instance of the flag.
1. the class should extend JavaGlobalFlag
.
1. to avoid extraneous creation of instances, thus forcing users to only
access the singleton, the constructor should be private
and the class
should be public final
.
An example of a GlobalFlag declared in Java:
import com.twitter.app.Flag; import com.twitter.app.Flaggable; import com.twitter.app.JavaGlobalFlag; public final class exampleJavaGlobalFlag$ extends JavaGlobalFlag<String> { private exampleJavaGlobalFlag() { super("The default value", "The help string", Flaggable.ofString()); } public static final Flag<String> Flag = new exampleJavaGlobalFlag(); public static Flag<?> globalFlagInstance() { return Flag; } }
_declaration
the default value used if the value is not specified by the user.
documentation regarding usage of this flag.
Return this flag's current value.
Return this flag's current value. The default value is returned when the flag has not otherwise been set.
String representation of this flag's default value
String representation of this flag's default value
Get the value if it has been set.
Get the value if it has been set.
if no user-defined value has been set, None
will be
returned even when a default value is supplied.
Used by Flags.parseArgs to initialize Flag values.
Used by Flags.parseArgs to initialize Flag values.
Called via reflection assuming it will be a static
method on a singleton object
. This causes problems
for Java developers who want to create a GlobalFlag
as there is no good means for them to have it be a
static
method. Thus, Java devs must add a method
public static Flag<?> globalFlagInstance()
which
returns the singleton instance of the flag.
See JavaGlobalFlag for more details.
Get the value if it has been set or if there is a default value supplied.
Get the value if it has been set or if there is a default value supplied.
Flag.get and Flag.isDefined if you are interested in determining if there is a supplied value.
True if the flag has been set.
True if the flag has been set.
if no user-defined value has been set, false
will be
returned even when a default value is supplied.
Override the value of this flag with t
, only for the scope of the current
com.twitter.util.Local for the given function f
.
Override the value of this flag with t
, only for the scope of the current
com.twitter.util.Local for the given function f
.
Unset the value of this flag, such that isDefined will return false
,
only for the scope of the current com.twitter.util.Local for the
given function f
.
Unset the value of this flag, such that isDefined will return false
,
only for the scope of the current com.twitter.util.Local for the
given function f
.
The "name", or "id", of this Flag.
The "name", or "id", of this Flag.
While not marked final
, if a subclass overrides this value, then
developers must set that flag via System properties as otherwise it
will not be recognized with command-line arguments.
e.g. -DyourGlobalFlagName=flagName
Indicates whether or not the flag is valid without an argument.
Indicates whether or not the flag is valid without an argument.
Parse this flag with no argument.
Parse this flag with no argument.
Parse value raw
into this flag.
Parse value raw
into this flag.
Reset this flag's value
Reset this flag's value
String representation of this flag in -foo='bar' format, suitable for being used on the command line.
String representation of this flag in -foo='bar' format, suitable for being used on the command line.