package net.minecraft; import java.util.Collection; import java.util.Iterator; import java.util.Objects; import java.util.function.Function; import java.util.function.Supplier; import org.jspecify.annotations.Nullable; public class Optionull { @Deprecated public static T orElse(final @Nullable T t, final T defaultValue) { return Objects.requireNonNullElse(t, defaultValue); } public static @Nullable R map(final @Nullable T t, final Function map) { return t == null ? null : map.apply(t); } public static R mapOrDefault(final @Nullable T t, final Function map, final R defaultValue) { return t == null ? defaultValue : map.apply(t); } public static R mapOrElse(final @Nullable T t, final Function map, final Supplier elseSupplier) { return t == null ? elseSupplier.get() : map.apply(t); } public static @Nullable T first(final Collection collection) { Iterator iterator = collection.iterator(); return iterator.hasNext() ? iterator.next() : null; } public static T firstOrDefault(final Collection collection, final T defaultValue) { Iterator iterator = collection.iterator(); return iterator.hasNext() ? iterator.next() : defaultValue; } public static T firstOrElse(final Collection collection, final Supplier elseSupplier) { Iterator iterator = collection.iterator(); return iterator.hasNext() ? iterator.next() : elseSupplier.get(); } public static boolean isNullOrEmpty(final T @Nullable [] t) { return t == null || t.length == 0; } public static boolean isNullOrEmpty(final boolean @Nullable [] t) { return t == null || t.length == 0; } public static boolean isNullOrEmpty(final byte @Nullable [] t) { return t == null || t.length == 0; } public static boolean isNullOrEmpty(final char @Nullable [] t) { return t == null || t.length == 0; } public static boolean isNullOrEmpty(final short @Nullable [] t) { return t == null || t.length == 0; } public static boolean isNullOrEmpty(final int @Nullable [] t) { return t == null || t.length == 0; } public static boolean isNullOrEmpty(final long @Nullable [] t) { return t == null || t.length == 0; } public static boolean isNullOrEmpty(final float @Nullable [] t) { return t == null || t.length == 0; } public static boolean isNullOrEmpty(final double @Nullable [] t) { return t == null || t.length == 0; } }