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

use stream api instead of Iterables utility class #3250

Open
wants to merge 20 commits into
base: master
Choose a base branch
from

Conversation

Outfluencer
Copy link
Collaborator

The Guava developers want us to migrate to the Stream Library, which they tell us in the Iterables class documentation

return ProxyServer.getInstance().getPlayers().stream()
.map( player -> player.getName() )
.filter( name -> name.toLowerCase( Locale.ROOT ).startsWith( lastArg ) )
.collect( Collectors.toList() );
Copy link
Member

Choose a reason for hiding this comment

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

This is actually worse than Guava because Iterables.transform and ilk are lazy, this is not.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't understand the problem here i need to check the full player list. I can't do less, what should i do instead

Copy link
Contributor

Choose a reason for hiding this comment

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

This might help you create an Iterable result without creating an ArrayList instance:
https://stackoverflow.com/questions/59869486/how-can-i-turn-a-stream-into-an-iterable

Copy link
Member

Choose a reason for hiding this comment

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

Guava doesn't make an ArrayList. You do. Making an ArrayList is unecessarily slow. The Guava code can of course be lambdafied, but overall it is a better implementation (even than what Black-Hole linked which is hacky).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

i think i found a nice way

using the stream iterator as the iterator() of a new Iterable
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.

3 participants