From c4575a67d9890d2b6bd715d72c7a07577cce2177 Mon Sep 17 00:00:00 2001 From: Hamidreza Bayat Date: Fri, 27 Mar 2020 19:20:30 +0430 Subject: [PATCH] Java language level migrations --- CuckooChess/src/main/java/gui/AppletGUI.java | 12 ++++++------ CuckooChess/src/main/java/gui/ChessBoardPainter.java | 4 +--- CuckooChess/src/main/java/tui/TUIGame.java | 5 +---- CuckooChess/src/main/java/uci/UCIProtocol.java | 4 +--- .../org/petero/droidfish/activities/GameAdapter.java | 2 +- .../org/petero/droidfish/activities/LoadFEN.java | 4 +--- .../java/org/petero/droidfish/book/InternalBook.java | 2 +- .../petero/droidfish/engine/DroidComputerPlayer.java | 2 +- .../java/org/petero/engineserver/EngineServer.java | 3 +-- 9 files changed, 14 insertions(+), 24 deletions(-) diff --git a/CuckooChess/src/main/java/gui/AppletGUI.java b/CuckooChess/src/main/java/gui/AppletGUI.java index 63dea8f..80ddc9f 100644 --- a/CuckooChess/src/main/java/gui/AppletGUI.java +++ b/CuckooChess/src/main/java/gui/AppletGUI.java @@ -138,7 +138,7 @@ public class AppletGUI extends javax.swing.JApplet implements GUIInterface { NewGame.setText("New Game"); NewGame.setFocusable(false); - NewGame.addActionListener(evt -> NewGameActionPerformed(evt)); + NewGame.addActionListener(this::NewGameActionPerformed); SettingsPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Settings")); SettingsPanel.setFocusable(false); @@ -161,15 +161,15 @@ public class AppletGUI extends javax.swing.JApplet implements GUIInterface { TimeSlider.setPaintTicks(true); TimeSlider.setValue(5); TimeSlider.setFocusable(false); - TimeSlider.addChangeListener(evt -> TimeSliderStateChanged(evt)); + TimeSlider.addChangeListener(this::TimeSliderStateChanged); ShowThinking.setText("Show Thinking"); ShowThinking.setFocusable(false); - ShowThinking.addChangeListener(evt -> ShowThinkingStateChanged(evt)); + ShowThinking.addChangeListener(this::ShowThinkingStateChanged); FlipBoard.setText("Flip Board"); FlipBoard.setFocusable(false); - FlipBoard.addChangeListener(evt -> FlipBoardStateChanged(evt)); + FlipBoard.addChangeListener(this::FlipBoardStateChanged); javax.swing.GroupLayout SettingsPanelLayout = new javax.swing.GroupLayout(SettingsPanel); SettingsPanel.setLayout(SettingsPanelLayout); @@ -215,13 +215,13 @@ public class AppletGUI extends javax.swing.JApplet implements GUIInterface { Forward.setDefaultCapable(false); Forward.setFocusPainted(false); Forward.setFocusable(false); - Forward.addActionListener(evt -> ForwardActionPerformed(evt)); + Forward.addActionListener(this::ForwardActionPerformed); Backward.setText("<-"); Backward.setDefaultCapable(false); Backward.setFocusPainted(false); Backward.setFocusable(false); - Backward.addActionListener(evt -> BackwardActionPerformed(evt)); + Backward.addActionListener(this::BackwardActionPerformed); javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); jPanel1.setLayout(jPanel1Layout); diff --git a/CuckooChess/src/main/java/gui/ChessBoardPainter.java b/CuckooChess/src/main/java/gui/ChessBoardPainter.java index 86eb162..f8e731a 100644 --- a/CuckooChess/src/main/java/gui/ChessBoardPainter.java +++ b/CuckooChess/src/main/java/gui/ChessBoardPainter.java @@ -179,9 +179,7 @@ public class ChessBoardPainter extends JLabel { try { Font font = Font.createFont(Font.TRUETYPE_FONT, inStream); chessFont = font.deriveFont((float)sqSize); - } catch (FontFormatException ex) { - throw new RuntimeException(); - } catch (IOException ex) { + } catch (FontFormatException | IOException ex) { throw new RuntimeException(); } } diff --git a/CuckooChess/src/main/java/tui/TUIGame.java b/CuckooChess/src/main/java/tui/TUIGame.java index d3a8428..501ccb8 100644 --- a/CuckooChess/src/main/java/tui/TUIGame.java +++ b/CuckooChess/src/main/java/tui/TUIGame.java @@ -147,12 +147,9 @@ public class TUIGame extends Game { return false; } catch (IOException ex) { System.out.printf("IO error: %s\n", ex.getMessage()); - } catch (ChessParseError cpe) { + } catch (ChessParseError | StringIndexOutOfBoundsException cpe) { int lineNo = (fr == null) ? -1 : fr.getLineNumber(); System.out.printf("Parse error, line %d: %s\n", lineNo, cpe.getMessage()); - } catch (StringIndexOutOfBoundsException e) { - int lineNo = (fr == null) ? -1 : fr.getLineNumber(); - System.out.printf("Parse error, line %d: %s\n", lineNo, e.getMessage()); } finally { if (fr != null) { try { diff --git a/CuckooChess/src/main/java/uci/UCIProtocol.java b/CuckooChess/src/main/java/uci/UCIProtocol.java index b92077a..ee596d3 100644 --- a/CuckooChess/src/main/java/uci/UCIProtocol.java +++ b/CuckooChess/src/main/java/uci/UCIProtocol.java @@ -199,9 +199,7 @@ public class UCIProtocol { } quit = true; } - } catch (ChessParseError ignore) { - } catch (ArrayIndexOutOfBoundsException ignore) { - } catch (NumberFormatException ignore) { + } catch (ChessParseError | ArrayIndexOutOfBoundsException | NumberFormatException ignore) { } } diff --git a/DroidFishApp/src/main/java/org/petero/droidfish/activities/GameAdapter.java b/DroidFishApp/src/main/java/org/petero/droidfish/activities/GameAdapter.java index 16cbeb5..a81fe3f 100644 --- a/DroidFishApp/src/main/java/org/petero/droidfish/activities/GameAdapter.java +++ b/DroidFishApp/src/main/java/org/petero/droidfish/activities/GameAdapter.java @@ -112,7 +112,7 @@ public class GameAdapter extends BaseAdapter implements Filterable { @SuppressWarnings("unchecked") @Override protected void publishResults(CharSequence constraint, FilterResults results) { - values = results == null ? new ArrayList() : (ArrayList) results.values; + values = results == null ? new ArrayList<>() : (ArrayList) results.values; notifyDataSetChanged(); } } diff --git a/DroidFishApp/src/main/java/org/petero/droidfish/activities/LoadFEN.java b/DroidFishApp/src/main/java/org/petero/droidfish/activities/LoadFEN.java index 5821533..cea5edc 100644 --- a/DroidFishApp/src/main/java/org/petero/droidfish/activities/LoadFEN.java +++ b/DroidFishApp/src/main/java/org/petero/droidfish/activities/LoadFEN.java @@ -93,9 +93,7 @@ public class LoadFEN extends ListActivity { workThread = new Thread(() -> { if (!readFile()) return; - runOnUiThread(() -> { - lfen.showList(); - }); + runOnUiThread(lfen::showList); }); workThread.start(); } else if ("org.petero.droidfish.loadNextFen".equals(action) || diff --git a/DroidFishApp/src/main/java/org/petero/droidfish/book/InternalBook.java b/DroidFishApp/src/main/java/org/petero/droidfish/book/InternalBook.java index df10cf7..e57fd22 100644 --- a/DroidFishApp/src/main/java/org/petero/droidfish/book/InternalBook.java +++ b/DroidFishApp/src/main/java/org/petero/droidfish/book/InternalBook.java @@ -41,7 +41,7 @@ final class InternalBook implements IOpeningBook { private boolean enabled = false; InternalBook() { - Thread t = new Thread(() -> initInternalBook()); + Thread t = new Thread(this::initInternalBook); t.setPriority(Thread.MIN_PRIORITY); t.start(); } diff --git a/DroidFishApp/src/main/java/org/petero/droidfish/engine/DroidComputerPlayer.java b/DroidFishApp/src/main/java/org/petero/droidfish/engine/DroidComputerPlayer.java index 9b89acf..f8efffc 100644 --- a/DroidFishApp/src/main/java/org/petero/droidfish/engine/DroidComputerPlayer.java +++ b/DroidFishApp/src/main/java/org/petero/droidfish/engine/DroidComputerPlayer.java @@ -1000,7 +1000,7 @@ public class DroidComputerPlayer { } if (havePvData) { while (statPvInfo.size() < pvNum) - statPvInfo.add(new PvInfo(0, 0, 0, 0, 0, 0, 0, 0, false, false, false, new ArrayList())); + statPvInfo.add(new PvInfo(0, 0, 0, 0, 0, 0, 0, 0, false, false, false, new ArrayList<>())); if (statPvInfo.size() == pvNum) statPvInfo.add(null); ArrayList moves = new ArrayList<>(); diff --git a/EngineServer/src/main/java/org/petero/engineserver/EngineServer.java b/EngineServer/src/main/java/org/petero/engineserver/EngineServer.java index 593d037..2601c06 100644 --- a/EngineServer/src/main/java/org/petero/engineserver/EngineServer.java +++ b/EngineServer/src/main/java/org/petero/engineserver/EngineServer.java @@ -62,8 +62,7 @@ public class EngineServer implements ErrorHandler { String arguments = prop.getProperty("arguments" + i, ""); configs[i] = new EngineConfig(enabled, port, filename, arguments); } - } catch (IOException ignore) { - } catch (NumberFormatException ignore) { + } catch (IOException | NumberFormatException ignore) { } }