public final class Nullsafe extends Object
| Modifier and Type | Method and Description |
|---|---|
static @NonNull BigInteger |
addNullsafe(@Nullable BigInteger first,
@Nullable BigInteger second) |
static @NonNull BigInteger |
asBigInteger(long value) |
static @NonNull Long |
asLong(long value) |
static @NonNull BigInteger |
divideNullsafe(@Nullable BigInteger first,
@Nullable BigInteger second) |
static <TYPE> @NonNull List<TYPE> |
ensureList(@Nullable List<TYPE> list)
Ensures that callers of this method can always work with a
NonNull list. |
static <KEY,VALUE> |
ensureMap(@Nullable Map<KEY,VALUE> map)
Ensures that callers of this method can always work with a
NonNull map. |
static <TYPE> @NonNull Set<TYPE> |
ensureSet(@Nullable Set<TYPE> set)
Ensures that callers of this method can always work with a
NonNull set. |
static boolean |
isNullOrEmpty(@Nullable Collection<?> collection)
Safely checks whether a given
collection is null or empty. |
static boolean |
isNullOrEmpty(@Nullable Map<?,?> map)
Safely checks whether a given
map is null or empty. |
static boolean |
isNullOrEmpty(@Nullable String string)
Safely checks whether a given
string is null or empty. |
static @NonNull BigInteger |
multiplyNullsafe(@Nullable BigInteger first,
@Nullable BigInteger second) |
static <TYPE> TYPE |
nonNull(TYPE reference)
Converts a
Nullable reference into a NonNull reference. |
static <TYPE> TYPE |
nonNull(TYPE reference,
String message)
Converts a
Nullable reference into a NonNull reference. |
static <TYPE> @NonNull Stream<TYPE> |
safelyStream(@Nullable Collection<TYPE> collection)
Safely creates a
stream of a nullable collection. |
static @NonNull BigInteger |
subtractNullsafe(@Nullable BigInteger first,
@Nullable BigInteger second) |
public static <TYPE> TYPE nonNull(TYPE reference)
Nullable reference into a NonNull reference. Performs a strict null check
that fails in case a null reference is given.TYPE - The type of the referencereference - A possible null reference.IllegalArgumentException, in case the reference was
null.public static <TYPE> TYPE nonNull(TYPE reference,
String message)
Nullable reference into a NonNull reference. Performs a strict null check
that fails in case a null reference is given.TYPE - The type of the referencereference - A possible null reference.message - The exception message to throw.IllegalArgumentException, in case the reference was
null.public static <TYPE> @NonNull Stream<TYPE> safelyStream(@Nullable Collection<TYPE> collection)
stream of a nullable collection. Falls back to an empty stream
in case the collection is null.TYPE - The collection typecollection - A collection or nullpublic static <TYPE> @NonNull List<TYPE> ensureList(@Nullable List<TYPE> list)
NonNull list. Falls back to an
empty list in case the given list is null.TYPE - The list typelist - A list or nullpublic static <TYPE> @NonNull Set<TYPE> ensureSet(@Nullable Set<TYPE> set)
NonNull set. Falls back to an
empty set in case the given set is null.TYPE - The set typeset - A Set or nullpublic static <KEY,VALUE> @NonNull Map<KEY,VALUE> ensureMap(@Nullable Map<KEY,VALUE> map)
NonNull map. Falls back to an
empty map in case the given map is null.KEY - The map key typeVALUE - The map value typemap - A Map or nullpublic static boolean isNullOrEmpty(@Nullable Collection<?> collection)
collection is null or empty.collection - A collection or nulltrue if the collection is null or empty, otherwise false.public static boolean isNullOrEmpty(@Nullable Map<?,?> map)
map is null or empty.map - A map or nulltrue if the map is null or empty, otherwise false.public static boolean isNullOrEmpty(@Nullable String string)
string is null or empty.string - A String or nulltrue if the string is null or empty, otherwise false.public static @NonNull BigInteger asBigInteger(long value)
value - The value to wrapBigIntegerpublic static @NonNull Long asLong(long value)
value - The value to wrapLongpublic static @NonNull BigInteger addNullsafe(@Nullable BigInteger first, @Nullable BigInteger second)
first - The first value to addsecond - The second value to addBigIntegerpublic static @NonNull BigInteger subtractNullsafe(@Nullable BigInteger first, @Nullable BigInteger second)
first - The first value to subtractsecond - The second value to subtractBigIntegerpublic static @NonNull BigInteger divideNullsafe(@Nullable BigInteger first, @Nullable BigInteger second)
first - The first value to dividesecond - The second value to divideBigIntegerpublic static @NonNull BigInteger multiplyNullsafe(@Nullable BigInteger first, @Nullable BigInteger second)
first - The first value to multiplysecond - The second value to multiplyBigIntegerCopyright © 2013–2017 metio.wtf. All rights reserved.