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

Migrate Guava Predicates and Functions to Java implementations #6047

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

Conversation

Jetz72
Copy link
Contributor

@Jetz72 Jetz72 commented Sep 3, 2024

Per #5717.

Not complete yet but wouldn't hurt to get some eyes on it while it's easier to revise things.

The switch-over of the implementation is done, but still need to finish cleaning up the helper methods. Many can be simplified through method references (e.g. ::equals and ::contains), but others don't have a good equivalent.

The dependency on Guava's Iterables is one point of uncertainty at the moment. It's too convenient to get rid of, but a handful of the filter methods still want Guava predicates. Could reimplement these manually in an IterableUtils class, or could just use the predicate::test hack to keep using the original library.

@Jetz72 Jetz72 requested a review from Hanmac September 3, 2024 14:34
Jetz added 5 commits September 29, 2024 11:03
# Conflicts:
#	forge-game/src/main/java/forge/game/ForgeScript.java
# Conflicts:
#	forge-game/src/main/java/forge/game/phase/PhaseHandler.java
# Conflicts:
#	forge-ai/src/main/java/forge/ai/ComputerUtil.java
#	forge-core/src/main/java/forge/card/DeckHints.java
#	forge-game/src/main/java/forge/game/ability/AbilityFactory.java
#	forge-game/src/main/java/forge/game/cost/CostUntapType.java
#	forge-gui/src/main/java/forge/player/HumanCostDecision.java
@tool4ever
Copy link
Contributor

@Hanmac
do you still want to check anything? otherwise since release happened we might ship it
maybe keep it unsquashed bc of the size? 🤔

Jetz added 5 commits October 17, 2024 08:23
# Conflicts:
#	forge-gui-mobile/src/forge/adventure/data/AdventureEventData.java
Rewrite `generateParticipants`
# Conflicts:
#	forge-game/src/main/java/forge/game/GameEntityCounterTable.java
#	forge-game/src/main/java/forge/game/ability/effects/PumpEffect.java
#	forge-game/src/main/java/forge/game/staticability/StaticAbilityContinuous.java
@kevlahnota
Copy link
Contributor

@Hanmac is this PR good, I think java is more performant than guava, also do we need guava (I don't know if java covers all other collections guava have)

@Hanmac
Copy link
Contributor

Hanmac commented Oct 21, 2024

@kevlahnota i will look over this MR, but i think it should be good enough?

we can't really drop guava fully, i would miss my Table support

@Jetz72
Copy link
Contributor Author

Jetz72 commented Oct 21, 2024

I looked at cutting out more of Guava and recreating the functionality within other util classes, but the scope of that started expanding too quickly for this PR at least. They have a huge number of helper methods that we use, and many of those are implemented through internal helper classes which would either need to be reproduced as well or replaced with inline logic.

If we want to further lessen the dependency on Guava, I think a good direction would be expanding the functionality of FCollection, FCollectionView, and their derivatives. Passing data around through those instead of Iterables would reduce our reliance on Guava's Iterables methods.

For performance improvements, as mentioned above, I think CardLists could do with some scrutiny. I believe many methods there create entirely new collections each time they're called, and they're often used even when the call site only needs a filtered view.

Jetz added 8 commits November 8, 2024 18:37
# Conflicts:
#	forge-ai/src/main/java/forge/ai/ability/ChooseCardAi.java
#	forge-ai/src/main/java/forge/ai/ability/ScryAi.java
#	forge-core/src/main/java/forge/card/DeckHints.java
#	forge-core/src/main/java/forge/util/TextUtil.java
#	forge-gui-mobile/src/forge/itemmanager/ItemManager.java
#	forge-gui/src/main/java/forge/download/AutoUpdater.java
#	forge-gui/src/main/java/forge/player/HumanCostDecision.java
Copy link
Contributor

@kevlahnota kevlahnota left a comment

Choose a reason for hiding this comment

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

the toList method directly from stream are missing on older Android (12 and below tested, not sure on 13 and above), so this will break mobile builds.
#4bbc165460cbe87a32eb4227f5b4fda26959d9f9

@Jetz72
Copy link
Contributor Author

Jetz72 commented Nov 11, 2024

Gah. I was excited when I saw we'd moved up to Java 17. Should I just treat the language level as though it were 11, then?

@kevlahnota
Copy link
Contributor

Gah. I was excited when I saw we'd moved up to Java 17. Should I just treat the language level as though it were 11, then?

Hmm I just discovered it when I update the auditer. Don't know which Java api are excluded on android.

@Jetz72
Copy link
Contributor Author

Jetz72 commented Nov 12, 2024

Android 12 and 13 reportedly support up to Java 11, and Android 14 partially supports Java 17.
https://developer.android.com/build/jdks#compileSdk

From what I can tell, the D8 compiler has support for backporting newer Java API members via desugaring, but it sounds like that's only being used to enable stuff from the Java 11 API on Android <= 11.
https://developer.android.com/studio/write/java11-default-support-table
https://issuetracker.google.com/issues/304335616

If the project is gonna be set to Java 17, though, It would probably be a good idea to add a github workflow to test the android build, or otherwise report unsupported API members. It seems like an easy thing to overlook.

Worth keeping an eye on this in case desugaring support for 17 gets added someday - https://github.com/google/desugar_jdk_libs/blob/master/CHANGELOG.md

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