Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider the feed method returning T or Optional #18

Open
gstamatelat opened this issue Jul 1, 2018 · 0 comments
Open

Consider the feed method returning T or Optional #18

gstamatelat opened this issue Jul 1, 2018 · 0 comments

Comments

@gstamatelat
Copy link
Owner

gstamatelat commented Jul 1, 2018

Idea 1

T feed(T item) returns the element T of the reservoir that was replaced by item or null if the sample was not modified as a result of this operation.

Idea 2

A new feed method has to return values from 3 different cases:

  1. item was not selected and there was no change in the sample (return null)
  2. item was inserted in the sample but nothing was removed (return null?)
  3. item replaced an existing item T of the sample (return T)

An obvious solution is to return Optional<T>:

Optional<T> feed(T item) returns null in case (1), an Optional<T> that doesn't hold a value in case (2) and an Optional<T> that holds the reference to the item that was removed in case (3).

@gstamatelat gstamatelat changed the title Consider the feed method returning T Consider the feed method returning T or Optional Jul 1, 2018
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

No branches or pull requests

1 participant