Optionull .java

net.minecraft.Optionull (class): members: firstOrDefault, mapOrDefault, firstOrElse, mapOrElse, isNullOrEmpty, orElse, first, map. imports: Nullable.

net.minecraftclass79 linescommon2.4 KB

API Surface (14)

<T> T orElse(final @Nullable T t, final T defaultValue)
<T, R> R mapOrDefault(final @Nullable T t, final Function<T, R> map, final R defaultValue)
<T, R> R mapOrElse(final @Nullable T t, final Function<T, R> map, final Supplier<R> elseSupplier)
<T> T firstOrDefault(final Collection<T> collection, final T defaultValue)
<T> T firstOrElse(final Collection<T> collection, final Supplier<T> elseSupplier)
<T> boolean isNullOrEmpty(final T @Nullable [] t)
boolean isNullOrEmpty(final boolean @Nullable [] t)
boolean isNullOrEmpty(final byte @Nullable [] t)
boolean isNullOrEmpty(final char @Nullable [] t)
boolean isNullOrEmpty(final short @Nullable [] t)
boolean isNullOrEmpty(final int @Nullable [] t)
boolean isNullOrEmpty(final long @Nullable [] t)
boolean isNullOrEmpty(final float @Nullable [] t)
boolean isNullOrEmpty(final double @Nullable [] t)

Full Source

Optionull.java79 lines · Minecraft 26.3 · verbatim
1
package net.minecraft;
2
3
import java.util.Collection;
4
import java.util.Iterator;
5
import java.util.Objects;
6
import java.util.function.Function;
7
import java.util.function.Supplier;
8
import org.jspecify.annotations.Nullable;
9
10
public class Optionull {
11
	@Deprecated
12
	public static <T> T orElse(final @Nullable T t, final T defaultValue) {
13
		return Objects.requireNonNullElse(t, defaultValue);
14
	}
15
16
	public static <T, R> @Nullable R map(final @Nullable T t, final Function<T, R> map) {
17
		return t == null ? null : map.apply(t);
18
	}
19
20
	public static <T, R> R mapOrDefault(final @Nullable T t, final Function<T, R> map, final R defaultValue) {
21
		return t == null ? defaultValue : map.apply(t);
22
	}
23
24
	public static <T, R> R mapOrElse(final @Nullable T t, final Function<T, R> map, final Supplier<R> elseSupplier) {
25
		return t == null ? elseSupplier.get() : map.apply(t);
26
	}
27
28
	public static <T> @Nullable T first(final Collection<T> collection) {
29
		Iterator<T> iterator = collection.iterator();
30
		return iterator.hasNext() ? iterator.next() : null;
31
	}
32
33
	public static <T> T firstOrDefault(final Collection<T> collection, final T defaultValue) {
34
		Iterator<T> iterator = collection.iterator();
35
		return iterator.hasNext() ? iterator.next() : defaultValue;
36
	}
37
38
	public static <T> T firstOrElse(final Collection<T> collection, final Supplier<T> elseSupplier) {
39
		Iterator<T> iterator = collection.iterator();
40
		return iterator.hasNext() ? iterator.next() : elseSupplier.get();
41
	}
42
43
	public static <T> boolean isNullOrEmpty(final T @Nullable [] t) {
44
		return t == null || t.length == 0;
45
	}
46
47
	public static boolean isNullOrEmpty(final boolean @Nullable [] t) {
48
		return t == null || t.length == 0;
49
	}
50
51
	public static boolean isNullOrEmpty(final byte @Nullable [] t) {
52
		return t == null || t.length == 0;
53
	}
54
55
	public static boolean isNullOrEmpty(final char @Nullable [] t) {
56
		return t == null || t.length == 0;
57
	}
58
59
	public static boolean isNullOrEmpty(final short @Nullable [] t) {
60
		return t == null || t.length == 0;
61
	}
62
63
	public static boolean isNullOrEmpty(final int @Nullable [] t) {
64
		return t == null || t.length == 0;
65
	}
66
67
	public static boolean isNullOrEmpty(final long @Nullable [] t) {
68
		return t == null || t.length == 0;
69
	}
70
71
	public static boolean isNullOrEmpty(final float @Nullable [] t) {
72
		return t == null || t.length == 0;
73
	}
74
75
	public static boolean isNullOrEmpty(final double @Nullable [] t) {
76
		return t == null || t.length == 0;
77
	}
78
}
79

Decompiled Minecraft 26.3 source of Optionull (net/minecraft/Optionull.java) with Mojang official mappings, stored verbatim on the site.