public final class ParameterTool
extends java.lang.Object
implements java.io.Serializable, java.lang.Cloneable
Modifier and Type | Field and Description |
---|---|
protected java.util.Map<java.lang.String,java.lang.String> |
data |
protected static java.lang.String |
DEFAULT_UNDEFINED |
protected java.util.Map<java.lang.String,java.lang.String> |
defaultData |
protected static java.lang.String |
NO_VALUE_KEY |
protected java.util.Set<java.lang.String> |
unrequestedParameters |
Modifier and Type | Method and Description |
---|---|
protected void |
addToDefaults(java.lang.String key,
java.lang.String value) |
static <T> T |
checkNotNull(T reference,
java.lang.String errorMessage) |
void |
createPropertiesFile(java.lang.String pathToFile)
Create a properties file with all the known parameters (call after the last get*() call).
|
void |
createPropertiesFile(java.lang.String pathToFile,
boolean overwrite)
Create a properties file with all the known parameters (call after the last get*() call).
|
boolean |
equals(java.lang.Object o) |
static ParameterTool |
fromArgs(java.lang.String[] args)
Returns
ParameterTool for the given arguments. |
static ParameterTool |
fromMap(java.util.Map<java.lang.String,java.lang.String> map)
Returns
ParameterTool for the given map. |
static ParameterTool |
fromPropertiesFile(java.io.File file)
Returns
ParameterTool for the given Properties file. |
static ParameterTool |
fromPropertiesFile(java.io.InputStream inputStream)
Returns
ParameterTool for the given InputStream from Properties file. |
static ParameterTool |
fromPropertiesFile(java.lang.String path)
Returns
ParameterTool for the given Properties file. |
static ParameterTool |
fromSystemProperties()
Returns
ParameterTool from the system properties. |
java.lang.String |
get(java.lang.String key)
Returns the String value for the given key.
|
java.lang.String |
get(java.lang.String key,
java.lang.String defaultValue)
Returns the String value for the given key.
|
boolean |
getBoolean(java.lang.String key)
Returns the Boolean value for the given key.
|
boolean |
getBoolean(java.lang.String key,
boolean defaultValue)
Returns the Boolean value for the given key.
|
byte |
getByte(java.lang.String key)
Returns the Byte value for the given key.
|
byte |
getByte(java.lang.String key,
byte defaultValue)
Returns the Byte value for the given key.
|
JobConfig |
getConfiguration() |
double |
getDouble(java.lang.String key)
Returns the Double value for the given key.
|
double |
getDouble(java.lang.String key,
double defaultValue)
Returns the Double value for the given key.
|
float |
getFloat(java.lang.String key)
Returns the Float value for the given key.
|
float |
getFloat(java.lang.String key,
float defaultValue)
Returns the Float value for the given key.
|
int |
getInt(java.lang.String key)
Returns the Integer value for the given key.
|
int |
getInt(java.lang.String key,
int defaultValue)
Returns the Integer value for the given key.
|
long |
getLong(java.lang.String key)
Returns the Long value for the given key.
|
long |
getLong(java.lang.String key,
long defaultValue)
Returns the Long value for the given key.
|
int |
getNumberOfParameters()
Returns number of parameters in
ParameterTool . |
java.util.Properties |
getProperties()
Returns a
Properties object from this ParameterTool . |
java.lang.String |
getRequired(java.lang.String key)
Returns the String value for the given key.
|
short |
getShort(java.lang.String key)
Returns the Short value for the given key.
|
short |
getShort(java.lang.String key,
short defaultValue)
Returns the Short value for the given key.
|
java.util.Set<java.lang.String> |
getUnrequestedParameters()
Returns the set of parameter names which have not been requested with
has(String) or one of the get methods. |
boolean |
has(java.lang.String value)
Check if value is set.
|
int |
hashCode() |
ParameterTool |
mergeWith(ParameterTool other)
Merges two
ParameterTool . |
java.util.Map<java.lang.String,java.lang.String> |
toMap() |
protected static final java.lang.String NO_VALUE_KEY
protected static final java.lang.String DEFAULT_UNDEFINED
protected final java.util.Map<java.lang.String,java.lang.String> data
protected transient java.util.Map<java.lang.String,java.lang.String> defaultData
protected transient java.util.Set<java.lang.String> unrequestedParameters
public static ParameterTool fromArgs(java.lang.String[] args)
ParameterTool
for the given arguments. The arguments are keys followed by values.
Keys have to start with '-' or '--'
Example arguments: --key1 value1 --key2 value2 -key3 value3
args
- Input array argumentsParameterTool
public static ParameterTool fromPropertiesFile(java.lang.String path) throws java.io.IOException
ParameterTool
for the given Properties
file.path
- Path to the properties fileParameterTool
java.io.IOException
- If the file does not existProperties
public static ParameterTool fromPropertiesFile(java.io.File file) throws java.io.IOException
ParameterTool
for the given Properties
file.file
- File object to the properties fileParameterTool
java.io.IOException
- If the file does not existProperties
public static ParameterTool fromPropertiesFile(java.io.InputStream inputStream) throws java.io.IOException
ParameterTool
for the given InputStream from Properties
file.inputStream
- InputStream from the properties fileParameterTool
java.io.IOException
- If the file does not existProperties
public static <T> T checkNotNull(T reference, java.lang.String errorMessage)
public static ParameterTool fromMap(java.util.Map<java.lang.String,java.lang.String> map)
ParameterTool
for the given map.map
- A map of arguments. Both Key and Value have to be StringsParameterTool
public static ParameterTool fromSystemProperties()
ParameterTool
from the system properties.
Example on how to pass system properties:
-Dkey1=value1 -Dkey2=value2ParameterTool
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public java.util.Set<java.lang.String> getUnrequestedParameters()
has(String)
or one of the get
methods. Access to the
map returned by toMap()
is not tracked.public int getNumberOfParameters()
ParameterTool
.public java.lang.String get(java.lang.String key)
public java.lang.String getRequired(java.lang.String key)
RuntimeException
.public java.lang.String get(java.lang.String key, java.lang.String defaultValue)
public boolean has(java.lang.String value)
public int getInt(java.lang.String key)
public int getInt(java.lang.String key, int defaultValue)
public long getLong(java.lang.String key)
public long getLong(java.lang.String key, long defaultValue)
public float getFloat(java.lang.String key)
public float getFloat(java.lang.String key, float defaultValue)
public double getDouble(java.lang.String key)
public double getDouble(java.lang.String key, double defaultValue)
public boolean getBoolean(java.lang.String key)
public boolean getBoolean(java.lang.String key, boolean defaultValue)
public short getShort(java.lang.String key)
public short getShort(java.lang.String key, short defaultValue)
public byte getByte(java.lang.String key)
public byte getByte(java.lang.String key, byte defaultValue)
protected void addToDefaults(java.lang.String key, java.lang.String value)
public JobConfig getConfiguration()
public java.util.Properties getProperties()
Properties
object from this ParameterTool
.Properties
public void createPropertiesFile(java.lang.String pathToFile) throws java.io.IOException
Use this method to create a properties file skeleton.
pathToFile
- Location of the default properties file.java.io.IOException
public void createPropertiesFile(java.lang.String pathToFile, boolean overwrite) throws java.io.IOException
pathToFile
- Location of the default properties file.overwrite
- Boolean flag indicating whether or not to overwrite the filejava.io.IOException
- If overwrite is not allowed and the file existspublic ParameterTool mergeWith(ParameterTool other)
ParameterTool
.other
- Other ParameterTool
objectParameterTool
public java.util.Map<java.lang.String,java.lang.String> toMap()