Class RStreams.Exceptional<T>

java.lang.Object
uk.co.terminological.rjava.utils.RStreams.Exceptional<T>
Enclosing class:
RStreams

public static class RStreams.Exceptional<T> extends Object
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Indicates whether some other object is "equal to" this Exceptional.
    boolean
    If a exception was throwb, returns true, otherwise false.
    static <T, E extends Exception>
    RStreams.Exceptional<T>
    failed(Exception exception)
     
    filter(Predicate<? super T> predicate)
    If the exceptional has a value, and the value matches the given predicate, returns an Exceptional describing the value, otherwise a Exceptional failing due to a FilteredException.
     
    flatMap(Function<? super T,? extends RStreams.Exceptional<? extends U>> mapper)
    If a value is present, returns the result of applying the given Exceptional-bearing mapping function to the value, otherwise returns an empty Exceptional.
    get()
    If a value is present, returns the value, otherwise throws NoSuchElementException.
    int
    Returns the hash code of the value, if present, otherwise 0 (zero) if no value is present.
    map(RStreams.ExceptionalFunction<? super T,? extends U> mapper)
    If a value is present, returns an Exceptional containing the result of applying the given mapping function to the value, otherwise returns a failing Exceptional.
    void
    onSuccess(Consumer<? super T> action)
    If a value is present, performs the given action with the value, otherwise does nothing.
    void
    onSucessOrFailure(Consumer<? super T> action, Consumer<Exception> errorHandler)
    If a value is present, performs the given action with the value, otherwise performs the given empty-based action.
    orElse(T other)
    If a value is present, returns the value, otherwise returns other.
    orElseGet(Supplier<? extends T> supplier)
    If a value is present, returns the value, otherwise returns the result produced by the supplying function.
    If a value is present, returns the value, otherwise throws NoSuchElementException.
    If a value is present, returns a sequential Stream containing only that value, otherwise returns an empty Stream.
    boolean
    If a value is present, returns true, otherwise false.
    static <T, E extends Exception>
    RStreams.Exceptional<T>
    success(T value)
     
    Returns a non-empty string representation of this Exceptional suitable for debugging.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Method Details

    • success

      public static <T, E extends Exception> RStreams.Exceptional<T> success(T value)
    • failed

      public static <T, E extends Exception> RStreams.Exceptional<T> failed(Exception exception)
    • filtered

      public RStreams.Exceptional<T> filtered()
    • get

      public T get() throws Exception
      If a value is present, returns the value, otherwise throws NoSuchElementException.
      Returns:
      the non-null value described by this Optional
      Throws:
      Exception - if no value is present
    • succeeded

      public boolean succeeded()
      If a value is present, returns true, otherwise false.
      Returns:
      true if a value is present, otherwise false
    • failed

      public boolean failed()
      If a exception was throwb, returns true, otherwise false.
      Returns:
      true if a value is present, otherwise false
    • onSuccess

      public void onSuccess(Consumer<? super T> action)
      If a value is present, performs the given action with the value, otherwise does nothing.
      Parameters:
      action - the action to be performed, if a value is present
      Throws:
      NullPointerException - if value is present and the given action is null
    • onSucessOrFailure

      public void onSucessOrFailure(Consumer<? super T> action, Consumer<Exception> errorHandler)
      If a value is present, performs the given action with the value, otherwise performs the given empty-based action.
      Parameters:
      action - the action to be performed, if a value is present
      errorHandler - the action to be performed, if an error was thrown
      Throws:
      NullPointerException - if a value is present and the given action is null, or no value is present and the given empty-based action is null.
      Since:
      9
    • filter

      public RStreams.Exceptional<T> filter(Predicate<? super T> predicate)
      If the exceptional has a value, and the value matches the given predicate, returns an Exceptional describing the value, otherwise a Exceptional failing due to a FilteredException.
      Parameters:
      predicate - the predicate to apply to a value, if present
      Returns:
      an Exceptional describing the value of this Exceptional, if a value is present and the value matches the given predicate, otherwise a failing Exceptional
      Throws:
      NullPointerException - if the predicate is null
    • map

      public <U> RStreams.Exceptional<U> map(RStreams.ExceptionalFunction<? super T,? extends U> mapper)
      If a value is present, returns an Exceptional containing the result of applying the given mapping function to the value, otherwise returns a failing Exceptional.

      If the mapping function returns a null result then this method returns an empty Exceptional.

      Type Parameters:
      U - The type of the value returned from the mapping function
      Parameters:
      mapper - the mapping function to apply to a value, if present
      Returns:
      an Exceptional describing the result of applying a mapping function to the value of this Exceptional, if a value is present, otherwise an empty Exceptional
      Throws:
      NullPointerException - if the mapping function is null
    • flatMap

      public <U> RStreams.Exceptional<U> flatMap(Function<? super T,? extends RStreams.Exceptional<? extends U>> mapper)
      If a value is present, returns the result of applying the given Exceptional-bearing mapping function to the value, otherwise returns an empty Exceptional.

      This method is similar to map(ExceptionalFunction), but the mapping function is one whose result is already an Exceptional, and if invoked, flatMap does not wrap it within an additional Exceptional.

      Type Parameters:
      U - The type of value of the Exceptional returned by the mapping function
      Parameters:
      mapper - the mapping function to apply to a value, if present
      Returns:
      the result of applying an Exceptional-bearing mapping function to the value of this Exceptional, if a value is present, otherwise an empty Exceptional
      Throws:
      NullPointerException - if the mapping function is null or returns a null result
    • stream

      public Stream<T> stream()
      If a value is present, returns a sequential Stream containing only that value, otherwise returns an empty Stream.
      Returns:
      the Exceptional value as a Stream
      Since:
      9
    • orElse

      public T orElse(T other)
      If a value is present, returns the value, otherwise returns other.
      Parameters:
      other - the value to be returned, if no value is present. May be null.
      Returns:
      the value, if present, otherwise other
    • orElseGet

      public T orElseGet(Supplier<? extends T> supplier)
      If a value is present, returns the value, otherwise returns the result produced by the supplying function.
      Parameters:
      supplier - the supplying function that produces a value to be returned
      Returns:
      the value, if present, otherwise the result produced by the supplying function
      Throws:
      NullPointerException - if no value is present and the supplying function is null
    • orElseThrow

      public T orElseThrow() throws Exception
      If a value is present, returns the value, otherwise throws NoSuchElementException.
      Returns:
      the non-null value described by this Exceptional
      Throws:
      Exception
      Since:
      10
    • equals

      public boolean equals(Object obj)
      Indicates whether some other object is "equal to" this Exceptional. The other object is considered equal if:
      • it is also an Exceptional and;
      • both instances have no value present or;
      • the present values are "equal to" each other via equals().
      Overrides:
      equals in class Object
      Parameters:
      obj - an object to be tested for equality
      Returns:
      true if the other object is "equal to" this object otherwise false
    • hashCode

      public int hashCode()
      Returns the hash code of the value, if present, otherwise 0 (zero) if no value is present.
      Overrides:
      hashCode in class Object
      Returns:
      hash code value of the present value or 0 if no value is present
    • toString

      public String toString()
      Returns a non-empty string representation of this Exceptional suitable for debugging. The exact presentation format is unspecified and may vary between implementations and versions.
      Overrides:
      toString in class Object
      Returns:
      the string representation of this instance