Add more annotations

This commit is contained in:
filoghost 2020-10-13 16:41:05 +02:00
parent 724708af00
commit 2dfecfb3a2
7 changed files with 24 additions and 18 deletions

View File

@ -5,6 +5,8 @@
*/
package me.filoghost.chestcommands.inventory;
import org.jetbrains.annotations.Nullable;
public class ArrayGrid<T> extends Grid<T> {
private final T[] elements;
@ -16,12 +18,12 @@ public class ArrayGrid<T> extends Grid<T> {
}
@Override
protected T getByIndex0(int ordinalIndex) {
protected @Nullable T getByIndex0(int ordinalIndex) {
return elements[ordinalIndex];
}
@Override
protected void setByIndex0(int ordinalIndex, T element) {
protected void setByIndex0(int ordinalIndex, @Nullable T element) {
elements[ordinalIndex] = element;
}

View File

@ -12,6 +12,7 @@ import me.filoghost.chestcommands.menu.BaseMenu;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* Represents a particular view of a menu.
@ -22,7 +23,7 @@ public class DefaultMenuView implements MenuView {
private final Player viewer;
private final InventoryGrid bukkitInventory;
public DefaultMenuView(BaseMenu menu, Player viewer) {
public DefaultMenuView(@NotNull BaseMenu menu, @NotNull Player viewer) {
this.menu = menu;
this.viewer = viewer;
this.bukkitInventory = new InventoryGrid(new MenuInventoryHolder(this), menu.getRowCount(), menu.getTitle());
@ -49,7 +50,7 @@ public class DefaultMenuView implements MenuView {
viewer.openInventory(bukkitInventory.getInventory());
}
public Icon getIcon(int slot) {
public @Nullable Icon getIcon(int slot) {
if (slot < 0 || slot >= bukkitInventory.getSize()) {
return null;
}

View File

@ -6,6 +6,7 @@
package me.filoghost.chestcommands.inventory;
import me.filoghost.fcommons.Preconditions;
import org.jetbrains.annotations.Nullable;
/*
* Example:
@ -33,28 +34,28 @@ public abstract class Grid<T> {
this.size = rows * columns;
}
public final void set(int row, int column, T element) {
public final void set(int row, int column, @Nullable T element) {
setByIndex(toOrdinalIndex(row, column), element);
}
public final T get(int row, int column) {
public final @Nullable T get(int row, int column) {
return getByIndex(toOrdinalIndex(row, column));
}
public final T getByIndex(int ordinalIndex) {
public final @Nullable T getByIndex(int ordinalIndex) {
Preconditions.checkIndex(ordinalIndex, getSize(), "ordinalIndex");
return getByIndex0(ordinalIndex);
}
protected abstract T getByIndex0(int ordinalIndex);
protected abstract @Nullable T getByIndex0(int ordinalIndex);
public final void setByIndex(int ordinalIndex, T element) {
public final void setByIndex(int ordinalIndex, @Nullable T element) {
Preconditions.checkIndex(ordinalIndex, getSize(), "ordinalIndex");
setByIndex0(ordinalIndex, element);
}
protected abstract void setByIndex0(int ordinalIndex, T element);
protected abstract void setByIndex0(int ordinalIndex, @Nullable T element);
private int toOrdinalIndex(int row, int column) {
Preconditions.checkIndex(row, getRows(), "row");

View File

@ -8,6 +8,7 @@ package me.filoghost.chestcommands.inventory;
import org.bukkit.Bukkit;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.Nullable;
public class InventoryGrid extends Grid<ItemStack> {
@ -23,12 +24,12 @@ public class InventoryGrid extends Grid<ItemStack> {
}
@Override
protected ItemStack getByIndex0(int ordinalIndex) {
protected @Nullable ItemStack getByIndex0(int ordinalIndex) {
return inventory.getItem(ordinalIndex);
}
@Override
protected void setByIndex0(int ordinalIndex, ItemStack element) {
protected void setByIndex0(int ordinalIndex, @Nullable ItemStack element) {
inventory.setItem(ordinalIndex, element);
}

View File

@ -7,18 +7,19 @@ package me.filoghost.chestcommands.menu;
import me.filoghost.fcommons.Preconditions;
import org.bukkit.plugin.Plugin;
import org.jetbrains.annotations.NotNull;
public class APIMenu extends BaseMenu {
private final Plugin owner;
public APIMenu(Plugin owner, String title, int rows) {
public APIMenu(@NotNull Plugin owner, @NotNull String title, int rows) {
super(title, rows);
Preconditions.notNull(owner, "owner");
this.owner = owner;
}
public Plugin getOwner() {
public @NotNull Plugin getOwner() {
return owner;
}

View File

@ -24,7 +24,7 @@ public abstract class BaseMenu implements Menu {
private final Grid<Icon> icons;
public BaseMenu(String title, int rows) {
public BaseMenu(@NotNull String title, int rows) {
Preconditions.notNull(title, "title");
Preconditions.checkArgument(rows > 0, "rows must be greater than 0");
this.title = title;
@ -56,7 +56,7 @@ public abstract class BaseMenu implements Menu {
return title;
}
public Grid<Icon> getIcons() {
public @NotNull Grid<Icon> getIcons() {
return icons;
}

View File

@ -26,13 +26,13 @@ public class InternalMenu extends BaseMenu {
private ImmutableList<Action> openActions;
private int refreshTicks;
public InternalMenu(String title, int rows, Path sourceFile) {
public InternalMenu(@NotNull String title, int rows, @NotNull Path sourceFile) {
super(title, rows);
this.sourceFile = sourceFile;
this.openPermission = Permissions.OPEN_MENU_PREFIX + sourceFile.getFileName();
}
public Path getSourceFile() {
public @NotNull Path getSourceFile() {
return sourceFile;
}