ParameterTool extends ExecutionConfig.GlobalJobParameters implements Serializable, Cloneable { public static ParameterTool fromArgs(String[] args) { Map<String, String> map = new HashMap<String, String>(args.length / 2); String key = null; String value = null; boolean expectValue = false; for (String arg : args) { if (arg.startsWith("--")) { if (expectValue) { if (value != null) { throw new IllegalStateException("Unexpected state"); } map.put(key, NO_VALUE_KEY); } key = arg.substring(2); expectValue = true; } else if (arg.startsWith("-")) { if (expectValue) { if (NumberUtils.isNumber(arg)) { value = arg; expectValue = false; } else { if (value != null) { throw new IllegalStateException("Unexpected state"); } map.put(key, NO_VALUE_KEY); key = arg.substring(1); expectValue = true; } } else { key = arg.substring(1); expectValue = true; } } else { if (expectValue) { value = arg; expectValue = false; } else { throw new RuntimeException("Error parsing arguments '" + Arrays.toString(args) + "' on '" + arg + "'. Unexpected value. Please prefix values with -- or -."); } } if (value == null && key == null) { throw new IllegalStateException("Value and key can not be null at the same time"); } if (key != null && value == null && !expectValue) { throw new IllegalStateException("Value expected but flag not set"); } if (key != null && value != null) { map.put(key, value); key = null; value = null; expectValue = false; } if (key != null && key.length() == 0) { throw new IllegalArgumentException("The input " + Arrays.toString(args) + " contains an empty argument"); } if (key != null && !expectValue) { map.put(key, NO_VALUE_KEY); key = null; expectValue = false; } } if (key != null) { map.put(key, NO_VALUE_KEY); } return fromMap(map); } private  ParameterTool(Map<String, String> data); static ParameterTool fromArgs(String[] args); static ParameterTool fromPropertiesFile(String path); static ParameterTool fromPropertiesFile(File file); static ParameterTool fromPropertiesFile(InputStream inputStream); static ParameterTool fromMap(Map<String, String> map); static ParameterTool fromSystemProperties(); @Override boolean equals(Object o); @Override int hashCode(); @PublicEvolving Set<String> getUnrequestedParameters(); int getNumberOfParameters(); String get(String key); String getRequired(String key); String get(String key, String defaultValue); boolean has(String value); int getInt(String key); int getInt(String key, int defaultValue); long getLong(String key); long getLong(String key, long defaultValue); float getFloat(String key); float getFloat(String key, float defaultValue); double getDouble(String key); double getDouble(String key, double defaultValue); boolean getBoolean(String key); boolean getBoolean(String key, boolean defaultValue); short getShort(String key); short getShort(String key, short defaultValue); byte getByte(String key); byte getByte(String key, byte defaultValue); Configuration getConfiguration(); Properties getProperties(); void createPropertiesFile(String pathToFile); void createPropertiesFile(String pathToFile, boolean overwrite); ParameterTool mergeWith(ParameterTool other); @Override Map<String, String> toMap();  }
@Test(expected = RuntimeException.class) public void testIllegalArgs() { ParameterTool.fromArgs(new String[]{"berlin"}); }
@Test(expected = IllegalArgumentException.class) public void testEmptyVal() { ParameterTool.fromArgs(new String[]{"--a", "-b", "--"}); }
@Test(expected = IllegalArgumentException.class) public void testEmptyValShort() { ParameterTool.fromArgs(new String[]{"--a", "-b", "-"}); }