Skip to content

Commit

Permalink
Added Jetbrains Annotations to Thermometer
Browse files Browse the repository at this point in the history
  • Loading branch information
TreeSnowFence committed Aug 10, 2024
1 parent 14dcf9c commit 27bca80
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 9 deletions.
10 changes: 8 additions & 2 deletions src/main/java/edu/rpi/legup/puzzle/thermometer/Thermometer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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);
Expand All @@ -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;
}
Expand All @@ -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;
}

Expand All @@ -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) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<Integer> {

Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,28 @@
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 {

// mixture of stuff stolen from tree tent and dev guide
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 27bca80

Please sign in to comment.