From 27bca802504450f9e7977de05fa2e2ca84507faa Mon Sep 17 00:00:00 2001 From: TreeSnowFence <139384610+TreeSnowFence@users.noreply.github.com> Date: Fri, 9 Aug 2024 23:14:59 -0400 Subject: [PATCH] Added Jetbrains Annotations to Thermometer --- .../edu/rpi/legup/puzzle/thermometer/Thermometer.java | 10 ++++++++-- .../rpi/legup/puzzle/thermometer/ThermometerCell.java | 2 ++ .../puzzle/thermometer/ThermometerController.java | 2 ++ .../puzzle/thermometer/ThermometerElementView.java | 7 +++++-- .../legup/puzzle/thermometer/ThermometerExporter.java | 7 +++++-- .../legup/puzzle/thermometer/ThermometerImporter.java | 11 +++++++++-- .../rpi/legup/puzzle/thermometer/ThermometerView.java | 3 ++- 7 files changed, 33 insertions(+), 9 deletions(-) diff --git a/src/main/java/edu/rpi/legup/puzzle/thermometer/Thermometer.java b/src/main/java/edu/rpi/legup/puzzle/thermometer/Thermometer.java index 8138104f5..faa1a63aa 100644 --- a/src/main/java/edu/rpi/legup/puzzle/thermometer/Thermometer.java +++ b/src/main/java/edu/rpi/legup/puzzle/thermometer/Thermometer.java @@ -2,6 +2,8 @@ import edu.rpi.legup.model.Puzzle; import edu.rpi.legup.model.gameboard.Board; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; // basically just copy-pasted from dev guide on wiki public class Thermometer extends Puzzle { @@ -18,6 +20,7 @@ public Thermometer() { /** Initializes the game board. Called by the invoker of the class */ @Override + @Contract(pure = false) public void initializeView() { boardView = new ThermometerView((ThermometerBoard) currentBoard); boardView.setBoard(currentBoard); @@ -31,6 +34,7 @@ public void initializeView() { * @return board of the random edu.rpi.legup.puzzle */ @Override + @Contract("_ -> null") public Board generatePuzzle(int difficulty) { return null; } @@ -42,7 +46,8 @@ public Board generatePuzzle(int difficulty) { * @return true if board is valid, false otherwise */ @Override - public boolean isBoardComplete(Board board) { + @Contract(pure = true) + public boolean isBoardComplete(@NotNull Board board) { return true; } @@ -52,5 +57,6 @@ public boolean isBoardComplete(Board board) { * @param board the board that has changed */ @Override - public void onBoardChange(Board board) {} + @Contract(pure = true) + public void onBoardChange(@NotNull Board board) {} } diff --git a/src/main/java/edu/rpi/legup/puzzle/thermometer/ThermometerCell.java b/src/main/java/edu/rpi/legup/puzzle/thermometer/ThermometerCell.java index 175a455b4..52540f27e 100644 --- a/src/main/java/edu/rpi/legup/puzzle/thermometer/ThermometerCell.java +++ b/src/main/java/edu/rpi/legup/puzzle/thermometer/ThermometerCell.java @@ -2,6 +2,7 @@ import edu.rpi.legup.model.gameboard.GridCell; import java.awt.Point; +import org.jetbrains.annotations.Contract; public class ThermometerCell extends GridCell { @@ -44,6 +45,7 @@ public int getRotation() { } @Override + @Contract(pure = true) public ThermometerCell copy() { ThermometerCell copy = new ThermometerCell((Point) location.clone(), this.type, this.fill, this.rotation); diff --git a/src/main/java/edu/rpi/legup/puzzle/thermometer/ThermometerController.java b/src/main/java/edu/rpi/legup/puzzle/thermometer/ThermometerController.java index cd2135bd7..2b2e1597c 100644 --- a/src/main/java/edu/rpi/legup/puzzle/thermometer/ThermometerController.java +++ b/src/main/java/edu/rpi/legup/puzzle/thermometer/ThermometerController.java @@ -3,12 +3,14 @@ import edu.rpi.legup.controller.ElementController; import edu.rpi.legup.model.gameboard.PuzzleElement; import java.awt.event.MouseEvent; +import org.jetbrains.annotations.Contract; public class ThermometerController extends ElementController { // method for updating thermometer cells since number cells have unknown for // their fill type we don't need to worry about end user modifying them with this @Override + @Contract(pure = false) public void changeCell(MouseEvent e, PuzzleElement data) { ThermometerCell cell = (ThermometerCell) data; diff --git a/src/main/java/edu/rpi/legup/puzzle/thermometer/ThermometerElementView.java b/src/main/java/edu/rpi/legup/puzzle/thermometer/ThermometerElementView.java index 0657e95b0..3dbbfbfb4 100644 --- a/src/main/java/edu/rpi/legup/puzzle/thermometer/ThermometerElementView.java +++ b/src/main/java/edu/rpi/legup/puzzle/thermometer/ThermometerElementView.java @@ -4,6 +4,8 @@ import java.awt.*; import java.io.IOException; import javax.imageio.ImageIO; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; public class ThermometerElementView extends GridElementView { @@ -11,18 +13,19 @@ public class ThermometerElementView extends GridElementView { private static final Font FONT = new Font("TimesRoman", Font.BOLD, 16); private static final Color FONT_COLOR = Color.BLACK; - public ThermometerElementView(ThermometerCell cell) { + public ThermometerElementView(@NotNull ThermometerCell cell) { super(cell); } @Override - public ThermometerCell getPuzzleElement() { + public @NotNull ThermometerCell getPuzzleElement() { return (ThermometerCell) super.getPuzzleElement(); } // method for drawing a thermometer cell // basically copy/pasted from tree tent drawing tent images @Override + @Contract(pure = true) public void drawElement(Graphics2D graphics2D) { ThermometerCell cell = (ThermometerCell) puzzleElement; diff --git a/src/main/java/edu/rpi/legup/puzzle/thermometer/ThermometerExporter.java b/src/main/java/edu/rpi/legup/puzzle/thermometer/ThermometerExporter.java index d4e6dbd39..bbbb1bcfa 100644 --- a/src/main/java/edu/rpi/legup/puzzle/thermometer/ThermometerExporter.java +++ b/src/main/java/edu/rpi/legup/puzzle/thermometer/ThermometerExporter.java @@ -3,15 +3,18 @@ import edu.rpi.legup.model.PuzzleExporter; import java.util.ArrayList; import org.w3c.dom.Document; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; public class ThermometerExporter extends PuzzleExporter { - public ThermometerExporter(Thermometer thermometer) { + public ThermometerExporter(@NotNull Thermometer thermometer) { super(thermometer); } @Override - protected org.w3c.dom.Element createBoardElement(Document newDocument) { + @Contract(pure = true) + protected @NotNull org.w3c.dom.Element createBoardElement(@NotNull Document newDocument) { ThermometerBoard board = (ThermometerBoard) puzzle.getTree().getRootNode().getBoard(); // Creating the XML section for the board diff --git a/src/main/java/edu/rpi/legup/puzzle/thermometer/ThermometerImporter.java b/src/main/java/edu/rpi/legup/puzzle/thermometer/ThermometerImporter.java index 711418d63..c75b2ad0c 100644 --- a/src/main/java/edu/rpi/legup/puzzle/thermometer/ThermometerImporter.java +++ b/src/main/java/edu/rpi/legup/puzzle/thermometer/ThermometerImporter.java @@ -8,31 +8,37 @@ import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; public class ThermometerImporter extends PuzzleImporter { // basic stuff stolen from dev guide/filled in by default - public ThermometerImporter(Thermometer thermometer) { + public ThermometerImporter(@NotNull Thermometer thermometer) { super(thermometer); } @Override + @Contract(pure = true, value = "-> false") public boolean acceptsRowsAndColumnsInput() { return false; } @Override + @Contract(pure = true, value = "-> false") public boolean acceptsTextInput() { return false; } @Override + @Contract (pure = false) public void initializeBoard(int rows, int columns) {} // method for initializing board from an xml file which has // a provided width/height @Override - public void initializeBoard(Node node) throws InvalidFileFormatException { + @Contract (pure = false) + public void initializeBoard(@NotNull Node node) throws InvalidFileFormatException { // sticking everything in a try statement because god has forsaken everyone try { // checking basic formatting of file @@ -120,6 +126,7 @@ public void initializeBoard(Node node) throws InvalidFileFormatException { } @Override + @Contract(value = "_ -> fail", pure = false) public void initializeBoard(String[] statements) throws UnsupportedOperationException, IllegalArgumentException {} diff --git a/src/main/java/edu/rpi/legup/puzzle/thermometer/ThermometerView.java b/src/main/java/edu/rpi/legup/puzzle/thermometer/ThermometerView.java index 444037cfe..b8aa98734 100644 --- a/src/main/java/edu/rpi/legup/puzzle/thermometer/ThermometerView.java +++ b/src/main/java/edu/rpi/legup/puzzle/thermometer/ThermometerView.java @@ -3,10 +3,11 @@ import edu.rpi.legup.controller.BoardController; import edu.rpi.legup.ui.boardview.GridBoardView; import java.awt.*; +import org.jetbrains.annotations.NotNull; public class ThermometerView extends GridBoardView { - public ThermometerView(ThermometerBoard board) { + public ThermometerView(@NotNull ThermometerBoard board) { super(new BoardController(), new ThermometerController(), board.getDimension()); // loop for displaying the vial cells