I am using hashmap, but it is not working correctly. I have a class Computing.java, where I have method for adding into hashmap:
addIntoMap(String key, String value){
m_parameters_values.put(key, value);
}
and method for get from hashmap:
public void getValueByKey(String key){
System.out.println("GET "+m_parameters_values.get(key));
}
I am calling theese methods from Main class, but I am not able to be able to get keys, I am still getting null. Do you know why?
Content of class computing (constructors omitted):
public void Parse (String args[]) throws Exception{
Parse(args,true);
}
public void Parse(String[] args, boolean throwErrorIfParamenterNotDefined) throws CmdLineException
{
int i = 0;
while (i < args.length)
{
// The current string is a parameter name
String key = args[i].substring(1, args[i].length() - 1).toLowerCase();
String value = "";
i++;
if (i < args.length)
{
if (args[i].length() > 0 && args[i] == "-")
{
// The next string is a new parameter, do not nothing
} else
{
// The next string is a value, read the value and move forward
value = args[i];
i++;
}
}
if (!m_parameters.containsKey(key))
{
if (throwErrorIfParamenterNotDefined)
{
//throw new CmdLineException("Parameter is not allowed.");
}
//continue;
}
System.out.println("Key: "+key+" value: "+value);
m_parameters_values.put(key, value);
//System.out.println("GET "+m_parameters_values.get("provider"));
}
// Check that required parameters are present in the command line.
for (String key : m_parameters.keySet())
{
if (m_parameters.get(key).required() && !m_parameters.get(key).exists())
throw new CmdLineException("Required parameter is not found.");
}
}
public void getValueByKey(String key){
System.out.println("GET "+m_parameters_values.get(key));
}
Content of main class:
public static void main(String[] args) {
Computing comp = new Computing("Computing");
cmdLine.Parse(args);
cmdLine.getValueByKey("convert");
print
valueused inputmethod.Acc. to javadoc:
To be sure, use
containsKeymethod to verify ifkeyreally exists.use following code in
getValueByKey; and see if it prints anything: