Record Class Result<T>

java.lang.Object
java.lang.Record
jdk.jpackage.internal.util.Result<T>

public record Result<T>(Optional<T> value, Collection<? extends Exception> errors) extends Record
  • Constructor Details

    • Result

      public Result(Optional<T> value, Collection<? extends Exception> errors)
      Creates an instance of a Result record class.
      Parameters:
      value - the value for the value record component
      errors - the value for the errors record component
  • Method Details

    • orElseThrow

      public T orElseThrow()
    • hasValue

      public boolean hasValue()
    • hasErrors

      public boolean hasErrors()
    • map

      public <U> Result<U> map(Function<T,U> conv)
    • flatMap

      public <U> Result<U> flatMap(Function<T,Result<U>> conv)
    • mapErrors

      public <U> Result<U> mapErrors()
    • peekErrors

      public Result<T> peekErrors(Consumer<Collection<? extends Exception>> consumer)
    • peekValue

      public Result<T> peekValue(Consumer<T> consumer)
    • firstError

      public Optional<? extends Exception> firstError()
    • of

      public static <T> Result<T> of(Supplier<T> supplier)
    • of

      public static <T, E extends Exception> Result<T> of(ThrowingSupplier<T,? extends E> supplier, Class<? extends E> supplierExceptionType)
    • ofValue

      public static <T> Result<T> ofValue(T value)
    • ofErrors

      public static <T> Result<T> ofErrors(Collection<? extends Exception> errors)
    • ofError

      public static <T> Result<T> ofError(Exception error)
    • allHaveValues

      public static boolean allHaveValues(Iterable<? extends Result<?>> results)
    • allHaveValues

      public static boolean allHaveValues(Result<?>... results)
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • value

      public Optional<T> value()
      Returns the value of the value record component.
      Returns:
      the value of the value record component
    • errors

      public Collection<? extends Exception> errors()
      Returns the value of the errors record component.
      Returns:
      the value of the errors record component