Class ObjectUtils
java.lang.Object
io.fluxzero.common.ObjectUtils
Utility class for common object handling, memoization, concurrency, stream processing, and error handling.
Offers reusable tools for:
- Memoizing functional interfaces
- Retry-safe functional wrappers (callables, consumers, etc.)
- Stream deduplication and flattening
- Property file manipulation
- Exception-safe task execution and error unwrapping
- Custom thread factories and naming
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Callable<?> asCallable(ThrowingRunnable runnable) Converts a ThrowingRunnable into aCallable<Object>that returns null.static Callable<?> asCallable(Runnable runnable) Converts a standardRunnableinto aCallable<Object>that returns null.static <T> Consumer<T> asConsumer(ThrowingConsumer<T> consumer) static <T,R> Function <T, R> asFunction(ThrowingFunction<T, R> function) static PropertiesasProperties(String content) Parses JavaPropertiesfrom a string.static RunnableasRunnable(ThrowingRunnable runnable) static RunnableasRunnable(Callable<?> callable) static Stream<?> Converts an object into a stream.static <T> Supplier<T> asSupplier(Callable<T> callable) static <T> TCalls the given callable, forcibly rethrowing exceptions.static <T> Stream<T> Concatenates multiple streams into a single flat stream.static PropertiescopyOf(Properties properties) Creates a deep copy of a Properties instance.static <T> List<T> deduplicate(List<T> list) Deduplicates elements in the list, preserving the last occurrence.static <T> List<T> deduplicate(List<T> list, Function<T, ?> idFunction) Deduplicates elements using a key extractor, preserving the last occurrence.static <T> List<T> deduplicate(List<T> list, Function<T, ?> idFunction, boolean keepFirst) Deduplicates elements using a key extractor, optionally keeping the first occurrence.static <T> Predicate<T> distinctByKey(Function<? super T, ?> keyExtractor) Returns a predicate that filters out duplicates based on a key extractor.static ObjectforceThrow(Throwable error) Forces the given throwable to be thrown.static byte[]getBytes(ByteBuffer buffer) Extracts the byte array from aByteBuffer.ifTrue(boolean check) Returns a consumer that runs the task only ifcheckis true.static <T> Stream<T> iterate(T seed, UnaryOperator<T> f, Predicate<T> breakCondition) Creates a stream that stops once the break condition evaluates true.static byte[]join(byte[]... chunks) Combines multiple byte arrays into a single byte array by concatenating their contents in the given order.static <T,U, R> MemoizingBiFunction <T, U, R> memoize(BiFunction<T, U, R> supplier) static <K,V> MemoizingFunction <K, V> static <T> MemoizingSupplier<T> static Propertiesmerge(Properties a, Properties b) Merges two Properties instances into a new one.static ThreadFactorynewPlatformThreadFactory(String prefix) Creates a newThreadFactorywith a named prefix.static <T,U> BiPredicate <T, U> Returns a bi-predicate that always evaluates to true.static <T> Predicate<T> Returns a predicate that always evaluates to true.static voidrun(ThrowingRunnable runnable) Executes the runnable, forcibly rethrowing exceptions as unchecked.static <T> Predicate<T> silentTest(Predicate<T> predicate) Returns a predicate that silently returns false when the given predicate throws an error.static <T> Consumer<? super T> Returns a consumer that logs errors instead of propagating them.static RunnableWraps a runnable in a try/catch block that logs any exception on execution.static voidExecutes the runnable and logs any thrown exception.static ThrowableRecursively unwraps the cause of common wrapping exceptions.
-
Constructor Details
-
ObjectUtils
public ObjectUtils()
-
-
Method Details
-
noOpPredicate
Returns a predicate that always evaluates to true. -
noOpBiPredicate
Returns a bi-predicate that always evaluates to true. -
distinctByKey
-
iterate
Creates a stream that stops once the break condition evaluates true. -
concat
Concatenates multiple streams into a single flat stream. -
deduplicate
-
deduplicate
-
deduplicate
-
asStream
-
ifTrue
-
forceThrow
-
call
Calls the given callable, forcibly rethrowing exceptions. -
run
Executes the runnable, forcibly rethrowing exceptions as unchecked. -
asCallable
Converts a ThrowingRunnable into aCallable<Object>that returns null. -
asCallable
-
tryRun
Executes the runnable and logs any thrown exception. -
tryCatch
-
asSupplier
-
asRunnable
-
asFunction
-
asConsumer
-
asRunnable
-
getBytes
Extracts the byte array from aByteBuffer. -
unwrapException
-
asProperties
Parses JavaPropertiesfrom a string. -
copyOf
Creates a deep copy of a Properties instance. -
merge
Merges two Properties instances into a new one. -
memoize
-
memoize
-
memoize
-
newPlatformThreadFactory
Creates a newThreadFactorywith a named prefix. -
tryAccept
-
silentTest
-
join
public static byte[] join(byte[]... chunks) Combines multiple byte arrays into a single byte array by concatenating their contents in the given order.
-