Skip to content

Commit

Permalink
Added Jetbrains annotations to TreeTent
Browse files Browse the repository at this point in the history
  • Loading branch information
TreeSnowFence committed Aug 16, 2024
1 parent 27bca80 commit 9df483f
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 11 deletions.
10 changes: 8 additions & 2 deletions src/main/java/edu/rpi/legup/puzzle/treetent/TreeTent.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import edu.rpi.legup.model.gameboard.Board;
import edu.rpi.legup.model.gameboard.PuzzleElement;
import java.util.List;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;

public class TreeTent extends Puzzle {

Expand All @@ -20,6 +22,7 @@ public TreeTent() {

/** Initializes the game board. Called by the invoker of the class */
@Override
@Contract(pure = false)
public void initializeView() {
TreeTentBoard board = (TreeTentBoard) currentBoard;
boardView = new TreeTentView((TreeTentBoard) currentBoard);
Expand All @@ -33,6 +36,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 @@ -57,7 +61,8 @@ public boolean isValidDimensions(int rows, int columns) {
* @return true if board is valid, false otherwise
*/
@Override
public boolean isBoardComplete(Board board) {
@Contract(pure = true)
public boolean isBoardComplete(@NotNull Board board) {
return false;
}

Expand All @@ -67,7 +72,8 @@ 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) {}

/**
* @return if it is valid TreeTent puzzle must have same number of clues as the dimension size
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentCell.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import edu.rpi.legup.model.gameboard.GridCell;
import java.awt.*;
import java.awt.event.MouseEvent;
import org.jetbrains.annotations.Contract;

public class TreeTentCell extends GridCell<TreeTentType> {

Expand All @@ -15,6 +16,7 @@ public TreeTentType getType() {
return data;
}

@Contract(pure = true)
public int getValue() {
switch (data) {
case TREE:
Expand Down Expand Up @@ -46,6 +48,7 @@ public void setType(Element e, MouseEvent m) {
}

@Override
@Contract(pure = true)
public TreeTentCell copy() {
TreeTentCell copy = new TreeTentCell(data, (Point) location.clone());
copy.setIndex(index);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;

public class TreeTentCellFactory extends ElementFactory {
/**
Expand All @@ -19,7 +21,8 @@ public class TreeTentCellFactory extends ElementFactory {
* @throws InvalidFileFormatException if file is invalid
*/
@Override
public PuzzleElement importCell(Node node, Board board) throws InvalidFileFormatException {
@Contract(pure = false)
public PuzzleElement importCell(@NotNull Node node,@NotNull Board board) throws InvalidFileFormatException {
try {
TreeTentBoard treeTentBoard = (TreeTentBoard) board;
int width = treeTentBoard.getWidth();
Expand Down Expand Up @@ -75,7 +78,8 @@ public PuzzleElement importCell(Node node, Board board) throws InvalidFileFormat
* @param puzzleElement PuzzleElement cell
* @return xml PuzzleElement
*/
public org.w3c.dom.Element exportCell(Document document, PuzzleElement puzzleElement) {
@Contract(pure = false)
public org.w3c.dom.Element exportCell(@NotNull Document document,@NotNull PuzzleElement puzzleElement) {
if (puzzleElement instanceof TreeTentCell) {
org.w3c.dom.Element cellElement = document.createElement("cell");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import edu.rpi.legup.ui.proofeditorui.treeview.TreeView;
import edu.rpi.legup.ui.proofeditorui.treeview.TreeViewSelection;
import java.awt.event.MouseEvent;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;

public class TreeTentController extends ElementController {

Expand Down Expand Up @@ -113,7 +115,8 @@ public void mouseReleased(MouseEvent e) {
}

@Override
public void changeCell(MouseEvent e, PuzzleElement element) {
@Contract(pure = false)
public void changeCell(@NotNull MouseEvent e,@NotNull PuzzleElement element) {
TreeTentCell cell = (TreeTentCell) element;
if (e.getButton() == MouseEvent.BUTTON1) {
if (cell.getData() == TreeTentType.UNKNOWN) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import edu.rpi.legup.ui.boardview.GridElementView;
import java.awt.*;
import java.awt.geom.Rectangle2D;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;


public class TreeTentElementView extends GridElementView {
public TreeTentElementView(TreeTentCell cell) {
Expand All @@ -15,7 +18,8 @@ public TreeTentElementView(TreeTentCell cell) {
* @param graphics2D the frame to be drawn on
*/
@Override
public void drawElement(Graphics2D graphics2D) {
@Contract(pure = true)
public void drawElement(@NotNull Graphics2D graphics2D) {
TreeTentCell cell = (TreeTentCell) puzzleElement;
TreeTentType type = cell.getType();
graphics2D.setStroke(new BasicStroke(0));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
import edu.rpi.legup.model.PuzzleExporter;
import edu.rpi.legup.model.gameboard.PuzzleElement;
import org.w3c.dom.Document;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;

public class TreeTentExporter extends PuzzleExporter {

public TreeTentExporter(TreeTent treeTent) {
public TreeTentExporter(@NotNull TreeTent treeTent) {
super(treeTent);
}

Expand All @@ -17,7 +19,8 @@ public TreeTentExporter(TreeTent treeTent) {
* @return the new board element
*/
@Override
protected org.w3c.dom.Element createBoardElement(Document newDocument) {
@Contract(pure = true)
protected @NotNull org.w3c.dom.Element createBoardElement(@NotNull Document newDocument) {
TreeTentBoard board;
if (puzzle.getTree() != null) {
board = (TreeTentBoard) puzzle.getTree().getRootNode().getBoard();
Expand Down
13 changes: 10 additions & 3 deletions src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentImporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,22 @@
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 TreeTentImporter extends PuzzleImporter {
public TreeTentImporter(TreeTent treeTent) {
public TreeTentImporter(@NotNull TreeTent treeTent) {
super(treeTent);
}

@Override
@Contract(pure = true, value = "-> true")
public boolean acceptsRowsAndColumnsInput() {
return true;
}

@Override
@Contract(pure = true, value = "-> false")
public boolean acceptsTextInput() {
return false;
}
Expand All @@ -32,6 +36,7 @@ public boolean acceptsTextInput() {
* @throws RuntimeException if board can not be created
*/
@Override
@Contract(pure = false)
public void initializeBoard(int rows, int columns) {
TreeTentBoard treeTentBoard = new TreeTentBoard(columns, rows);

Expand Down Expand Up @@ -64,7 +69,8 @@ public void initializeBoard(int rows, int columns) {
* @throws InvalidFileFormatException if file is invalid
*/
@Override
public void initializeBoard(Node node) throws InvalidFileFormatException {
@Contract(pure = false)
public void initializeBoard(@NotNull Node node) throws InvalidFileFormatException {
try {
if (!node.getNodeName().equalsIgnoreCase("board")) {
throw new InvalidFileFormatException(
Expand Down Expand Up @@ -215,7 +221,8 @@ public void initializeBoard(Node node) throws InvalidFileFormatException {
}

@Override
public void initializeBoard(String[] statements) throws UnsupportedOperationException {
@Contract(value = "_ -> fail", pure = false)
public void initializeBoard( @NotNull String[] statements) throws UnsupportedOperationException {
throw new UnsupportedOperationException("Tree Tent cannot accept text input");
}

Expand Down

0 comments on commit 9df483f

Please sign in to comment.