From 036ede6ccf7c20226ae5f1f9e5b4950602e9e92d Mon Sep 17 00:00:00 2001 From: Rime <81419447+Emirlol@users.noreply.github.com> Date: Sat, 27 Jul 2024 12:00:30 +0300 Subject: Add more documentation to SlotText.java --- .../skyblock/item/slottext/SlotText.java | 38 +++++++++++++++++----- 1 file changed, 29 insertions(+), 9 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/SlotText.java b/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/SlotText.java index 73224509..43960c9c 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/SlotText.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/SlotText.java @@ -2,39 +2,59 @@ package de.hysky.skyblocker.skyblock.item.slottext; import it.unimi.dsi.fastutil.objects.ObjectLists; import net.minecraft.text.Text; +import org.jetbrains.annotations.NotNull; import java.util.List; -public record SlotText(Text text, TextPosition position) { - public static SlotText bottomLeft(Text text) { +public record SlotText(@NotNull Text text, @NotNull TextPosition position) { + public static SlotText bottomLeft(@NotNull Text text) { return new SlotText(text, TextPosition.BOTTOM_LEFT); } - public static SlotText bottomRight(Text text) { + public static SlotText bottomRight(@NotNull Text text) { return new SlotText(text, TextPosition.BOTTOM_RIGHT); } - public static SlotText topLeft(Text text) { + public static SlotText topLeft(@NotNull Text text) { return new SlotText(text, TextPosition.TOP_LEFT); } - public static SlotText topRight(Text text) { + public static SlotText topRight(@NotNull Text text) { return new SlotText(text, TextPosition.TOP_RIGHT); } - public static List topLeftList(Text text) { + // The methods below use ObjectLists.singleton rather than List.of because List.of + // has 1 more method call (a null check) and 1 more field set for no good reason. + + /** + * Convenience method for creating a singleton list containing this SlotText. Useful for returning a single SlotText from a method that returns a list. + * @return A singleton list containing a SlotText with the {@link TextPosition#TOP_LEFT top left} position and the given text. + */ + public static List topLeftList(@NotNull Text text) { return ObjectLists.singleton(topLeft(text)); } - public static List topRightList(Text text) { + /** + * Convenience method for creating a singleton list containing this SlotText. Useful for returning a single SlotText from a method that returns a list. + * @return A singleton list containing a SlotText with the {@link TextPosition#TOP_RIGHT top right} position and the given text. + */ + public static List topRightList(@NotNull Text text) { return ObjectLists.singleton(topRight(text)); } - public static List bottomLeftList(Text text) { + /** + * Convenience method for creating a singleton list containing this SlotText. Useful for returning a single SlotText from a method that returns a list. + * @return A singleton list containing a SlotText with the {@link TextPosition#BOTTOM_LEFT bottom left} position and the given text. + */ + public static List bottomLeftList(@NotNull Text text) { return ObjectLists.singleton(bottomLeft(text)); } - public static List bottomRightList(Text text) { + /** + * Convenience method for creating a singleton list containing this SlotText. Useful for returning a single SlotText from a method that returns a list. + * @return A singleton list containing a SlotText with the {@link TextPosition#BOTTOM_RIGHT bottom right} position and the given text. + */ + public static List bottomRightList(@NotNull Text text) { return ObjectLists.singleton(bottomRight(text)); } } -- cgit