No need to nest.

This commit is contained in:
Gary Gregory 2021-02-07 10:15:29 -05:00
parent 45e8395ec7
commit ac6ebf4e1c
1 changed files with 6 additions and 12 deletions

View File

@ -72,9 +72,8 @@ public class Objects {
public static <O> @Nonnull O requireNonNull(@Nullable O value) throws NullPointerException { public static <O> @Nonnull O requireNonNull(@Nullable O value) throws NullPointerException {
if (value == null) { if (value == null) {
throw new NullPointerException("The value must not be null."); throw new NullPointerException("The value must not be null.");
} else {
return value;
} }
return value;
} }
/** /**
@ -92,13 +91,11 @@ public class Objects {
if (value == null) { if (value == null) {
if (defaultValue == null) { if (defaultValue == null) {
throw new NullPointerException("The default value must not be null."); throw new NullPointerException("The default value must not be null.");
} else { }
return defaultValue; return defaultValue;
} }
} else {
return value; return value;
} }
}
/** /**
* Checks, whether the given object is non-null. If so, returns the non-null * Checks, whether the given object is non-null. If so, returns the non-null
@ -115,9 +112,8 @@ public class Objects {
public static <O> @Nonnull O requireNonNull(@Nullable O value, @Nonnull String msg) throws NullPointerException { public static <O> @Nonnull O requireNonNull(@Nullable O value, @Nonnull String msg) throws NullPointerException {
if (value == null) { if (value == null) {
throw new NullPointerException(msg); throw new NullPointerException(msg);
} else {
return value;
} }
return value;
} }
/** /**
@ -135,9 +131,8 @@ public class Objects {
public static <O> @Nonnull O requireNonNull(@Nullable O value, @Nonnull Supplier<String> msgSupplier) throws NullPointerException { public static <O> @Nonnull O requireNonNull(@Nullable O value, @Nonnull Supplier<String> msgSupplier) throws NullPointerException {
if (value == null) { if (value == null) {
throw new NullPointerException(msgSupplier.get()); throw new NullPointerException(msgSupplier.get());
} else {
return value;
} }
return value;
} }
/** Checks, whether the given object is non-null. If so, returns the non-null /** Checks, whether the given object is non-null. If so, returns the non-null
@ -169,8 +164,7 @@ public class Objects {
throw Failable.rethrow(t); throw Failable.rethrow(t);
} }
return requireNonNull(o, "The supplier must not return null."); return requireNonNull(o, "The supplier must not return null.");
} else { }
return value; return value;
} }
}
} }