Mon Jun 22 01:04:57 UTC 2026 Ah, a brand mew day is here! This I can handle. I didn’t hear from the kids, kinda expected that. I never hear from them on Father’s Day. It’s whatever. I deal with it and move on is all. Nothing big. Nothing major. Nothing too crazy. I really shouldn’t be surprised by any of this. I mean it is what it is. I know I can call them but they’re probably celebrating that other man who they call Dad. Gah! I hate overthinking this. It’s like this every year. I need to stop thinking about it. That’s all there is to it! Mon Jun 22 08:10:05 AM MDT 2026 Welp! Back to work I go. Doesn’t mean it’s not useful of course, work is a good thing at times. I wonder how it all would go down if there wasn’t work? I mean that could be kind crazy right? Yeah, that’s what I’m thinking! Well, the kids did eventually call last night, around 10 PM. They didn’t have much to say. They never do. They never know what they’re doing or are up to. It can be frustrating at times. Maybe ...
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