Class Utils
-
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
isPrintableCharacter
(char c) Indicates whether the provided character is a valid printable character.static <V,
E extends Exception>
io.reactivex.rxjava3.core.Maybe<V>Transforms a Promise into a Maybe.toPromise
(io.reactivex.rxjava3.core.Maybe<V> maybe, io.reactivex.rxjava3.functions.Function<Throwable, E> exceptionConverter) Transforms a Maybe into a Promise.toPromise
(io.reactivex.rxjava3.core.Single<V> single, io.reactivex.rxjava3.functions.Function<Throwable, E> exceptionConverter) Transforms a Single into a Promise.static <V> Promise<V,
NeverThrowsException> toPromiseNoError
(io.reactivex.rxjava3.core.Single<V> single) Transforms a Single into a Promise which do not throws exceptions.static <V,
E extends Exception>
io.reactivex.rxjava3.core.Single<V>Transforms a Promise into a Single.static <C extends Closeable,
T>
io.reactivex.rxjava3.core.Flowable<T>tryWith
(io.reactivex.rxjava3.core.Single<C> closeable, io.reactivex.rxjava3.functions.Function<? super C, io.reactivex.rxjava3.core.Flowable<T>> mapper) Constructs aFlowable
based upon a givenCloseable
and aFunction
mapper.static <C extends Closeable,
T>
io.reactivex.rxjava3.core.Single<T>tryWithSingle
(io.reactivex.rxjava3.core.Single<C> closeable, io.reactivex.rxjava3.functions.Function<? super C, io.reactivex.rxjava3.core.Single<T>> mapper) Constructs aSingle
based upon a givenCloseable
and aFunction
mapper.
-
Method Details
-
isPrintableCharacter
public static boolean isPrintableCharacter(char c) Indicates whether the provided character is a valid printable character.- Parameters:
c
- The character for which to make the determination.- Returns:
true
if the provided character is a printable character, orfalse
if not.
-
tryWith
public static <C extends Closeable,T> io.reactivex.rxjava3.core.Flowable<T> tryWith(io.reactivex.rxjava3.core.Single<C> closeable, io.reactivex.rxjava3.functions.Function<? super C, io.reactivex.rxjava3.core.Flowable<T>> mapper) Constructs aFlowable
based upon a givenCloseable
and aFunction
mapper.The given
Closeable
is automatically closed wheneveronComplete
oronError
orSubscription.cancel()
is invoked.This method is similar to the try-with-resources of Java 7 that closes resources at the end of the statement.
It is also similar to the reactive using operator.
Below an example of usage: when the subscription is complete, canceled or terminates with an error, the
socket
is automatically closed.Single<LdapClientSocket> ldapSocket = ... tryWith(ldapSocket, socket -> socket.search(request)).subscribe(this::handleResponse, this::handleException)
- Type Parameters:
C
- Any element type that extendsCloseable
T
- The element type of the generated Flowable- Parameters:
closeable
- TheSingle
that encapsulates theCloseable
mapper
- A factory function to create a Flowable based upon the givenCloseable
- Returns:
- The Flowable based upon the given
Closeable
- See Also:
-
Flowable
Closeable
-
tryWithSingle
public static <C extends Closeable,T> io.reactivex.rxjava3.core.Single<T> tryWithSingle(io.reactivex.rxjava3.core.Single<C> closeable, io.reactivex.rxjava3.functions.Function<? super C, io.reactivex.rxjava3.core.Single<T>> mapper) Constructs aSingle
based upon a givenCloseable
and aFunction
mapper.The given
Closeable
is automatically closed wheneveronComplete
oronError
orSubscription.cancel()
is invoked.This method is similar to the try-with-resources of Java 7 that closes resources at the end of the statement.
It is also similar to the reactive using operator.
Below an example of usage: when the subscription is complete, canceled or terminates with an error, the
socket
is automatically closed.Single<LdapClientSocket> ldapSocket = ... tryWithSingle(ldapSocket, socket -> socket.searchSingleEntry(request)) .subscribe(this::handleResponse, this::handleException)
- Type Parameters:
C
- Any element type that extendsCloseable
T
- The element type of the generated Single- Parameters:
closeable
- TheSingle
that encapsulates theCloseable
mapper
- A factory function to create a Single based upon the givenCloseable
- Returns:
- The Single based upon the given
Closeable
- See Also:
-
Single
Closeable
-
toPromise
public static <V,E extends Exception> Promise<V,E> toPromise(io.reactivex.rxjava3.core.Maybe<V> maybe, io.reactivex.rxjava3.functions.Function<Throwable, E> exceptionConverter) Transforms a Maybe into a Promise.- Type Parameters:
V
- Type of the valueE
- Type of exception- Parameters:
maybe
- The single to transformexceptionConverter
- Function used to translate exceptions from Throwable to the expected type- Returns:
- A promise, result of the single transformation.
-
toPromise
public static <V,E extends Exception> Promise<V,E> toPromise(io.reactivex.rxjava3.core.Single<V> single, io.reactivex.rxjava3.functions.Function<Throwable, E> exceptionConverter) Transforms a Single into a Promise.- Type Parameters:
V
- Type of the valueE
- Type of exception- Parameters:
single
- The single to transformexceptionConverter
- Function used to translate exceptions from Throwable to the expected type- Returns:
- A promise, result of the single transformation.
-
toPromiseNoError
public static <V> Promise<V,NeverThrowsException> toPromiseNoError(io.reactivex.rxjava3.core.Single<V> single) Transforms a Single into a Promise which do not throws exceptions.- Type Parameters:
V
- Type of the value- Parameters:
single
- The single to transform- Returns:
- A promise, result of the single transformation.
-
toSingle
public static <V,E extends Exception> io.reactivex.rxjava3.core.Single<V> toSingle(Callable<Promise<V, E>> callable) Transforms a Promise into a Single.- Type Parameters:
V
- Type of the valueE
- Type of the exception thrown by the promise- Parameters:
callable
- The callable returning the promise to transform- Returns:
- A single, result of the promise transformation.
-
toMaybe
public static <V,E extends Exception> io.reactivex.rxjava3.core.Maybe<V> toMaybe(Callable<Promise<V, E>> callable) Transforms a Promise into a Maybe.- Type Parameters:
V
- Type of the valueE
- Type of the exception thrown by the promise- Parameters:
callable
- The callable returning the promise to transform- Returns:
- A single, result of the promise transformation.
-