while (i < args.length) {
String item = args[i];
if (option.equals(item)) {
if ((i + 1) >= args.length) {
throw new InvalidArgumentsException("Parameter " + option + " was malformed.");
} else {
if (result != null) {
throw new InvalidArgumentsException("Parameter " + option + " was found more than once.");
} else {
result = args[++i];
}
}
}
i += 1;
}
}
if (result == null) {
throw new InvalidArgumentsException("Parameter " + option + " was not found");
}
return result;
}