Skip to content

Use computeIfAbsent in CommandLineArgs.addOptionArg#36493

Open
junhyung8795 wants to merge 1 commit intospring-projects:mainfrom
junhyung8795:refactor/use-compute-if-absent
Open

Use computeIfAbsent in CommandLineArgs.addOptionArg#36493
junhyung8795 wants to merge 1 commit intospring-projects:mainfrom
junhyung8795:refactor/use-compute-if-absent

Conversation

@junhyung8795
Copy link
Contributor

Replace the manual containsKey/put/get three-step pattern in
CommandLineArgs.addOptionArg with Map.computeIfAbsent, which expresses
the same intent more concisely and avoids the redundant second map lookup.

Before:

if (!this.optionArgs.containsKey(optionName)) {
    this.optionArgs.put(optionName, new ArrayList<>());
}
if (optionValue != null) {
    this.optionArgs.get(optionName).add(optionValue);
}

After:

List<String> values = this.optionArgs.computeIfAbsent(optionName, key -> new ArrayList<>());
if (optionValue != null) {
    values.add(optionValue);
}

Behavior is identical: the option name is always registered in the map (even
without a value), and the value is added only when non-null.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Mar 18, 2026
@bclozel
Copy link
Member

bclozel commented Mar 18, 2026

Please sign the DCO.

@bclozel bclozel added the status: waiting-for-feedback We need additional information before we can continue label Mar 18, 2026
Signed-off-by: junhyung8795 <junhyung8795@naver.com>
@junhyung8795 junhyung8795 force-pushed the refactor/use-compute-if-absent branch from a1d3e5b to 10d1ad3 Compare March 18, 2026 13:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: waiting-for-feedback We need additional information before we can continue status: waiting-for-triage An issue we've not yet triaged or decided on

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants