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

Remove unnecessary Guava usages #13

Merged
merged 5 commits into from
Oct 4, 2018
Merged

Conversation

MrMicky-FR
Copy link
Contributor

Remove unnecessary Guava usages like Lists.newArrayList() that can be replace with just new ArrayList<>()

https://google.github.io/guava/releases/23.0/api/docs/com/google/common/collect/Lists.html#newArrayList--

Note for Java 7 and later: this method is now unnecessary and should be treated as deprecated. Instead, use the ArrayList constructor directly, taking advantage of the new "diamond" syntax.

@msftclas
Copy link

msftclas commented Sep 27, 2018

CLA assistant check
All CLA requirements met.

Dinnerbone
Dinnerbone previously approved these changes Sep 27, 2018
Copy link
Contributor

@Dinnerbone Dinnerbone left a comment

Choose a reason for hiding this comment

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

Thank you very much for this!

When I started writing Brigadier in 2015, we didn't have this luxury. I think perhaps we could even remove Guava entirely at this point. I'm on an airplane right now and can't check myself - were there any remaining usages of Guava after this change?

@MiniDigger
Copy link

I couldn't spot any other guava usages in the source, but there are plenty in the tests.

https://github.com/Mojang/brigadier/search?p=1&q=common.collect&unscoped_q=common.collect

@Dinnerbone
Copy link
Contributor

Then perhaps we can make it only required for testing?

@MiniDigger
Copy link

@MrMicky-FR change 'api' -> 'testCompile' here
https://github.com/Mojang/brigadier/blob/master/build.gradle#L36

@MrMicky-FR
Copy link
Contributor Author

MrMicky-FR commented Sep 27, 2018

I removed some others Guava usages, just one to remove now: https://github.com/Mojang/brigadier/blob/master/src/main/java/com/mojang/brigadier/tree/CommandNode.java#L179-L183

@MrMicky-FR
Copy link
Contributor Author

I finished removing Guava 😃

Just I have'nt tested it yet

Copy link
Contributor

@Dinnerbone Dinnerbone left a comment

Choose a reason for hiding this comment

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

This looks great, just 2 details to take care of and then we'll pull it in! Thank you again <3

return getSortedKey().compareTo(o.getSortedKey());
}

return (o instanceof LiteralCommandNode) ? 1 : -1;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this should return 0 if they're both, or neither, instanceof. I am not sure that will have any practical effects in the current codebase but it could skew any pre-sorting.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This code returns the same as the actual code with Guava ComparisonChain but I can change it if you prefer.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think it does. The ComparisonChain should return 0 if neither are literals (therefore preserving any existing sort), but this will return -1.

Copy link
Contributor Author

@MrMicky-FR MrMicky-FR Oct 1, 2018

Choose a reason for hiding this comment

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

Oh thanks, I corrected this

import java.util.List;
import java.util.Map;

public class CommandContext<S> {

public static final Map<Class<?>, Class<?>> PRIMITIVE_TO_WRAPPER = new HashMap<>();
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps make this private so it's not an official part of the Brigadier API.

@Dinnerbone Dinnerbone merged commit 7ee589b into Mojang:master Oct 4, 2018
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.

4 participants