diff --git a/game-app/game-core/src/main/java/games/strategy/triplea/attachments/AbstractRulesAttachment.java b/game-app/game-core/src/main/java/games/strategy/triplea/attachments/AbstractRulesAttachment.java index 48810f1f2a7..b503071b159 100644 --- a/game-app/game-core/src/main/java/games/strategy/triplea/attachments/AbstractRulesAttachment.java +++ b/game-app/game-core/src/main/java/games/strategy/triplea/attachments/AbstractRulesAttachment.java @@ -13,7 +13,6 @@ import games.strategy.triplea.delegate.Matches; import games.strategy.triplea.delegate.OriginalOwnerTracker; import java.util.Collection; -import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -67,9 +66,8 @@ private void setPlayers(final List value) { } protected List getPlayers() { - return players == null - ? List.of((GamePlayer) getAttachedTo()) - : Collections.unmodifiableList(players); + List result = getListProperty(players); + return result.isEmpty() ? List.of((GamePlayer) getAttachedTo()) : result; } private void resetPlayers() { diff --git a/game-app/game-core/src/main/java/games/strategy/triplea/ui/ObjectivePanel.java b/game-app/game-core/src/main/java/games/strategy/triplea/ui/ObjectivePanel.java index bf618ffd533..2442c288972 100644 --- a/game-app/game-core/src/main/java/games/strategy/triplea/ui/ObjectivePanel.java +++ b/game-app/game-core/src/main/java/games/strategy/triplea/ui/ObjectivePanel.java @@ -94,15 +94,15 @@ protected void initLayout() { column1.setCellEditor(new EditorPaneCellEditor()); column1.setCellRenderer(new EditorPaneTableCellRenderer()); final JScrollPane scroll = new JScrollPane(table); - final JButton refresh = new JButton("Refresh Objectives"); + final JButton refresh = + new JButton( + SwingAction.of( + "Refresh Objectives", + e -> { + objectiveModel.loadData(); + SwingUtilities.invokeLater(table::repaint); + })); refresh.setAlignmentY(Component.CENTER_ALIGNMENT); - refresh.addActionListener( - SwingAction.of( - "Refresh Objectives", - e -> { - objectiveModel.loadData(); - SwingUtilities.invokeLater(table::repaint); - })); add(Box.createVerticalStrut(6)); add(refresh); add(Box.createVerticalStrut(6)); @@ -249,10 +249,7 @@ public synchronized Object getValueAt(final int row, final int col) { } private synchronized void loadData() { - // copy so acquire/release read lock are on the same object! - final GameData gameData = ObjectivePanel.this.gameData; - gameData.acquireReadLock(); - try { + try (GameData.Unlocker ignored = gameData.acquireReadLock()) { final Map conditions = getConditionComment(getTestedConditions()); collectedData = new String[getRowTotal()][COLUMNS_TOTAL]; int row = 0; @@ -270,8 +267,6 @@ private synchronized void loadData() { collectedData[row][1] = "--------------------"; row++; } - } finally { - gameData.releaseReadLock(); } } @@ -285,13 +280,13 @@ public Map getConditionComment( final int each = AbstractTriggerAttachment.getEachMultiple(ta); final int uses = ta.getUses(); if (uses < 0) { - final String comment = satisfied ? (each > 1 ? "T" + each : "T") : "F"; + final String comment = formatStatus(satisfied, each); conditionsComments.put(entry.getKey(), comment); } else if (uses == 0) { final String comment = satisfied ? "Used" : "used"; conditionsComments.put(entry.getKey(), comment); } else { - final String comment = uses + "" + (satisfied ? (each > 1 ? "T" + each : "T") : "F"); + final String comment = uses + "" + formatStatus(satisfied, each); conditionsComments.put(entry.getKey(), comment); } } else if (entry.getKey() instanceof RulesAttachment) { @@ -305,7 +300,7 @@ public Map getConditionComment( final String comment = satisfied ? "Used" : "used"; conditionsComments.put(entry.getKey(), comment); } else { - final String comment = uses + "" + (satisfied ? (each > 1 ? "T" + each : "T") : "F"); + final String comment = uses + "" + formatStatus(satisfied, each); conditionsComments.put(entry.getKey(), comment); } } else { @@ -315,6 +310,10 @@ public Map getConditionComment( return conditionsComments; } + private String formatStatus(boolean satisfied, int each) { + return satisfied ? (each > 1 ? "T" + each : "T") : "F"; + } + public Map getTestedConditions() { final Set myConditions = new HashSet<>(); for (final Map map : statsObjective.values()) { @@ -342,11 +341,8 @@ public synchronized int getRowCount() { return collectedData.length; } - gameData.acquireReadLock(); - try { + try (GameData.Unlocker ignored = gameData.acquireReadLock()) { return getRowTotal(); - } finally { - gameData.releaseReadLock(); } } @@ -507,12 +503,12 @@ private int findMaximumRowSize(final JTable table, final int row) { if (rows == null) { return 0; } - final Map rowheights = rows.get(row); - if (rowheights == null) { + final Map rowHeights = rows.get(row); + if (rowHeights == null) { return 0; } int maximumHeight = 0; - for (final Entry entry : rowheights.entrySet()) { + for (final Entry entry : rowHeights.entrySet()) { final int cellHeight = entry.getValue(); maximumHeight = Math.max(maximumHeight, cellHeight); }