Skip to content

Commit d18cb88

Browse files
authored
chore: add a lot of exception throwing and parameter checking to hologram (#300)
1 parent 1b8eb9a commit d18cb88

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

src/main/java/minevalley/core/api/utils/Hologram.java

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
import minevalley.core.api.modifiers.LocationModifier;
44
import minevalley.core.api.modifiers.VisibilityModifier;
5+
import org.jetbrains.annotations.Contract;
6+
7+
import javax.annotation.Nonnegative;
8+
import javax.annotation.Nonnull;
59

610
@SuppressWarnings("unused")
711
public interface Hologram extends LocationModifier, VisibilityModifier {
@@ -11,24 +15,30 @@ public interface Hologram extends LocationModifier, VisibilityModifier {
1115
*
1216
* @return the lines of the hologram.
1317
*/
18+
@Nonnull
19+
@Contract(pure = true)
1420
String[] getLines();
1521

1622
/**
1723
* Returns the line at the specified index.
1824
*
1925
* @param line the index of the line.
2026
* @return the line at the specified index.
27+
* @throws IndexOutOfBoundsException if the line is out of bounds.
2128
*/
22-
default String getLine(int line) {
29+
@Contract(pure = true)
30+
default String getLine(@Nonnegative int line) throws IndexOutOfBoundsException {
2331
return getLines()[line];
2432
}
2533

2634
/**
2735
* Adds a line to the hologram.
2836
*
2937
* @param text the text of the line.
38+
* @throws IllegalArgumentException if the text is null.
3039
*/
31-
default void addLine(String text) {
40+
default void addLine(@Nonnull String text) throws IllegalArgumentException {
41+
if (text == null) throw new IllegalArgumentException("The text cannot be null.");
3242
addLineAfter(getLines().length - 1, text);
3343
}
3444

@@ -37,21 +47,26 @@ default void addLine(String text) {
3747
*
3848
* @param line the index of the line.
3949
* @param text the text of the line.
50+
* @throws IndexOutOfBoundsException if the line is out of bounds.
51+
* @throws IllegalArgumentException if the text is null.
4052
*/
41-
void addLineAfter(int line, String text);
53+
void addLineAfter(@Nonnegative int line, @Nonnull String text) throws IndexOutOfBoundsException, IllegalArgumentException;
4254

4355
/**
4456
* Changes the line at the specified index.
4557
*
4658
* @param line the index of the line.
4759
* @param text the new text of the line.
60+
* @throws IndexOutOfBoundsException if the line is out of bounds.
61+
* @throws IllegalArgumentException if the text is null.
4862
*/
49-
void changeLine(int line, String text);
63+
void changeLine(@Nonnegative int line, @Nonnull String text) throws IndexOutOfBoundsException, IllegalArgumentException;
5064

5165
/**
5266
* Removes the line at the specified index.
5367
*
5468
* @param line the index of the line.
69+
* @throws IndexOutOfBoundsException if the line is out of bounds.
5570
*/
56-
void removeLine(int line);
71+
void removeLine(@Nonnegative int line) throws IndexOutOfBoundsException;
5772
}

0 commit comments

Comments
 (0)