Class Utils
- java.lang.Object
-
- org.forgerock.opendj.ldap.Utils
-
public final class Utils extends Object
This class provides utility functions.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static boolean
isPrintableCharacter(char c)
Indicates whether the provided character is a valid printable character.static <V,E extends Exception>
Maybe<V>toMaybe(Callable<Promise<V,E>> callable)
Transforms a Promise into a Maybe.static <V,E extends Exception>
Promise<V,E>toPromise(Maybe<V> maybe, Function<Throwable,E> exceptionConverter)
Transforms a Maybe into a Promise.static <V,E extends Exception>
Promise<V,E>toPromise(Single<V> single, Function<Throwable,E> exceptionConverter)
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.static <V,E extends Exception>
Single<V>toSingle(Callable<Promise<V,E>> callable)
Transforms a Promise into a Single.static <C extends Closeable,T>
Flowable<T>tryWith(Single<C> closeable, Function<? super C,Flowable<T>> mapper)
static <C extends Closeable,T>
Single<T>tryWithSingle(Single<C> closeable, Function<? super C,Single<T>> mapper)
-
-
-
Method Detail
-
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> Flowable<T> tryWith(Single<C> closeable, Function<? super C,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> Single<T> tryWithSingle(Single<C> closeable, Function<? super C,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(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
public static <V> Promise<V,NeverThrowsException> toPromiseNoError(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> 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> 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.
-
-