I did something similar some time ago. The idea is nice but it was abandoned due to performance drawbacks as streams are quite slower than regular iteration. Anyway, this is what I did

https://github.com/apache/wicket/commit/73ac8c7e6da3ff9dd0244ad66c63944ba3d64c78


On 12/11/2016 17:56, Martijn Dashorst wrote:
In our code I often see code that (ugh) retrieves a component by id,
something like:

public class SomePanel extends Panel {
     ...
        target.add(getPage().get("feedback"));
     ...
}

If we made MarkupContainer streamable, we could, in pseudo code, do
something like:

getPage().stream().filter(c->c.getId().equals("feedback")).findFirst();

Which is not better than getPage().get("feedback")

But it is more flexible checking for types, etc.

The implementation is not that complicated:


/**
  * Returns a sequential {@code Stream} with the children of this
markup container
  *  as its source.
  *
  * @return a sequential {@code Stream} over the children of this
markup container
  * @since 8.0
  */
public Stream<Component> stream()
{
     return StreamSupport.stream(spliterator(), false);
}

Good idea?

Martijn

Reply via email to