RFR: 1256: Use stream api to simplify the csr issue lookup [v2]

Guoxiong Li gli at openjdk.java.net
Wed Dec 1 08:04:38 UTC 2021

On Tue, 30 Nov 2021 23:18:25 GMT, Erik Joelsson <erikj at openjdk.org> wrote:

>> Guoxiong Li has updated the pull request incrementally with one additional commit since the last revision:
>>   Use stream api instead of the encapsulated method.
> bots/pr/src/main/java/org/openjdk/skara/bots/pr/CSRCommand.java line 165:
>> 163:         }
>> 164: 
>> 165:         var csr = jbsIssue.get().links().stream()
> This particular pattern now occurs twice in this file. Perhaps worth moving to a private method at least, to reduce some duplication.


> bots/pr/src/main/java/org/openjdk/skara/bots/pr/CheckRun.java line 142:
>> 140:                 .filter(link -> link.relationship().isPresent() && "csr for".equals(link.relationship().get()))
>> 141:                 .findAny().flatMap(Link::issue).orElse(null);
>> 142:         if (csr == null) {
> I just noticed this pattern being used a lot. Instead of .orElse(null), I would prefer if you let `csr` be an optional and used `csr.isPresent()` in the if statement. You will then need to use `csr.get()` to actually get the value, but this is safe as it's protected by the condition on isPresent(). If the variable in question is used a lot, you can choose resolve it with .get() into a new variable at the top of the if/else block.
> This applies to several places where the same pattern is used.



PR: https://git.openjdk.java.net/skara/pull/1248

More information about the skara-dev mailing list