What Happened Kyle Eggleston Doesn’t make sense most days. What exactly happened? I don’t get it. I don’t understand any of it. Am I supposed to understand all of it? A piece of it? Portions? I’m feeling emotions and I don’t understand why I’m feeling these different emotions. I’d rather not speculate at all, but well what am I supposed to do about it all? I don’t get it. I wish I understood everything that was happening lately. I don’t.
I found the code I was looking for:
static class Args {
public static Map<String, List<String>> parseArgs(String[] args, Set<String> validArgs) {
Map<String, List<String>> map = new HashMap<>();
List<String> options = null;
for (String a : args) {
if (a.charAt(0) == '-') {
if (a.length() < 2) {
throw new IllegalArgumentException("Invalid Argument: " + a);
}
if (!validArgs.contains(a)) {
throw new IllegalArgumentException("Invalid Argument: " + a);
}
options = new ArrayList<>();
map.put(a, options);
} else if (options != null) {
options.add(a);
} else {
throw new IllegalArgumentException("Invalid Argument: " + a);
}
}
return map;
}
}
I've modified this piece of code then was in the original post. You can pass this a Set of Strings that ensure only the correct proper argumetns are being passed into the program as to not waste the programs time trying to decide if they are proper later.
Comments
Post a Comment