Add OptionalUtil to Java util - #2464
Conversation
| @@ -0,0 +1,64 @@ | |||
| /* | |||
There was a problem hiding this comment.
Note that even though this is technically a new file, the code is copied from https://github.com/apache/pekko-http/blob/4833a8e42f946682a72a72a0f3bee4c4d662b9a6/http-core/src/main/java/org/apache/pekko/http/impl/util/Util.java so we still need to use the lightbend header
003e05d to
61f33c7
Compare
pjfanning
left a comment
There was a problem hiding this comment.
seems generally ok but a couple of regression tests would be useful
Regression tests would be pointless due to how trivial the code is and also its case of if it compiles then it works, its just that I have split this PR out of the main work I am doing as part of zstd. We know that this code works as it was directly copied from pekko-http and its working locally with my zstd work To put it differently, once other code starts using this code we know it will work because of that other work being able to compile. If someone changes the code in this PR to create a regression, than that other code that are using these utils will no longer compile. |
|
Thanks for the review, I created apache/pekko-http#869 as a reminder so that we use these methods in pekko-http once it starts depending on pekko 2.0.0-M1 milestone |
When working on #2409 I needed to convert from Java
OptionalIntto ScalaOption[Int]and I realized that due to Java Optional being invariant and Scala'sIntbeing a subclass of Java'sIntegeryou need some boilerplate in order convert from one to the other.This boilerplate already lives in pekko-http since pekko-http already has this issue (see https://github.com/apache/pekko-http/blob/4833a8e42f946682a72a72a0f3bee4c4d662b9a6/http-core/src/main/java/org/apache/pekko/http/impl/util/Util.java) so this PR moves that code from pekko-http to pekko (since this will be the first time we need to use this code in pekko core).
Once 2.0.0-M1 will be published then we can change pekko-http 2.0.0 to use this code.