Skip to content

Consider the feed method returning T or Optional #18

@gstamatelat

Description

@gstamatelat

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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions