Skip to content

Commit

Permalink
Added jetbrains notations to Skyscrapers
Browse files Browse the repository at this point in the history
  • Loading branch information
TreeSnowFence committed Jul 26, 2024
1 parent 745c3e5 commit 5f52703
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import edu.rpi.legup.model.gameboard.Board;
import edu.rpi.legup.model.gameboard.PuzzleElement;
import edu.rpi.legup.model.rules.ContradictionRule;
import org.jetbrains.annotations.Contract;

public class ShortTruthTable extends Puzzle {

Expand Down Expand Up @@ -39,6 +40,7 @@ public Board generatePuzzle(int difficulty) {
}

@Override
@Contract(pure = true)
/**
* Determines if the given dimensions are valid for Short Truth Table
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import edu.rpi.legup.model.gameboard.Board;
import edu.rpi.legup.model.gameboard.PuzzleElement;
import edu.rpi.legup.model.rules.ContradictionRule;
import org.jetbrains.annotations.Contract;

public class Skyscrapers extends Puzzle {

Expand Down Expand Up @@ -38,6 +39,7 @@ public Board generatePuzzle(int difficulty) {
}

@Override
@Contract(pure = true)
/**
* Determines if the given dimensions are valid for Skyscrapers
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

import edu.rpi.legup.model.elements.Element;
import edu.rpi.legup.model.gameboard.GridCell;
import org.jetbrains.annotations.Contract;

import java.awt.*;
import java.awt.event.MouseEvent;

Expand Down Expand Up @@ -56,6 +58,7 @@ public int getMax() {
}

@Override
@Contract(pure = true)
public SkyscrapersCell copy() {
SkyscrapersCell copy = new SkyscrapersCell(data, (Point) location.clone(), max);
copy.setIndex(index);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import edu.rpi.legup.model.gameboard.PuzzleElement;
import edu.rpi.legup.save.InvalidFileFormatException;
import java.awt.*;

import org.jetbrains.annotations.Contract;
import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
Expand All @@ -19,6 +21,7 @@ public class SkyscrapersCellFactory extends ElementFactory {
* @throws InvalidFileFormatException if input is invalid
*/
@Override
@Contract(pure = false)
public PuzzleElement importCell(Node node, Board board) throws InvalidFileFormatException {
try {
if (!node.getNodeName().equalsIgnoreCase("cell")) {
Expand Down Expand Up @@ -61,6 +64,7 @@ public PuzzleElement importCell(Node node, Board board) throws InvalidFileFormat
* @param puzzleElement PuzzleElement cell
* @return xml PuzzleElement
*/
@Contract(pure = false)
public org.w3c.dom.Element exportCell(Document document, PuzzleElement puzzleElement) {
org.w3c.dom.Element cellElement = document.createElement("cell");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import edu.rpi.legup.controller.ElementController;
import edu.rpi.legup.model.gameboard.PuzzleElement;
import org.jetbrains.annotations.Contract;

import java.awt.event.MouseEvent;

public class SkyscrapersController extends ElementController {
Expand All @@ -11,6 +13,7 @@ public SkyscrapersController() {
}

@Override
@Contract(pure = false)
public void changeCell(MouseEvent e, PuzzleElement element) {
SkyscrapersCell cell = (SkyscrapersCell) element;
if (e.getButton() == MouseEvent.BUTTON1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,21 @@

import edu.rpi.legup.ui.boardview.GridElementView;
import java.awt.*;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;

public class SkyscrapersElementView extends GridElementView {
private static final Font FONT = new Font("TimesRoman", Font.BOLD, 16);
private static final Color FONT_COLOR = new Color(0x212121);
private static final Color BORDER_COLOR = new Color(0x424242);
private static final Color BACKGROUND_COLOR = new Color(0xEEEEEE);

public SkyscrapersElementView(SkyscrapersCell cell) {
public SkyscrapersElementView(@NotNull SkyscrapersCell cell) {
super(cell);
}

@Override
@Contract (pure = true)
public void drawElement(Graphics2D graphics2D) {
graphics2D.setStroke(new BasicStroke(1));
graphics2D.setColor(BACKGROUND_COLOR);
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 edu.rpi.legup.model.gameboard.PuzzleElement;
import org.w3c.dom.Document;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;

public class SkyscrapersExporter extends PuzzleExporter {

public SkyscrapersExporter(Skyscrapers skyscrapers) {
public SkyscrapersExporter(@NotNull Skyscrapers skyscrapers) {
super(skyscrapers);
}

@Override
protected org.w3c.dom.Element createBoardElement(Document newDocument) {
@Contract (pure = true)
protected @NotNull org.w3c.dom.Element createBoardElement(@NotNull Document newDocument) {
SkyscrapersBoard board;
if (puzzle.getTree() != null) {
board = (SkyscrapersBoard) puzzle.getTree().getRootNode().getBoard();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,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 SkyscrapersImporter extends PuzzleImporter {
public SkyscrapersImporter(Skyscrapers skyscrapers) {
public SkyscrapersImporter(@NotNull Skyscrapers skyscrapers) {
super(skyscrapers);
}

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

@Override
@Contract(pure = true, value = "-> false")
public boolean acceptsTextInput() {
return false;
}
Expand All @@ -30,6 +34,7 @@ public boolean acceptsTextInput() {
* @throws RuntimeException if board can not be created
*/
@Override
@Contract(pure = false)
public void initializeBoard(int rows, int columns) {
// assert(rows == columns);
int size = rows;
Expand Down Expand Up @@ -74,7 +79,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 @@ -218,6 +224,7 @@ public void initializeBoard(Node node) throws InvalidFileFormatException {
}

@Override
@Contract(value = "_ -> fail", pure = false)
public void initializeBoard(String[] statements) throws UnsupportedOperationException {
throw new UnsupportedOperationException("Skyscrapers cannot accept text input");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.util.ArrayList;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.jetbrains.annotations.NotNull;

public class SkyscrapersView extends GridBoardView {
private static final Logger LOGGER = LogManager.getLogger(SkyscrapersView.class.getName());
Expand All @@ -19,7 +20,7 @@ public class SkyscrapersView extends GridBoardView {
private ArrayList<SkyscrapersClueView> southClues;
private ArrayList<SkyscrapersClueView> westClues;

public SkyscrapersView(SkyscrapersBoard board) {
public SkyscrapersView(@NotNull SkyscrapersBoard board) {
super(new BoardController(), new SkyscrapersController(), board.getDimension());

this.northClues = new ArrayList<>();
Expand Down

0 comments on commit 5f52703

Please sign in to comment.