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(@Nullable final T t, final T defaultValue) { return (T)Objects.requireNonNullElse(t, defaultValue); } @Nullable public static R map(@Nullable final T t, final Function map) { return (R)(t == null ? null : map.apply(t)); } public static R mapOrDefault(@Nullable final T t, final Function map, final R defaultValue) { return (R)(t == null ? defaultValue : map.apply(t)); } public static R mapOrElse(@Nullable final T t, final Function map, final Supplier elseSupplier) { return (R)(t == null ? elseSupplier.get() : map.apply(t)); } @Nullable public static T first(final Collection collection) { Iterator iterator = collection.iterator(); return (T)(iterator.hasNext() ? iterator.next() : null); } public static T firstOrDefault(final Collection collection, final T defaultValue) { Iterator iterator = collection.iterator(); return (T)(iterator.hasNext() ? iterator.next() : defaultValue); } public static T firstOrElse(final Collection collection, final Supplier elseSupplier) { Iterator iterator = collection.iterator(); return (T)(iterator.hasNext() ? iterator.next() : elseSupplier.get()); } public static boolean isNullOrEmpty(@Nullable final T[] t) { return t == null || t.length == 0; } public static boolean isNullOrEmpty(@Nullable final boolean[] t) { return t == null || t.length == 0; } public static boolean isNullOrEmpty(@Nullable final byte[] t) { return t == null || t.length == 0; } public static boolean isNullOrEmpty(@Nullable final char[] t) { return t == null || t.length == 0; } public static boolean isNullOrEmpty(@Nullable final short[] t) { return t == null || t.length == 0; } public static boolean isNullOrEmpty(@Nullable final int[] t) { return t == null || t.length == 0; } public static boolean isNullOrEmpty(@Nullable final long[] t) { return t == null || t.length == 0; } public static boolean isNullOrEmpty(@Nullable final float[] t) { return t == null || t.length == 0; } public static boolean isNullOrEmpty(@Nullable final double[] t) { return t == null || t.length == 0; } }