Class 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>
      io.reactivex.rxjava3.core.Maybe<V>
      toMaybe​(Callable<Promise<V,​E>> callable)
      Transforms a Promise into a Maybe.
      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.
      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.
      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>
      toSingle​(Callable<Promise<V,​E>> callable)
      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 a Flowable based upon a given Closeable and a Function 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 a Single based upon a given Closeable and a Function 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, or false 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 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:
        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 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:
        Single, Closeable
      • toPromise

        public static <V,​E extends ExceptionPromise<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 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 ExceptionPromise<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 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​(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 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> io.reactivex.rxjava3.core.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.