Class ObjectUtil
java.lang.Object
ru.progrm_jarvis.javacommons.object.ObjectUtil
Utilities for common object operations.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final @NotNull Object @NotNull @Unmodifiable []Empty array of objects. -
Method Summary
Modifier and TypeMethodDescriptionstatic <T,R> R Maps (transforms) the value specified using the mapping function.static <T,R> R mapNonNull(@NonNull Function<@Nullable T, R> mappingFunction, @NotNull Supplier<@Nullable T> @NonNull ... variants) Returns the first nonnull value of specified variants ornullif none found mapped using function specified.static <T,R> R mapNonNull(@NonNull Function<@Nullable T, R> mappingFunction, @Nullable T @NonNull ... variants) Returns the first nonnull value of specified variants ornullif none found mapped using function specified.static <T,R> R mapNonNullOrThrow(@NonNull Function<@NotNull T, R> mappingFunction, @NotNull Supplier<@Nullable T> @NonNull ... variants) Returns the first nonnull value of specified variants mapped using function specified or throwsNullPointerExceptionif none found.static <T,R> R mapNonNullOrThrow(@NonNull Function<@NotNull T, R> mappingFunction, @Nullable T @NonNull ... variants) Returns the first nonnull value of specified variants mapped using function specified or throwsNullPointerExceptionif none found.static <T,R> R mapOnlyNonNull(@NonNull Function<@NotNull T, R> mappingFunction, @NotNull Supplier<@Nullable T> @NonNull ... variants) Returns the first nonnull value of specified variants mapped using function specified ornullif none found.static <T,R> R mapOnlyNonNull(@NonNull Function<@NotNull T, R> mappingFunction, @Nullable T @NonNull ... variants) Returns the first nonnull value of specified variants mapped using function specified ornullif none found.static <T> TnonNull(@Nullable T @NonNull ... variants) Returns the first nonnull value of specified variants ornullif none found.static <T> TReturns the first nonnull value of specified variants ornullif none found.static <T> TReturns the first nonnull value of specified variants or throwsNullPointerExceptionif none found.static <T> TReturns the first nonnull value of specified variants or throwsNullPointerExceptionif none found.static <T> TnonNullOrThrow(@NotNull Supplier<@Nullable T> @NonNull ... variants) Returns the first nonnull value of specified variants or throwsNullPointerExceptionif none found.static <T> TnonNullOrThrow(@Nullable T @NonNull ... variants) Returns the first nonnull value of specified variants or throwsNullPointerExceptionif none found.static <T> @NotNull Optional<T>optionalNonNull(@NotNull Supplier<@Nullable T> @NonNull ... variants) Returns the first nonnull value of specified variants wrapped inOptionalor empty if none found.static <T> @NotNull Optional<T>optionalNonNull(@Nullable T @NonNull ... variants) Returns the first nonnull value of specified variants wrapped inOptionalor empty if none found.
-
Field Details
-
EMPTY_ARRAY
Empty array of objects.
-
-
Method Details
-
nonNull
Returns the first nonnull value of specified variants ornullif none found.- Type Parameters:
T- type of value- Parameters:
variants- variants which may be nonnull- Returns:
- first nonnull value found or
nullif none
-
nonNull
Returns the first nonnull value of specified variants ornullif none found.- Type Parameters:
T- type of value- Parameters:
variants- variant suppliers whose values may be null- Returns:
- first nonnull value found or
nullif none
-
optionalNonNull
@SafeVarargs @NotNull public static <T> @NotNull Optional<T> optionalNonNull(@Nullable @Nullable T @NonNull ... variants) Returns the first nonnull value of specified variants wrapped inOptionalor empty if none found.- Type Parameters:
T- type of value- Parameters:
variants- variants which may be nonnull- Returns:
Optionalcontaining first nonnull value found or empty if none
-
optionalNonNull
@SafeVarargs @NotNull public static <T> @NotNull Optional<T> optionalNonNull(@NotNull @NotNull Supplier<@Nullable T> @NonNull ... variants) Returns the first nonnull value of specified variants wrapped inOptionalor empty if none found.- Type Parameters:
T- type of value- Parameters:
variants- variant suppliers whose values may be null- Returns:
Optionalcontaining first nonnull value found or empty if none
-
nonNullOrThrow
@SafeVarargs @NotNull public static <T> T nonNullOrThrow(@Nullable @Nullable T @NonNull ... variants) Returns the first nonnull value of specified variants or throwsNullPointerExceptionif none found.- Type Parameters:
T- type of value- Parameters:
variants- variants which may be nonnull- Returns:
- first nonnull value found
- Throws:
NullPointerException- if none of the variants specified is nonnull
-
nonNullOrThrow
@SafeVarargs @NotNull public static <T> T nonNullOrThrow(@NotNull @NotNull Supplier<@Nullable T> @NonNull ... variants) Returns the first nonnull value of specified variants or throwsNullPointerExceptionif none found.- Type Parameters:
T- type of value- Parameters:
variants- variant suppliers whose values may be null- Returns:
- first nonnull value found
- Throws:
NullPointerException- if none of the variants specified is nonnull
-
nonNullOr
@SafeVarargs public static <T> T nonNullOr(@NonNull @NonNull Supplier<T> nullHandler, @Nullable @Nullable T @NonNull ... variants) Returns the first nonnull value of specified variants or throwsNullPointerExceptionif none found.- Type Parameters:
T- type of value- Parameters:
nullHandler- handler to be used to supply the value in case of all variants beingnullvariants- variants which may be nonnull- Returns:
- first nonnull value found
- Throws:
NullPointerException- if none of the variants specified is nonnull
-
nonNullOr
@SafeVarargs public static <T> T nonNullOr(@NonNull @NonNull Supplier<T> nullHandler, @NotNull @NotNull Supplier<@Nullable T> @NonNull ... variants) Returns the first nonnull value of specified variants or throwsNullPointerExceptionif none found.- Type Parameters:
T- type of value- Parameters:
nullHandler- handler to be used to supply the value in case of all variants beingnullvariants- variant suppliers whose values may be null- Returns:
- first nonnull value found
- Throws:
NullPointerException- if none of the variants specified is nonnull
-
map
Maps (transforms) the value specified using the mapping function. This may come in handy in case of initializing fields with expressions which have checked exceptions.- Type Parameters:
T- type of source valueR- type of resulting value- Parameters:
value- value to mapmappingFunction- function to map the value to the required type- Returns:
- mapped (transformed) value
-
mapNonNull
@SafeVarargs public static <T,R> R mapNonNull(@NonNull @NonNull Function<@Nullable T, R> mappingFunction, @Nullable @Nullable T @NonNull ... variants) Returns the first nonnull value of specified variants ornullif none found mapped using function specified.- Type Parameters:
T- type of source valueR- type of resulting value- Parameters:
mappingFunction- function to map the value to the required typevariants- variants which may be nonnull- Returns:
- first nonnull value found or
nullif none found mapped using mapping function
-
mapNonNull
@SafeVarargs public static <T,R> R mapNonNull(@NonNull @NonNull Function<@Nullable T, R> mappingFunction, @NotNull @NotNull Supplier<@Nullable T> @NonNull ... variants) Returns the first nonnull value of specified variants ornullif none found mapped using function specified.- Type Parameters:
T- type of source valueR- type of resulting value- Parameters:
mappingFunction- function to map the value to the required typevariants- variant suppliers whose values may be null- Returns:
- first nonnull value found or
nullif none found mapped using mapping function
-
mapOnlyNonNull
@SafeVarargs @Nullable public static <T,R> R mapOnlyNonNull(@NonNull @NonNull Function<@NotNull T, R> mappingFunction, @Nullable @Nullable T @NonNull ... variants) Returns the first nonnull value of specified variants mapped using function specified ornullif none found.- Type Parameters:
T- type of source valueR- type of resulting value- Parameters:
mappingFunction- function to map the value to the required typevariants- variants which may be nonnull- Returns:
- first nonnull value found mapped using mapping function or
nullif none found
-
mapOnlyNonNull
@SafeVarargs @Nullable public static <T,R> R mapOnlyNonNull(@NonNull @NonNull Function<@NotNull T, R> mappingFunction, @NotNull @NotNull Supplier<@Nullable T> @NonNull ... variants) Returns the first nonnull value of specified variants mapped using function specified ornullif none found.- Type Parameters:
T- type of source valueR- type of resulting value- Parameters:
mappingFunction- function to map the value to the required typevariants- variant suppliers whose values may be null- Returns:
- first nonnull value found mapped using mapping function or
nullif none found
-
mapNonNullOrThrow
@SafeVarargs @NotNull public static <T,R> R mapNonNullOrThrow(@NonNull @NonNull Function<@NotNull T, R> mappingFunction, @Nullable @Nullable T @NonNull ... variants) Returns the first nonnull value of specified variants mapped using function specified or throwsNullPointerExceptionif none found.- Type Parameters:
T- type of source valueR- type of resulting value- Parameters:
mappingFunction- function to map the value to the required typevariants- variants which may be nonnull- Returns:
- first nonnull value found mapped using mapping function
- Throws:
NullPointerException- if none of the variants specified is nonnull
-
mapNonNullOrThrow
@SafeVarargs @NotNull public static <T,R> R mapNonNullOrThrow(@NonNull @NonNull Function<@NotNull T, R> mappingFunction, @NotNull @NotNull Supplier<@Nullable T> @NonNull ... variants) Returns the first nonnull value of specified variants mapped using function specified or throwsNullPointerExceptionif none found.- Type Parameters:
T- type of source valueR- type of resulting value- Parameters:
mappingFunction- function to map the value to the required typevariants- variant suppliers whose values may be null- Returns:
- first nonnull value found mapped using mapping function
- Throws:
NullPointerException- if none of the variants specified is nonnull
-