Skip to content

Conversation

ctrimble
Copy link
Contributor

@ctrimble ctrimble commented Aug 21, 2025

This PR adds the streaming methods found on java.util.Optional to the JsonNullable type.

Methods added:

  • isUndefined()
  • orElseGet(Supplier)
  • orElseThrow()
  • orElseThrow(Supplier)
  • ifPresentOrElse(Supplier, Runnable)
  • filter(Predicate)
  • map(Function)
  • flatMap(Function)
  • or(Supplier)
  • stream()

Fixes #7.
Fixes #65.

@ctrimble ctrimble marked this pull request as draft August 21, 2025 10:15
@ctrimble ctrimble force-pushed the feature_streaming-methods branch 3 times, most recently from ae3d143 to 1098000 Compare August 21, 2025 10:37
@ctrimble ctrimble marked this pull request as ready for review August 21, 2025 11:46
@ctrimble ctrimble force-pushed the feature_streaming-methods branch 2 times, most recently from 86946b7 to 50481b5 Compare August 21, 2025 19:58
@ctrimble
Copy link
Contributor Author

@wing328 any thoughts on this or other changes like this that improve the interface on JsonNullable?

@wing328
Copy link
Member

wing328 commented Sep 9, 2025

Thanks for the PR and sorry for late reply,.

We're looking for maintainers: #71

Let me know if you're interesting in maintaining this project. Thank you.

Copy link
Contributor

@Til7701 Til7701 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR. This looks great. There are two small suggestions.

*
* @since 0.2.8
*/
public JsonNullable<T> filter( Predicate<T> predicate ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method seems to be indented with two spaces instead of four.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be fixed. Is 4 spaces the project standard? Should I fix the indenting on the test as well?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don’t know off hand. You could probably just check a few existing files and match whatever they have. I’m not aware of anything enforcing it, so it’s possible there’s already a mix.

For existing files, match whatever that file uses. For new files, match the project standard (if it exists).

@@ -0,0 +1,421 @@
/*
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn’t notice the copyright in any other files (maybe I missed some).

Are you ok with removing this? I don’t exactly know the difference whether you add this or not though. I assume you’re the copyright holder either way. (…I’m not a lawyer though, so I could be completely wrong.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can drop this, if it makes things better for the project.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly, I just don't know the implications. @wing328 might be able to provide some guidance?

Copy link
Contributor

@nrayburn-tech nrayburn-tech left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly minor changes. If you aren't able to get to these, let us know and we can create a new PR with the required changes.

@ctrimble
Copy link
Contributor Author

I think I have time to get to these changes tonight.

@nrayburn-tech
Copy link
Contributor

Sounds good to me.

Can you add the below to the PR description? It will automatically close out some of the other issues when this PR gets merged in.

Fixes #7.
Fixes #65.

@ctrimble
Copy link
Contributor Author

@nrayburn-tech I haven't made the changes yet, but there is now testing that shows exactly where this implementation does not match an equivalent call on Optional. The build will skip comparisons with Optional methods that are not present in the current JDK. Building with Java 17 will show all the issues.

The following all need NullPointerExceptions:

  • filter null predicate on undefined
  • flatMap null predicate on undefined
  • map null mapping on undefined
  • or null supplier on value
  • or null supplier on null

I am going to rework testing of ifPresentOrElse to make sure that is consistent as well.

@ctrimble
Copy link
Contributor Author

@nrayburn-tech I think I have the changes you asked for completed.

Items still open:

  • The license header on StreamingApiTest
  • Should I update the indent to 4 spaces on StreamingApiTest?

I would like to squash this history down and get rebased on master (it looks like the pom.xml cannot merge) before this gets accepted.

@nrayburn-tech
Copy link
Contributor

After you merge in master, you’ll want to update your pom changes to match the existing format.

Use a property for the version.
Put the dependencies within the test region comment.

@ctrimble
Copy link
Contributor Author

@nrayburn-tech the project moved to JUnit 5 while this PR was open. I will have to rework the testing annotations.

found in java.util.Optional.

- isUndefined()
- orElseGet(Supplier)
- orElseThrow()
- orElseThrow(Supplier)
- ifPresentOrElse(Supplier, Runnable)
- filter(Predicate)
- map(Function)
- flatMap(Function)
- or(Supplier)
- stream()
@ctrimble ctrimble force-pushed the feature_streaming-methods branch from b2b3080 to fbafe0f Compare September 28, 2025 18:42
@ctrimble
Copy link
Contributor Author

@nrayburn-tech the tests for this are now reworked and history is squashed down. I still need to deal with this license header and possible indentation issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add map and flatmap methods New Method isUndefined
4 participants