Life is an amazing experience to behold at times. Other times it can be a bit of a nightmare. I guess it all depends on the day, now doesn’t it? Yeah, something like that. Who knows what this life will bring about. I for one don’t know. That’s the big secret behind this life I suppose. But life doesn’t have to be mysterious. Trying to figure out how this life work sat times- can be a nightmare. However all is not lost if you can have hope in something that will make life that much better. If we constantly allow our own thoughts and feelings to fight against us, we will never be better than we currently are. It’s easier said than done naturally. I am my own worst enemy, my worst critic. That’s simply how this life treats me at times. Not much else to comment about that. Am I playing the victim or simply stating the facts? Who can say for sure? I personally feel I’m just telling it like it is, nothing more. Sometimes I can’t determine my own thoughts from that of psychosis . Parts o...
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