Skip to content

Commit

Permalink
add annotations and excecptions
Browse files Browse the repository at this point in the history
  • Loading branch information
Snabeldier committed Feb 5, 2025
1 parent 1b8eb9a commit 2b743f4
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions src/main/java/minevalley/core/api/utils/Hologram.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import minevalley.core.api.modifiers.LocationModifier;
import minevalley.core.api.modifiers.VisibilityModifier;

import javax.annotation.Nonnegative;
import javax.annotation.Nonnull;

@SuppressWarnings("unused")
public interface Hologram extends LocationModifier, VisibilityModifier {

Expand All @@ -11,24 +14,28 @@ public interface Hologram extends LocationModifier, VisibilityModifier {
*
* @return the lines of the hologram.
*/
@Nonnull
String[] getLines();

/**
* Returns the line at the specified index.
*
* @param line the index of the line.
* @return the line at the specified index.
* @throws IndexOutOfBoundsException if the line is out of bounds.
*/
default String getLine(int line) {
default String getLine(@Nonnegative int line) throws IndexOutOfBoundsException {
return getLines()[line];
}

/**
* Adds a line to the hologram.
*
* @param text the text of the line.
* @throws IllegalArgumentException if the text is null.
*/
default void addLine(String text) {
default void addLine(@Nonnull String text) throws IllegalArgumentException {
if (text == null) throw new IllegalArgumentException("The text cannot be null.");
addLineAfter(getLines().length - 1, text);
}

Expand All @@ -37,21 +44,26 @@ default void addLine(String text) {
*
* @param line the index of the line.
* @param text the text of the line.
* @throws IndexOutOfBoundsException if the line is out of bounds.
* @throws IllegalArgumentException if the text is null.
*/
void addLineAfter(int line, String text);
void addLineAfter(@Nonnegative int line, @Nonnull String text) throws IndexOutOfBoundsException, IllegalArgumentException;

/**
* Changes the line at the specified index.
*
* @param line the index of the line.
* @param text the new text of the line.
* @throws IndexOutOfBoundsException if the line is out of bounds.
* @throws IllegalArgumentException if the text is null.
*/
void changeLine(int line, String text);
void changeLine(@Nonnegative int line, @Nonnull String text) throws IndexOutOfBoundsException, IllegalArgumentException;

/**
* Removes the line at the specified index.
*
* @param line the index of the line.
* @throws IndexOutOfBoundsException if the line is out of bounds.
*/
void removeLine(int line);
void removeLine(@Nonnegative int line) throws IndexOutOfBoundsException;
}

0 comments on commit 2b743f4

Please sign in to comment.