public class FlagType extends BolType implements FlaggableType<Boolean>
This would be used to parse a command line argument that is true by its presence, e.g.:
java MyClass launch
If launch is an AndHow property using the FlagType (i.e. FlagProp), launch will
be considered true just by its presence.
This class is threadsafe and uses a singleton pattern to prevent multiple instances since all users can safely use the same instance.
clazzType| Modifier | Constructor and Description |
|---|---|
protected |
FlagType() |
| Modifier and Type | Method and Description |
|---|---|
static FlagType |
instance()
Fetch the single, shared instance of this ValueType
|
Boolean |
parseFlag(String sourceValue)
Attempts to parse the passed String into the destination type with flag semantics.
|
getDestinationType, toStringclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitcast, getDestinationType, parse, toStringpublic static FlagType instance()
FlagType()public Boolean parseFlag(String sourceValue) throws ParsingException
FlaggableType
This method behaves as ValueType.parse(String), but with these differences:
FlagProp for an example.ValueType.toString(Object)
This method should only be called by loaders that support Flags. For instance, loading a
non-null value from the properties file entry 'name = ' would be unexpected,
so a properties file loader should use the 'parse' method. However, a command line loader
would be expected to support flags, so could call this method instead of 'parse'.
This method may still throw a ParsingException, since non-null values may still be parsed.
As with ValueType.parse(String), all trimming (removing whitespace from around a value) should
be assumed to already have happened for the incoming sourceValue.
Implementations should be careful to ONLY throw a ParsingException - Integers and other types may throw other unchecked exceptions when trying to convert values, which should be handled in this method and rethrown as a ParsingException.
parseFlag in interface FlaggableType<Boolean>ParsingException - for any type of failure.Copyright © 2022. All rights reserved.