You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
item was not selected and there was no change in the sample (return null)
item was inserted in the sample but nothing was removed (return null?)
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).
The text was updated successfully, but these errors were encountered:
gstamatelat
changed the title
Consider the feed method returning T
Consider the feed method returning T or Optional
Jul 1, 2018
Idea 1
T feed(T item)
returns the elementT
of the reservoir that was replaced byitem
ornull
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:item
was not selected and there was no change in the sample (returnnull
)item
was inserted in the sample but nothing was removed (returnnull
?)item
replaced an existing itemT
of the sample (returnT
)An obvious solution is to return
Optional<T>
:Optional<T> feed(T item)
returnsnull
in case (1), anOptional<T>
that doesn't hold a value in case (2) and anOptional<T>
that holds the reference to the item that was removed in case (3).The text was updated successfully, but these errors were encountered: