mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-18 11:48:02 +00:00
Miscallaneous Cleanup Part 2 - Lambdas and Method References (#5737)
* Cleanup - Unnecessary Boxing * Cleanup - Unnecessary Unboxing * Cleanup - For-Each Loops * Cleanup - `indexOf != -1` -> `contains` * Cleanup - Merge identical catch blocks * Cleanup - Try-with-resources * Cleanup - System.lineSeparator * Cleanup - Reference types to primitives Some loops over Integers were switched to IntStreams to hopefully cut down on overall boxing. * Cleanup - Manually filling and copying arrays * Remove unused imports * Switch a lambda to a method reference * Cleanup - CardPredicate Aggregates to method references * Cleanup - Other static functions to method references * Cleanup - Ambiguous class reference Unclear when or how this happened... * Cleanup - Anonymous -> Method reference * Cleanup - Anonymous -> Lambda * Cleanup - Comparator helper methods * Cleanup - final method in final class * Cleanup - private final methods * Remove unused imports * Convert a couple more lambdas to comparators. * Simplify creature type list comparison. --------- Co-authored-by: Jetz <Jetz722@gmail.com> Co-authored-by: tool4ever <therealtoolkit@hotmail.com>
This commit is contained in:
@@ -1,14 +1,11 @@
|
||||
package forge.lda;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Predicates;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import forge.GuiDesktop;
|
||||
import forge.StaticData;
|
||||
import forge.card.CardRules;
|
||||
import forge.card.CardRulesPredicates;
|
||||
import forge.deck.Deck;
|
||||
import forge.deck.DeckFormat;
|
||||
@@ -43,14 +40,11 @@ public final class LDAModelGenetrator {
|
||||
public static Map<String, List<Archetype>> ldaArchetypes = new HashMap<>();
|
||||
|
||||
|
||||
public static final void main(String[] args){
|
||||
public static void main(String[] args){
|
||||
GuiBase.setInterface(new GuiDesktop());
|
||||
FModel.initialize(null, new Function<ForgePreferences, Void>() {
|
||||
@Override
|
||||
public Void apply(ForgePreferences preferences) {
|
||||
preferences.setPref(ForgePreferences.FPref.LOAD_CARD_SCRIPTS_LAZILY, false);
|
||||
return null;
|
||||
}
|
||||
FModel.initialize(null, preferences -> {
|
||||
preferences.setPref(ForgePreferences.FPref.LOAD_CARD_SCRIPTS_LAZILY, false);
|
||||
return null;
|
||||
});
|
||||
initialize();
|
||||
}
|
||||
@@ -258,12 +252,7 @@ public final class LDAModelGenetrator {
|
||||
|
||||
unfilteredTopics.add(new Archetype(topRankVocabs, deckName, decks.size()));
|
||||
}
|
||||
Comparator<Archetype> archetypeComparator = new Comparator<Archetype>() {
|
||||
@Override
|
||||
public int compare(Archetype o1, Archetype o2) {
|
||||
return o2.getDeckCount().compareTo(o1.getDeckCount());
|
||||
}
|
||||
};
|
||||
Comparator<Archetype> archetypeComparator = (o1, o2) -> o2.getDeckCount().compareTo(o1.getDeckCount());
|
||||
|
||||
Collections.sort(unfilteredTopics,archetypeComparator);
|
||||
return unfilteredTopics;
|
||||
@@ -271,14 +260,10 @@ public final class LDAModelGenetrator {
|
||||
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static <K, V> Map<K, V> sortByValue(Map<K, V> map) {
|
||||
List<Map.Entry<K, V>> list = new LinkedList<>(map.entrySet());
|
||||
Collections.sort(list, new Comparator<Object>() {
|
||||
@SuppressWarnings("unchecked")
|
||||
public int compare(Object o1, Object o2) {
|
||||
return ((Comparable<V>) ((Map.Entry<K, V>) (o2)).getValue()).compareTo(((Map.Entry<K, V>) (o1)).getValue());
|
||||
}
|
||||
});
|
||||
Collections.sort(list, (Comparator<Object>) (o1, o2) -> ((Comparable<V>) ((Map.Entry<K, V>) (o2)).getValue()).compareTo(((Map.Entry<K, V>) (o1)).getValue()));
|
||||
|
||||
Map<K, V> result = new LinkedHashMap<>();
|
||||
for (Map.Entry<K, V> entry : list) {
|
||||
@@ -306,7 +291,7 @@ public final class LDAModelGenetrator {
|
||||
|
||||
//get all cards
|
||||
final Iterable<PaperCard> cards = Iterables.filter(FModel.getMagicDb().getCommonCards().getUniqueCards()
|
||||
, Predicates.compose(Predicates.not(CardRulesPredicates.Presets.IS_BASIC_LAND_NOT_WASTES), PaperCard.FN_GET_RULES));
|
||||
, Predicates.compose(Predicates.not(CardRulesPredicates.Presets.IS_BASIC_LAND_NOT_WASTES), PaperCard::getRules));
|
||||
List<PaperCard> cardList = Lists.newArrayList(cards);
|
||||
cardList.add(FModel.getMagicDb().getCommonCards().getCard("Wastes"));
|
||||
Map<String, Integer> cardIntegerMap = new HashMap<>();
|
||||
@@ -321,12 +306,8 @@ public final class LDAModelGenetrator {
|
||||
|
||||
//filter to just legal commanders
|
||||
List<PaperCard> legends = Lists.newArrayList(Iterables.filter(cardList,Predicates.compose(
|
||||
new Predicate<CardRules>() {
|
||||
@Override
|
||||
public boolean apply(CardRules rules) {
|
||||
return DeckFormat.Commander.isLegalCommander(rules);
|
||||
}
|
||||
}, PaperCard.FN_GET_RULES)));
|
||||
DeckFormat.Commander::isLegalCommander, PaperCard::getRules
|
||||
)));
|
||||
|
||||
//generate lookups for legends to link commander names to matrix rows
|
||||
for (int i=0; i<legends.size(); ++i){
|
||||
@@ -369,7 +350,7 @@ public final class LDAModelGenetrator {
|
||||
public static void updateLegendMatrix(Deck deck, PaperCard legend, Map<String, Integer> cardIntegerMap,
|
||||
Map<String, Integer> legendIntegerMap, int[][] matrix){
|
||||
for (PaperCard pairCard:Iterables.filter(deck.getMain().toFlatList(),
|
||||
Predicates.compose(Predicates.not(CardRulesPredicates.Presets.IS_BASIC_LAND_NOT_WASTES), PaperCard.FN_GET_RULES))){
|
||||
Predicates.compose(Predicates.not(CardRulesPredicates.Presets.IS_BASIC_LAND_NOT_WASTES), PaperCard::getRules))){
|
||||
if (!pairCard.getName().equals(legend.getName())){
|
||||
try {
|
||||
int old = matrix[legendIntegerMap.get(legend.getName())][cardIntegerMap.get(pairCard.getName())];
|
||||
|
||||
Reference in New Issue
Block a user