Fix orElse

This commit is contained in:
Andrea Cavalli 2022-06-19 17:22:26 +02:00
parent de3853e0b6
commit 8d72c9cfc5
3 changed files with 3 additions and 20 deletions

View File

@ -1,5 +1,6 @@
package it.cavallium.data.generator; package it.cavallium.data.generator;
import java.util.Objects;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@ -25,7 +26,8 @@ public interface TypedNullable<T> extends NativeNullable<T> {
default @NotNull T orElse(@NotNull T defaultValue) { default @NotNull T orElse(@NotNull T defaultValue) {
var value = getNullable(); var value = getNullable();
if (value == null) { if (value == null) {
throw new NullPointerException(); Objects.requireNonNull(defaultValue, "default value must not be null");
return defaultValue;
} else { } else {
return value; return value;
} }

View File

@ -64,15 +64,6 @@ public class NullableInt52 implements Serializable, IGenericNullable, TypedNulla
} }
} }
@Override
public @NotNull Int52 orElse(@NotNull Int52 defaultValue) {
if (value == null) {
return defaultValue;
} else {
return value;
}
}
@Override @Override
public @NotNull NullableInt52 or(@NotNull NativeNullable<? extends Int52> fallback) { public @NotNull NullableInt52 or(@NotNull NativeNullable<? extends Int52> fallback) {
if (value == null) { if (value == null) {

View File

@ -76,16 +76,6 @@ public class NullableString implements Serializable, IGenericNullable, TypedNull
} }
} }
@Override
@NotNull
public String orElse(@NotNull String defaultValue) {
if (value == null) {
return defaultValue;
} else {
return value;
}
}
@Override @Override
public @NotNull NullableString or(@NotNull NativeNullable<? extends String> fallback) { public @NotNull NullableString or(@NotNull NativeNullable<? extends String> fallback) {
if (value == null) { if (value == null) {