Class Utils

java.lang.Object
org.forgerock.opendj.ldap.Utils

public final class Utils extends Object
This class provides utility functions.
  • 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, or false if not.
    • tryWith

      public static <C extends Closeable, T> Flowable<T> tryWith(Single<C> closeable, Function<? super C,Flowable<T>> mapper)
      Constructs a Flowable based upon a given Closeable and a Function mapper.

      The given Closeable is automatically closed wheneveronComplete or onError or Subscription.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 extends Closeable
      T - The element type of the generated Flowable
      Parameters:
      closeable - The Single that encapsulates the Closeable
      mapper - A factory function to create a Flowable based upon the given Closeable
      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 a Single based upon a given Closeable and a Function mapper.

      The given Closeable is automatically closed whenever onComplete or onError or Subscription.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 extends Closeable
      T - The element type of the generated Single
      Parameters:
      closeable - The Single that encapsulates the Closeable
      mapper - A factory function to create a Single based upon the given Closeable
      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 value
      E - Type of exception
      Parameters:
      maybe - The single to transform
      exceptionConverter - 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 value
      E - Type of exception
      Parameters:
      single - The single to transform
      exceptionConverter - 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 value
      E - 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 value
      E - 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.