-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
base: master
Are you sure you want to change the base?
Conversation
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() ); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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
proxy/src/main/java/net/md_5/bungee/command/ConsoleCommandCompleter.java
Outdated
Show resolved
Hide resolved
using the stream iterator as the iterator() of a new Iterable
The Guava developers want us to migrate to the Stream Library, which they tell us in the Iterables class documentation