Jkube: Use `Map.computeIfAbsent` wherever applicable across codebase

Created on 9 Feb 2021  路  1Comment  路  Source: eclipse/jkube

We have a few places in our code where we check whether a value exists in a Map and then we perform some sort of operation to put the value inside that map. For example:

https://github.com/eclipse/jkube/blob/a70b19b6776f4e0c570053cc38913e031db4b0df/jkube-kit/common/src/main/java/org/eclipse/jkube/kit/common/util/OpenshiftHelper.java#L136-L140

This can be simplified like this:

       String key = entry.getKey();
       String value = entry.getValue();
       annotations.computeIfAbsent(key, s -> value);

According to Sonar, there are a few other places[0] across the codebase too which we can refactor to use Map.computeIfAbsent. I think we should refactor these to make use of features available by the Java 8 API.

[0] https://sonarcloud.io/organizations/jkubeio/issues?resolved=false&rules=java%3AS3824

good first issue help wanted

Most helpful comment

Hi, I'd like to resolve this issue, I've created a fork in my repository, could you assign this issue to me?

>All comments

Hi, I'd like to resolve this issue, I've created a fork in my repository, could you assign this issue to me?

Was this page helpful?
0 / 5 - 0 ratings