So…last night, when I was in bed. I kept hearing a voice. I can’t remember what it was saying, but I do remember it getting madder as I was yelling at it to stop. I just wanted the damn voice to stop, and I couldn’t make it stop! Oh man that was annoying, so very annoying that it wouldn’t stop and I couldn’t make it stop. Life feels so difficult at times with these voices doing whatever the hell they want to do in my head. I can’t seem to shake them. Maybe I need to be put on a different medication? I’m not sure. I just want to feel normal, whatever normal is. I’m not even sure I know what normal is now! Talk about a nightmare. A living nightmare that I cannot control in any way, shape, or form. I want it to end somehow. I don’t even know how to make that possible.
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