Cleanup - More Lambdas to method references

This commit is contained in:
Jetz
2024-08-10 12:54:16 -04:00
parent 4614c6c0c9
commit f7d0929ea0
29 changed files with 62 additions and 68 deletions

View File

@@ -51,12 +51,12 @@ public class BiomeEdit extends FormPanel {
add(terrain);
add(structures);
name.getDocument().addDocumentListener(new DocumentChangeListener(() -> BiomeEdit.this.updateTerrain()));
tilesetName.getDocument().addDocumentListener(new DocumentChangeListener(() -> BiomeEdit.this.updateTerrain()));
color.getDocument().addDocumentListener(new DocumentChangeListener(() -> BiomeEdit.this.updateTerrain()));
name.getDocument().addDocumentListener(new DocumentChangeListener(BiomeEdit.this::updateTerrain));
tilesetName.getDocument().addDocumentListener(new DocumentChangeListener(BiomeEdit.this::updateTerrain));
color.getDocument().addDocumentListener(new DocumentChangeListener(BiomeEdit.this::updateTerrain));
collision.addChangeListener(e -> BiomeEdit.this.updateTerrain());
spriteNames.getEdit().getDocument().addDocumentListener(new DocumentChangeListener(() -> BiomeEdit.this.updateTerrain()));
enemies.getEdit().getDocument().addDocumentListener(new DocumentChangeListener(() -> BiomeEdit.this.updateTerrain()));
spriteNames.getEdit().getDocument().addDocumentListener(new DocumentChangeListener(BiomeEdit.this::updateTerrain));
enemies.getEdit().getDocument().addDocumentListener(new DocumentChangeListener(BiomeEdit.this::updateTerrain));
terrain.addChangeListener(e -> BiomeEdit.this.updateTerrain());
@@ -64,7 +64,7 @@ public class BiomeEdit extends FormPanel {
startPointY.addChangeListener(e -> BiomeEdit.this.updateTerrain());
noiseWeight.addChangeListener(e -> BiomeEdit.this.updateTerrain());
distWeight.addChangeListener(e -> BiomeEdit.this.updateTerrain());
tilesetAtlas.getEdit().getDocument().addDocumentListener(new DocumentChangeListener(() -> BiomeEdit.this.updateTerrain()));
tilesetAtlas.getEdit().getDocument().addDocumentListener(new DocumentChangeListener(BiomeEdit.this::updateTerrain));
width.addChangeListener(e -> BiomeEdit.this.updateTerrain());
height.addChangeListener(e -> BiomeEdit.this.updateTerrain());
refresh();

View File

@@ -135,8 +135,8 @@ public class BiomeStructureDataMappingEditor extends JComponent {
add("color:",color);
add("collision:",collision);
name.getDocument().addDocumentListener(new DocumentChangeListener(() -> BiomeStructureDataMappingEdit.this.update()));
color.getDocument().addDocumentListener(new DocumentChangeListener(() -> BiomeStructureDataMappingEdit.this.update()));
name.getDocument().addDocumentListener(new DocumentChangeListener(BiomeStructureDataMappingEdit.this::update));
color.getDocument().addDocumentListener(new DocumentChangeListener(BiomeStructureDataMappingEdit.this::update));
collision.addChangeListener(e -> BiomeStructureDataMappingEdit.this.update());
refresh();
}

View File

@@ -45,7 +45,7 @@ public class BiomeStructureEdit extends FormPanel {
add(center);
add(data);
structureAtlasPath.getDocument().addDocumentListener(new DocumentChangeListener(() -> BiomeStructureEdit.this.updateStructure()));
structureAtlasPath.getDocument().addDocumentListener(new DocumentChangeListener(BiomeStructureEdit.this::updateStructure));
x.addChangeListener(e -> BiomeStructureEdit.this.updateStructure());
@@ -55,8 +55,8 @@ public class BiomeStructureEdit extends FormPanel {
randomPosition.addChangeListener(e -> BiomeStructureEdit.this.updateStructure());
N.addChangeListener(e -> BiomeStructureEdit.this.updateStructure());
sourcePath.getDocument().addDocumentListener(new DocumentChangeListener(() -> BiomeStructureEdit.this.updateStructure()));
maskPath.getDocument().addDocumentListener(new DocumentChangeListener(() -> BiomeStructureEdit.this.updateStructure()));
sourcePath.getDocument().addDocumentListener(new DocumentChangeListener(BiomeStructureEdit.this::updateStructure));
maskPath.getDocument().addDocumentListener(new DocumentChangeListener(BiomeStructureEdit.this::updateStructure));
periodicInput.addChangeListener(e -> BiomeStructureEdit.this.updateStructure());
ground.addChangeListener(e -> BiomeStructureEdit.this.updateStructure());
symmetry.addChangeListener(e -> BiomeStructureEdit.this.updateStructure());

View File

@@ -27,7 +27,7 @@ public class BiomeTerrainEdit extends FormPanel {
center.add("resolution:",resolution);
add(center,preview);
spriteName.getDocument().addDocumentListener(new DocumentChangeListener(() -> BiomeTerrainEdit.this.updateTerrain()));
spriteName.getDocument().addDocumentListener(new DocumentChangeListener(BiomeTerrainEdit.this::updateTerrain));
min.addChangeListener(e -> BiomeTerrainEdit.this.updateTerrain());
max.addChangeListener(e -> BiomeTerrainEdit.this.updateTerrain());

View File

@@ -40,8 +40,8 @@ public class DialogOptionEdit extends FormPanel {
add(middle);
name.getDocument().addDocumentListener(new DocumentChangeListener(() -> DialogOptionEdit.this.updateDialog()));
text.getDocument().addDocumentListener(new DocumentChangeListener(() -> DialogOptionEdit.this.updateDialog()));
name.getDocument().addDocumentListener(new DocumentChangeListener(DialogOptionEdit.this::updateDialog));
text.getDocument().addDocumentListener(new DocumentChangeListener(DialogOptionEdit.this::updateDialog));
}

View File

@@ -42,7 +42,7 @@ public class EditorMainWindow extends JFrame {
BorderLayout layout=new BorderLayout();
JToolBar toolBar = new JToolBar("toolbar");
JButton newButton=new JButton("open ParticleEditor");
newButton.addActionListener(e -> EventQueue.invokeLater(() ->new ParticleEditor()));
newButton.addActionListener(e -> EventQueue.invokeLater(ParticleEditor::new));
toolBar.add(newButton);
setLayout(layout);
toolBar.setFloatable(false);

View File

@@ -42,8 +42,8 @@ public class EffectEditor extends JComponent {
lifeModifier.addChangeListener(e -> EffectEditor.this.updateEffect());
moveSpeed.addChangeListener(e -> EffectEditor.this.updateEffect());
colorView.addChangeListener(e -> EffectEditor.this.updateEffect());
name.getDocument().addDocumentListener(new DocumentChangeListener(() -> EffectEditor.this.updateEffect()));
startBattleWithCard.getEdit().getDocument().addDocumentListener(new DocumentChangeListener(() -> EffectEditor.this.updateEffect()));
name.getDocument().addDocumentListener(new DocumentChangeListener(EffectEditor.this::updateEffect));
startBattleWithCard.getEdit().getDocument().addDocumentListener(new DocumentChangeListener(EffectEditor.this::updateEffect));
if(opponent!=null)
opponent.addChangeListener(e -> EffectEditor.this.updateEffect());

View File

@@ -289,7 +289,7 @@ public class EnemyEdit extends FormPanel {
tags.add(e.nextElement());
}
tags.removeIf(q -> q.isEmpty());
tags.removeIf(String::isEmpty);
currentData.questTags = tags.toArray(currentData.questTags);
QuestController.getInstance().refresh();
filterExisting(enemyModel);

View File

@@ -38,10 +38,10 @@ public class ItemEdit extends JComponent {
add(effect);
add(new Box.Filler(new Dimension(0,0),new Dimension(0,Integer.MAX_VALUE),new Dimension(0,Integer.MAX_VALUE)));
nameField.getDocument().addDocumentListener(new DocumentChangeListener(() -> ItemEdit.this.updateItem()));
equipmentSlot.getDocument().addDocumentListener(new DocumentChangeListener(() -> ItemEdit.this.updateItem()));
description.getDocument().addDocumentListener(new DocumentChangeListener(() -> ItemEdit.this.updateItem()));
iconName.getDocument().addDocumentListener(new DocumentChangeListener(() -> ItemEdit.this.updateItem()));
nameField.getDocument().addDocumentListener(new DocumentChangeListener(ItemEdit.this::updateItem));
equipmentSlot.getDocument().addDocumentListener(new DocumentChangeListener(ItemEdit.this::updateItem));
description.getDocument().addDocumentListener(new DocumentChangeListener(ItemEdit.this::updateItem));
iconName.getDocument().addDocumentListener(new DocumentChangeListener(ItemEdit.this::updateItem));
cost.addChangeListener(e -> ItemEdit.this.updateItem());
questItem.addChangeListener(e -> ItemEdit.this.updateItem());
effect.addChangeListener(e -> ItemEdit.this.updateItem());

View File

@@ -58,18 +58,18 @@ public class RewardEdit extends FormPanel {
probability.addChangeListener(e -> RewardEdit.this.updateReward());
count.addChangeListener(e -> RewardEdit.this.updateReward());
addMaxCount.addChangeListener(e -> RewardEdit.this.updateReward());
cardName.getDocument().addDocumentListener(new DocumentChangeListener(() -> RewardEdit.this.updateReward()));
itemName.getDocument().addDocumentListener(new DocumentChangeListener(() -> RewardEdit.this.updateReward()));
editions.getEdit().getDocument().addDocumentListener(new DocumentChangeListener(() -> RewardEdit.this.updateReward()));
colors.getEdit().getDocument().addDocumentListener(new DocumentChangeListener(() -> RewardEdit.this.updateReward()));
rarity.getEdit().getDocument().addDocumentListener(new DocumentChangeListener(() -> RewardEdit.this.updateReward()));
subTypes.getEdit().getDocument().addDocumentListener(new DocumentChangeListener(() -> RewardEdit.this.updateReward()));
cardTypes.getEdit().getDocument().addDocumentListener(new DocumentChangeListener(() -> RewardEdit.this.updateReward()));
superTypes.getEdit().getDocument().addDocumentListener(new DocumentChangeListener(() -> RewardEdit.this.updateReward()));
manaCosts.getEdit().getDocument().addDocumentListener(new DocumentChangeListener(() -> RewardEdit.this.updateReward()));
keyWords.getEdit().getDocument().addDocumentListener(new DocumentChangeListener(() -> RewardEdit.this.updateReward()));
cardName.getDocument().addDocumentListener(new DocumentChangeListener(RewardEdit.this::updateReward));
itemName.getDocument().addDocumentListener(new DocumentChangeListener(RewardEdit.this::updateReward));
editions.getEdit().getDocument().addDocumentListener(new DocumentChangeListener(RewardEdit.this::updateReward));
colors.getEdit().getDocument().addDocumentListener(new DocumentChangeListener(RewardEdit.this::updateReward));
rarity.getEdit().getDocument().addDocumentListener(new DocumentChangeListener(RewardEdit.this::updateReward));
subTypes.getEdit().getDocument().addDocumentListener(new DocumentChangeListener(RewardEdit.this::updateReward));
cardTypes.getEdit().getDocument().addDocumentListener(new DocumentChangeListener(RewardEdit.this::updateReward));
superTypes.getEdit().getDocument().addDocumentListener(new DocumentChangeListener(RewardEdit.this::updateReward));
manaCosts.getEdit().getDocument().addDocumentListener(new DocumentChangeListener(RewardEdit.this::updateReward));
keyWords.getEdit().getDocument().addDocumentListener(new DocumentChangeListener(RewardEdit.this::updateReward));
colorType.addActionListener((e -> RewardEdit.this.updateReward()));
cardText.getDocument().addDocumentListener(new DocumentChangeListener(() -> RewardEdit.this.updateReward()));
cardText.getDocument().addDocumentListener(new DocumentChangeListener(RewardEdit.this::updateReward));
}

View File

@@ -427,7 +427,7 @@ public class EffectAi extends SpellAbilityAi {
if (sa.usesTargeting() && !sa.getTargetRestrictions().canTgtPlayer()) {
// try to target the opponent's best targetable permanent, if able
CardCollection oppPerms = CardLists.getValidCards(aiPlayer.getOpponents().getCardsIn(sa.getTargetRestrictions().getZone()), sa.getTargetRestrictions().getValidTgts(), aiPlayer, sa.getHostCard(), sa);
oppPerms = CardLists.filter(oppPerms, card -> sa.canTarget(card));
oppPerms = CardLists.filter(oppPerms, sa::canTarget);
if (!oppPerms.isEmpty()) {
sa.resetTargets();
sa.getTargets().add(ComputerUtilCard.getBestAI(oppPerms));
@@ -437,7 +437,7 @@ public class EffectAi extends SpellAbilityAi {
if (mandatory) {
// try to target the AI's worst targetable permanent, if able
CardCollection aiPerms = CardLists.getValidCards(aiPlayer.getCardsIn(sa.getTargetRestrictions().getZone()), sa.getTargetRestrictions().getValidTgts(), aiPlayer, sa.getHostCard(), sa);
aiPerms = CardLists.filter(aiPerms, card -> sa.canTarget(card));
aiPerms = CardLists.filter(aiPerms, sa::canTarget);
if (!aiPerms.isEmpty()) {
sa.resetTargets();
sa.getTargets().add(ComputerUtilCard.getWorstAI(aiPerms));

View File

@@ -323,7 +323,7 @@ public final class ImageKeys {
}
public static boolean hasSetLookup(String filename) {
if (!StaticData.instance().getSetLookup().isEmpty()) {
return StaticData.instance().getSetLookup().keySet().stream().anyMatch(setKey -> filename.startsWith(setKey));
return StaticData.instance().getSetLookup().keySet().stream().anyMatch(filename::startsWith);
}
return false;

View File

@@ -1602,7 +1602,7 @@ public class CardProperty {
if (!(property.contains("LKI") ? lki : card).isAttacking()) return false;
if (property.equals("attacking")) return true;
if (property.endsWith("Alone")) {
return CardLists.count(card.getGame().getLastStateBattlefield(), c -> c.isAttacking()) == 1;
return CardLists.count(card.getGame().getLastStateBattlefield(), Card::isAttacking) == 1;
}
if (property.equals("attackingYou")) return combat.isAttacking(card, sourceController);
if (property.equals("attackingSame")) {

View File

@@ -52,8 +52,8 @@ public class DeckSelectScene extends UIScene {
back = ui.findActor("return");
edit = ui.findActor("edit");
rename = ui.findActor("rename");
ui.onButtonPress("return", () -> DeckSelectScene.this.back());
ui.onButtonPress("edit", () -> DeckSelectScene.this.edit());
ui.onButtonPress("return", DeckSelectScene.this::back);
ui.onButtonPress("edit", DeckSelectScene.this::edit);
ui.onButtonPress("rename", () -> {
textInput.setText(Current.player().getSelectedDeck().getName());
showRenameDialog();

View File

@@ -173,10 +173,10 @@ public class NewGameScene extends MenuScene {
gender.setCurrentIndex(rand.nextInt());
colorId.setCurrentIndex(rand.nextInt());
race.setCurrentIndex(rand.nextInt());
ui.onButtonPress("back", () -> NewGameScene.this.back());
ui.onButtonPress("start", () -> NewGameScene.this.start());
ui.onButtonPress("leftAvatar", () -> NewGameScene.this.leftAvatar());
ui.onButtonPress("rightAvatar", () -> NewGameScene.this.rightAvatar());
ui.onButtonPress("back", NewGameScene.this::back);
ui.onButtonPress("start", NewGameScene.this::start);
ui.onButtonPress("leftAvatar", NewGameScene.this::leftAvatar);
ui.onButtonPress("rightAvatar", NewGameScene.this::rightAvatar);
difficultyHelp.addListener(new ClickListener(){ public void clicked(InputEvent e, float x, float y){ showDifficultyHelp(); }});
modeHelp.addListener(new ClickListener(){ public void clicked(InputEvent e, float x, float y){ showModeHelp(); }});
}

View File

@@ -114,7 +114,7 @@ public class SpellSmithScene extends UIScene {
}
}
ui.onButtonPress("done", () -> SpellSmithScene.this.done());
ui.onButtonPress("done", SpellSmithScene.this::done);
ui.onButtonPress("pullUsingGold", () -> SpellSmithScene.this.pullCard(false));
ui.onButtonPress("pullUsingShards", () -> SpellSmithScene.this.pullCard(true));
ui.onButtonPress("BReset", () -> {

View File

@@ -123,11 +123,11 @@ public class KeyBoardDialog extends Dialog {
key0 = Controls.newTextButton("0", () -> kbLabel.setText(kbLabel.getText()+"0"));
keyDot = Controls.newTextButton(".", () -> kbLabel.setText(kbLabel.getText()+"."));
keyComma = Controls.newTextButton(",", () -> kbLabel.setText(kbLabel.getText()+","));
keyShift = Controls.newTextButton("Aa", () -> shiftKey());
keyShift = Controls.newTextButton("Aa", this::shiftKey);
keyBackspace = Controls.newTextButton("<<", () -> kbLabel.setText(removeLastChar(String.valueOf(kbLabel.getText()))));
keySpace = Controls.newTextButton("SPACE", () -> kbLabel.setText(kbLabel.getText()+" "));
keyOK = Controls.newTextButton("OK", () -> setKeyboardDialogText());
keyAbort = Controls.newTextButton("Abort", () -> abortKeyInput());
keyOK = Controls.newTextButton("OK", this::setKeyboardDialogText);
keyAbort = Controls.newTextButton("Abort", this::abortKeyInput);
this.getContentTable().add(kbLabel).width(220).height(20).colspan(10).expandX().align(Align.center);
this.getButtonTable().row();
this.getButtonTable().add(key1).width(20).height(20);

View File

@@ -143,18 +143,14 @@ public class SimpleTiledModel extends Model {
for (int t = 0; t < cardinality; t++) {
ColorMap xtileData = tileData.get(tilename);
this.tiles.add(
tile.apply(
(Integer x, Integer y) -> (xtileData.getColor(x, y))
)
tile.apply(xtileData::getColor)
);
this.tilenames.add(String.format("%s %s", tilename, t));
}
} else {
ColorMap xtileData = tileData.get(tilename);
this.tiles.add(
tile.apply(
(Integer x, Integer y) -> (xtileData.getColor(x, y))
)
tile.apply(xtileData::getColor)
);
this.tilenames.add(String.format("%s 0", tilename));

View File

@@ -57,7 +57,7 @@ public class LoadingOverlay extends FOverlay {
loader.show();
FThreads.invokeInBackgroundThread(() -> {
task.run();
FThreads.invokeInEdtLater(() -> loader.hide());
FThreads.invokeInEdtLater(loader::hide);
});
}

View File

@@ -115,7 +115,7 @@ public class OnlineLobbyScreen extends LobbyScreen implements IOnlineLobby {
}
chatInterface.addMessage(result);
if (!joinServer) {
FThreads.invokeInBackgroundThread(() -> NetConnectUtil.copyHostedServerUrl());
FThreads.invokeInBackgroundThread(NetConnectUtil::copyHostedServerUrl);
}
//update menu buttons
OnlineScreen.Lobby.update();

View File

@@ -37,7 +37,7 @@ public class NewConquestScreen extends MultiStepWizardScreen<NewConquestScreenMo
@Override
protected void finish() {
//create new quest in game thread so option panes can wait for input
ThreadUtil.invokeInGameThread(() -> newConquest());
ThreadUtil.invokeInGameThread(this::newConquest);
}
private void newConquest() {

View File

@@ -181,7 +181,7 @@ public class NewQuestScreen extends FScreen {
private final FLabel btnEmbark = add(new FLabel.ButtonBuilder()
.font(FSkinFont.get(22)).text(Forge.getLocalizer().getMessage("lblEmbark")).icon(FSkinImage.QUEST_ZEP).command(event -> {
//create new quest in game thread so option panes can wait for input
ThreadUtil.invokeInGameThread(() -> newQuest());
ThreadUtil.invokeInGameThread(this::newQuest);
}).build());
public NewQuestScreen() {

View File

@@ -24,7 +24,7 @@ public abstract class QuestLaunchScreen extends LaunchScreen {
protected void startMatch() {
FThreads.invokeInBackgroundThread(() -> {
if (QuestUtil.canStartGame()) {
FThreads.invokeInEdtLater(() -> LoadingOverlay.show(Forge.getLocalizer().getMessage("lblLoadingNewGame"), true, () -> QuestUtil.finishStartingGame()));
FThreads.invokeInEdtLater(() -> LoadingOverlay.show(Forge.getLocalizer().getMessage("lblLoadingNewGame"), true, QuestUtil::finishStartingGame));
return;
}
});

View File

@@ -51,14 +51,14 @@ public class QuestMenu extends FPopupMenu implements IVQuestStats {
//invoke in background thread so prompts can work
ThreadUtil.invokeInGameThread(() -> {
QuestUtil.chooseAndUnlockEdition();
FThreads.invokeInEdtLater(() -> updateCurrentQuestScreen());
FThreads.invokeInEdtLater(QuestMenu::updateCurrentQuestScreen);
});
});
private static final FMenuItem travelItem = new FMenuItem(Forge.getLocalizer().getMessage("btnTravel"), FSkinImage.QUEST_MAP, event -> {
//invoke in background thread so prompts can work
ThreadUtil.invokeInGameThread(() -> {
QuestUtil.travelWorld();
FThreads.invokeInEdtLater(() -> updateCurrentQuestScreen());
FThreads.invokeInEdtLater(QuestMenu::updateCurrentQuestScreen);
});
});
private static final FMenuItem prefsItem = new FMenuItem(Forge.getLocalizer().getMessage("Preferences"), Forge.hdbuttons ? FSkinImage.HDPREFERENCE : FSkinImage.SETTINGS, event -> setCurrentScreen(prefsScreen));

View File

@@ -64,7 +64,7 @@ public class QuestSpellShopScreen extends TabPageScreen<QuestSpellShopScreen> {
else {
inventoryPage.activateItems(items);
}
FThreads.invokeInEdtLater(() -> updateCreditsLabel());
FThreads.invokeInEdtLater(this::updateCreditsLabel);
});
});
}

View File

@@ -84,19 +84,19 @@ public class QuestTournamentsScreen extends QuestLaunchScreen implements IQuestT
controller = new QuestTournamentController(this);
btnSpendToken.setCommand(event -> {
//must run in background thread to handle alerts
FThreads.invokeInBackgroundThread(() -> controller.spendToken());
FThreads.invokeInBackgroundThread(controller::spendToken);
});
btnEditDeck.setCommand(event -> editDeck(true));
btnLeaveTournament.setCommand(event -> {
//must run in background thread to handle alerts
FThreads.invokeInBackgroundThread(() -> controller.endTournamentAndAwardPrizes());
FThreads.invokeInBackgroundThread(controller::endTournamentAndAwardPrizes);
});
// TODO: is it possible to somehow reuse the original btnEditDeck/btnLeaveTournament
btnEditDeckInTourn.setCommand(event -> editDeck(true));
btnLeaveTournamentInTourn.setCommand(event -> {
//must run in background thread to handle alerts
FThreads.invokeInBackgroundThread(() -> controller.endTournamentAndAwardPrizes());
FThreads.invokeInBackgroundThread(controller::endTournamentAndAwardPrizes);
});
pnlPrepareDeck.add(btnEditDeck);

View File

@@ -35,8 +35,6 @@ public class DeckProxy implements InventoryItem {
protected final String deckType;
protected final IStorage<? extends IHasName> storage;
public static final Function<DeckProxy, String> FN_GET_NAME = arg0 -> arg0.getName();
// cached values
protected ColorSet color;
protected ColorSet colorIdentity;

View File

@@ -2589,7 +2589,7 @@ public class PlayerControllerHuman extends PlayerController implements IGameCont
final Card card = gameCacheCounters.get(cv);
final ImmutableList<CounterType> counters = subtract ? ImmutableList.copyOf(card.getCounters().keySet())
: ImmutableList.copyOf(Collections2.transform(CounterEnumType.values, input -> CounterType.get(input)));
: ImmutableList.copyOf(Collections2.transform(CounterEnumType.values, CounterType::get));
final CounterType counter = getGui().oneOrNone(localizer.getMessage("lblWhichTypeofCounter"), counters);
if (counter == null) {

View File

@@ -45,7 +45,7 @@ class Documents {
//System.out.println(docID);
//System.out.println(bow.getWords(docID).toString());
return bow.getWords(docID).stream()
.map(id -> vocabs.get(id))
.map(vocabs::get)
.collect(Collectors.toList());
}