Class Utils
-
Method Summary
Modifier and TypeMethodDescriptionstatic booleanisPrintableCharacter(char c) Indicates whether the provided character is a valid printable character.Transforms a Promise into a Maybe.Transforms a Maybe into a Promise.Transforms a Single into a Promise.static <V> Promise<V,NeverThrowsException> toPromiseNoError(Single<V> single) Transforms a Single into a Promise which do not throws exceptions.Transforms a Promise into a Single.tryWithSingle(Single<C> closeable, Function<? super C, Single<T>> 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:
trueif the provided character is a printable character, orfalseif not.
-
tryWith
public static <C extends Closeable,T> Flowable<T> tryWith(Single<C> closeable, Function<? super C, Flowable<T>> mapper) Constructs aFlowablebased upon a givenCloseableand aFunctionmapper.The given
Closeableis automatically closed wheneveronCompleteoronErrororSubscription.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
socketis automatically closed.Single<LdapClientSocket> ldapSocket = ... tryWith(ldapSocket, socket -> socket.search(request)).subscribe(this::handleResponse, this::handleException)- Type Parameters:
C- Any element type that extendsCloseableT- The element type of the generated Flowable- Parameters:
closeable- TheSinglethat encapsulates theCloseablemapper- A factory function to create a Flowable based upon the givenCloseable- Returns:
- The Flowable based upon the given
Closeable - See Also:
-
tryWithSingle
public static <C extends Closeable,T> Single<T> tryWithSingle(Single<C> closeable, Function<? super C, Single<T>> mapper) Constructs aSinglebased upon a givenCloseableand aFunctionmapper.The given
Closeableis automatically closed wheneveronCompleteoronErrororSubscription.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
socketis automatically closed.Single<LdapClientSocket> ldapSocket = ... tryWithSingle(ldapSocket, socket -> socket.searchSingleEntry(request)) .subscribe(this::handleResponse, this::handleException)- Type Parameters:
C- Any element type that extendsCloseableT- The element type of the generated Single- Parameters:
closeable- TheSinglethat encapsulates theCloseablemapper- A factory function to create a Single based upon the givenCloseable- Returns:
- The Single based upon the given
Closeable - See Also:
-
toPromise
public static <V,E extends Exception> Promise<V,E> toPromise(Maybe<V> maybe, 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(Single<V> single, 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
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
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
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.
-