@Public public class ParameterTool extends ExecutionConfig.GlobalJobParameters implements Serializable, Cloneable
Modifier and Type | Field and Description |
---|---|
protected Map<String,String> |
data |
protected static String |
DEFAULT_UNDEFINED |
protected HashMap<String,String> |
defaultData |
protected static String |
NO_VALUE_KEY |
Modifier and Type | Method and Description |
---|---|
protected void |
addToDefaults(String key,
String value) |
protected Object |
clone() |
void |
createPropertiesFile(String pathToFile)
Create a properties file with all the known parameters (call after the last get*() call).
|
void |
createPropertiesFile(String pathToFile,
boolean overwrite)
Create a properties file with all the known parameters (call after the last get*() call).
|
static ParameterTool |
fromArgs(String[] args)
Returns
ParameterTool for the given arguments. |
static ParameterTool |
fromGenericOptionsParser(String[] args)
Returns
ParameterTool for the arguments parsed by GenericOptionsParser |
static ParameterTool |
fromMap(Map<String,String> map)
Returns
ParameterTool for the given map |
static ParameterTool |
fromPropertiesFile(String path)
Returns
ParameterTool for the given Properties file |
static ParameterTool |
fromSystemProperties()
Returns
ParameterTool from the system properties. |
String |
get(String key)
Returns the String value for the given key.
|
String |
get(String key,
String defaultValue)
Returns the String value for the given key.
|
boolean |
getBoolean(String key)
Returns the Boolean value for the given key.
|
boolean |
getBoolean(String key,
boolean defaultValue)
Returns the Boolean value for the given key.
|
byte |
getByte(String key)
Returns the Byte value for the given key.
|
byte |
getByte(String key,
byte defaultValue)
Returns the Byte value for the given key.
|
Configuration |
getConfiguration()
Returns a
Configuration object from this ParameterTool |
double |
getDouble(String key)
Returns the Double value for the given key.
|
double |
getDouble(String key,
double defaultValue)
Returns the Double value for the given key.
|
float |
getFloat(String key)
Returns the Float value for the given key.
|
float |
getFloat(String key,
float defaultValue)
Returns the Float value for the given key.
|
int |
getInt(String key)
Returns the Integer value for the given key.
|
int |
getInt(String key,
int defaultValue)
Returns the Integer value for the given key.
|
long |
getLong(String key)
Returns the Long value for the given key.
|
long |
getLong(String key,
long defaultValue)
Returns the Long value for the given key.
|
int |
getNumberOfParameters()
Returns number of parameters in
ParameterTool . |
Properties |
getProperties()
Returns a
Properties object from this ParameterTool |
String |
getRequired(String key)
Returns the String value for the given key.
|
short |
getShort(String key)
Returns the Short value for the given key.
|
short |
getShort(String key,
short defaultValue)
Returns the Short value for the given key.
|
boolean |
has(String value)
Check if value is set.
|
ParameterTool |
mergeWith(ParameterTool other)
Merges two
ParameterTool |
Map<String,String> |
toMap()
Convert UserConfig into a
Map<String, String> representation. |
protected static String NO_VALUE_KEY
protected static String DEFAULT_UNDEFINED
public static ParameterTool fromArgs(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(String path) throws IOException
ParameterTool
for the given Properties
filepath
- Path to the properties fileParameterTool
IOException
- If the file does not existProperties
public static ParameterTool fromMap(Map<String,String> map)
ParameterTool
for the given mapmap
- 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
@PublicEvolving public static ParameterTool fromGenericOptionsParser(String[] args) throws IOException
ParameterTool
for the arguments parsed by GenericOptionsParser
args
- Input array arguments. It should be parsable by GenericOptionsParser
ParameterTool
IOException
- If arguments cannot be parsed by GenericOptionsParser
GenericOptionsParser
public int getNumberOfParameters()
ParameterTool
.public String get(String key)
public String getRequired(String key)
RuntimeException
.public String get(String key, String defaultValue)
public boolean has(String value)
public int getInt(String key)
public int getInt(String key, int defaultValue)
public long getLong(String key)
public long getLong(String key, long defaultValue)
public float getFloat(String key)
public float getFloat(String key, float defaultValue)
public double getDouble(String key)
public double getDouble(String key, double defaultValue)
public boolean getBoolean(String key)
public boolean getBoolean(String key, boolean defaultValue)
public short getShort(String key)
public short getShort(String key, short defaultValue)
public byte getByte(String key)
public byte getByte(String key, byte defaultValue)
public Configuration getConfiguration()
Configuration
object from this ParameterTool
Configuration
public Properties getProperties()
Properties
object from this ParameterTool
Properties
public void createPropertiesFile(String pathToFile) throws IOException
pathToFile
- Location of the default properties file.IOException
public void createPropertiesFile(String pathToFile, boolean overwrite) throws IOException
pathToFile
- Location of the default properties file.overwrite
- Boolean flag indicating whether or not to overwrite the fileIOException
- If overwrite is not allowed and the file existsprotected Object clone() throws CloneNotSupportedException
clone
in class Object
CloneNotSupportedException
public ParameterTool mergeWith(ParameterTool other)
ParameterTool
other
- Other ParameterTool
objectParameterTool
public Map<String,String> toMap()
ExecutionConfig.GlobalJobParameters
Map<String, String>
representation.
This can be used by the runtime, for example for presenting the user config in the web frontend.toMap
in class ExecutionConfig.GlobalJobParameters
Copyright © 2014–2017 The Apache Software Foundation. All rights reserved.