fixes some code inspection issues

Mon, 27 Jul 2020 10:56:17 +0200

author
Mike Becker <universe@uap-core.de>
date
Mon, 27 Jul 2020 10:56:17 +0200
changeset 12
1c62c6009161
parent 11
f7433671fec5
child 13
5e69b1bb707f

fixes some code inspection issues

manifest.mf file | annotate | diff | comparison | revisions
src/main/java/de/uapcore/sudoku/ActionHandler.java file | annotate | diff | comparison | revisions
src/main/java/de/uapcore/sudoku/ButtonPanel.java file | annotate | diff | comparison | revisions
src/main/java/de/uapcore/sudoku/DocumentHandler.java file | annotate | diff | comparison | revisions
src/main/java/de/uapcore/sudoku/Field.java file | annotate | diff | comparison | revisions
src/main/java/de/uapcore/sudoku/MainMenu.java file | annotate | diff | comparison | revisions
src/main/java/de/uapcore/sudoku/Solver.java file | annotate | diff | comparison | revisions
src/main/java/de/uapcore/sudoku/SudokuTextField.java file | annotate | diff | comparison | revisions
     1.1 --- a/manifest.mf	Sat Jul 25 15:56:48 2020 +0200
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,3 +0,0 @@
     1.4 -Manifest-Version: 1.0
     1.5 -X-COMMENT: Main-Class will be added automatically by build
     1.6 -
     2.1 --- a/src/main/java/de/uapcore/sudoku/ActionHandler.java	Sat Jul 25 15:56:48 2020 +0200
     2.2 +++ b/src/main/java/de/uapcore/sudoku/ActionHandler.java	Mon Jul 27 10:56:17 2020 +0200
     2.3 @@ -47,9 +47,9 @@
     2.4      public static final String QUIT = "quit";
     2.5      public static final String ABOUT = "about";
     2.6  
     2.7 -    private Field field;
     2.8 -    private Solver solver;
     2.9 -    private DocumentHandler doc;
    2.10 +    private final Field field;
    2.11 +    private final Solver solver;
    2.12 +    private final DocumentHandler doc;
    2.13  
    2.14      /**
    2.15       * Constructs a new action handler instance.
     3.1 --- a/src/main/java/de/uapcore/sudoku/ButtonPanel.java	Sat Jul 25 15:56:48 2020 +0200
     3.2 +++ b/src/main/java/de/uapcore/sudoku/ButtonPanel.java	Mon Jul 27 10:56:17 2020 +0200
     3.3 @@ -34,7 +34,7 @@
     3.4   */
     3.5  public final class ButtonPanel extends JPanel {
     3.6      
     3.7 -    private JButton save, check, solve;
     3.8 +    private final JButton save, check, solve;
     3.9  
    3.10      public ButtonPanel(ActionHandler l) {
    3.11          setLayout(new GridBagLayout());
     4.1 --- a/src/main/java/de/uapcore/sudoku/DocumentHandler.java	Sat Jul 25 15:56:48 2020 +0200
     4.2 +++ b/src/main/java/de/uapcore/sudoku/DocumentHandler.java	Mon Jul 27 10:56:17 2020 +0200
     4.3 @@ -59,13 +59,13 @@
     4.4                  }
     4.5                  Matcher m = pat.matcher(line);
     4.6                  if (m.matches()) {
     4.7 -                    String c[] = line.trim().split(" ");
     4.8 +                    String[] c = line.trim().split(" ");
     4.9                      if (c.length != 9) {
    4.10                          break;
    4.11                      }
    4.12                      for (int i = 0 ; i < 9 ; i++) {
    4.13                          field.setCellValue(i, row,
    4.14 -                                c[i].equals("_") ? 0 : Integer.valueOf(c[i]));
    4.15 +                                c[i].equals("_") ? 0 : Integer.parseInt(c[i]));
    4.16                      }
    4.17                      row++;
    4.18                  } else {
     5.1 --- a/src/main/java/de/uapcore/sudoku/Field.java	Sat Jul 25 15:56:48 2020 +0200
     5.2 +++ b/src/main/java/de/uapcore/sudoku/Field.java	Mon Jul 27 10:56:17 2020 +0200
     5.3 @@ -36,7 +36,7 @@
     5.4   * Cells are identified by zero-based indices from top-left to bottom-right.
     5.5   */
     5.6  public final class Field extends JPanel {
     5.7 -    private SudokuTextField[][] cells;
     5.8 +    private final SudokuTextField[][] cells;
     5.9  
    5.10      /**
    5.11       * Constructs a new 9x9 Sudoku grid.
    5.12 @@ -124,6 +124,7 @@
    5.13       * @param x horizontal position
    5.14       * @param y vertical position
    5.15       * @param v the cells value
    5.16 +     * @throws IllegalArgumentException if v is not between 0 and 9
    5.17       */
    5.18      public void setCellValue(int x, int y, int v) {
    5.19          cells[x][y].setValue(v);
    5.20 @@ -198,6 +199,7 @@
    5.21       * @param x horizontal position from 0 to 2
    5.22       * @param y vertical position from 0 to 2
    5.23       * @return a two-dimensional array containing the square cell values
    5.24 +     * @throws IllegalArgumentException if the coordinates are out of bounds
    5.25       */
    5.26      public int[][] getSquare(int x, int y) {
    5.27          if (x < 0 || x > 2 || y < 0 || y > 2) {
    5.28 @@ -219,12 +221,13 @@
    5.29       *
    5.30       * @param y the row position
    5.31       * @return an array containing the row values
    5.32 +     * @throws IllegalArgumentException if y is not between 0 and 8
    5.33       */
    5.34      public int[] getRow(int y) {
    5.35          if (y < 0 || y > 8) {
    5.36              throw new IllegalArgumentException("Invalid row number");
    5.37          }
    5.38 -        int row[] = new int[9];
    5.39 +        int[] row = new int[9];
    5.40  
    5.41          for (int x = 0; x < 9; x++) {
    5.42              row[x] = getCellValue(x, y);
    5.43 @@ -238,12 +241,13 @@
    5.44       *
    5.45       * @param x the column position
    5.46       * @return an array containing the column values
    5.47 +     * @throws IllegalArgumentException if x is not between 0 and 8
    5.48       */
    5.49      public int[] getColumn(int x) {
    5.50          if (x < 0 || x > 8) {
    5.51              throw new IllegalArgumentException("Invalid column number");
    5.52          }
    5.53 -        int column[] = new int[9];
    5.54 +        int[] column = new int[9];
    5.55  
    5.56          for (int y = 0; y < 9; y++) {
    5.57              column[y] = getCellValue(x, y);
     6.1 --- a/src/main/java/de/uapcore/sudoku/MainMenu.java	Sat Jul 25 15:56:48 2020 +0200
     6.2 +++ b/src/main/java/de/uapcore/sudoku/MainMenu.java	Mon Jul 27 10:56:17 2020 +0200
     6.3 @@ -33,8 +33,8 @@
     6.4   */
     6.5  public class MainMenu {
     6.6      
     6.7 -    private ActionHandler handler;
     6.8 -    private JMenuBar menuBar;
     6.9 +    private final ActionHandler handler;
    6.10 +    private final JMenuBar menuBar;
    6.11      
    6.12      public MainMenu(ActionHandler h) {
    6.13          handler = h;
     7.1 --- a/src/main/java/de/uapcore/sudoku/Solver.java	Sat Jul 25 15:56:48 2020 +0200
     7.2 +++ b/src/main/java/de/uapcore/sudoku/Solver.java	Mon Jul 27 10:56:17 2020 +0200
     7.3 @@ -148,7 +148,7 @@
     7.4      public boolean solve(Field f) {
     7.5          
     7.6          // Calculate initial candidates
     7.7 -        List<Integer> candidates[][] = new List[9][9];
     7.8 +        List<Integer>[][] candidates = new List[9][9];
     7.9          for (int x = 0 ; x < 9 ; x++) {
    7.10              for (int y = 0 ; y < 9 ; y++) {
    7.11                  candidates[x][y] = new ArrayList<>(9);
    7.12 @@ -189,7 +189,7 @@
    7.13       * @return true, if the check succeeds, false otherwise
    7.14       */
    7.15      public boolean check(Field f) {
    7.16 -        int line[];
    7.17 +        int[] line;
    7.18          for (int i = 0 ; i < 9 ; i++) {
    7.19              line = f.getRow(i);
    7.20              if (!valid(line)) {
    7.21 @@ -201,7 +201,7 @@
    7.22              }
    7.23          }
    7.24          
    7.25 -        int square[][];
    7.26 +        int[][] square;
    7.27          for (int x = 0 ; x < 3 ; x++) {
    7.28              for (int y = 0 ; y < 3 ; y++) {
    7.29                  square = f.getSquare(x, y);
    7.30 @@ -215,7 +215,7 @@
    7.31      }
    7.32      
    7.33      private boolean valid(int[] line) {
    7.34 -        int numbers[];
    7.35 +        int[] numbers;
    7.36          numbers = new int[9];
    7.37          for (int i = 0 ; i < 9 ; i++) {
    7.38              int l = line[i]-1;
     8.1 --- a/src/main/java/de/uapcore/sudoku/SudokuTextField.java	Sat Jul 25 15:56:48 2020 +0200
     8.2 +++ b/src/main/java/de/uapcore/sudoku/SudokuTextField.java	Mon Jul 27 10:56:17 2020 +0200
     8.3 @@ -114,7 +114,7 @@
     8.4          if (getText().isEmpty()) {
     8.5              return 0;
     8.6          } else {
     8.7 -            return Integer.valueOf(getText());
     8.8 +            return Integer.parseInt(getText());
     8.9          }
    8.10      }
    8.11  
    8.12 @@ -122,6 +122,7 @@
    8.13       * Sets the field's value.
    8.14       *
    8.15       * @param v the number from 1 to 9 or zero to clear the field
    8.16 +     * @throws IllegalArgumentException if v is not between 0 and 9
    8.17       */
    8.18      public void setValue(int v) {
    8.19          if (v == 0) {

mercurial