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