Class ValueContainer.Supplying<T>

java.lang.Object
ru.progrm_jarvis.javacommons.object.ValueContainer.Supplying<T>
Type Parameters:
T - type of stored value
All Implemented Interfaces:
Supplier<T>, ValueContainer<T>
Enclosing interface:
ValueContainer<T>

public static final class ValueContainer.Supplying<T> extends Object implements ValueContainer<T>
Value-container which provides new values for each request.
  • Method Details

    • isPresent

      public boolean isPresent()
      Description copied from interface: ValueContainer
      Checks whether the object is present ot not.
      Specified by:
      isPresent in interface ValueContainer<T>
      Returns:
      true if the value is present (might be null) and false otherwise
    • orElse

      @Nullable public T orElse(@Nullable T value)
      Description copied from interface: ValueContainer
      Gets the value if it is present otherwise using the specified one.
      Specified by:
      orElse in interface ValueContainer<T>
      Parameters:
      value - value to use if this value container is empty
      Returns:
      this value container's value if it is not empty or the specified value otherwise
    • orElseGet

      @Nullable public T orElseGet(@NonNull @NonNull Supplier<T> defaultValueSupplier)
      Description copied from interface: ValueContainer
      Gets the value if it is present otherwise using the one got from the specified supplier.
      Specified by:
      orElseGet in interface ValueContainer<T>
      Parameters:
      defaultValueSupplier - supplier to be used for getting the value if this value container is empty
      Returns:
      this value container's value if it is not empty or the one got from the supplier otherwise
    • orElseThrow

      @Nullable public <X extends Throwable> T orElseThrow(@NonNull @NonNull Supplier<X> exceptionSupplier)
      Description copied from interface: ValueContainer
      Gets the value if it is present otherwise throwing an exception.
      Specified by:
      orElseThrow in interface ValueContainer<T>
      Type Parameters:
      X - type of an exception thrown if this value container is empty
      Parameters:
      exceptionSupplier - supplier to be used for getting the exception if this value container is empty
      Returns:
      this value container's value if it is not empty
    • asResult

      @NotNull public <E> @NotNull Result<T,@Nullable E> asResult()
      Description copied from interface: ValueContainer
      Converts this value container into a null-error result.
      Specified by:
      asResult in interface ValueContainer<T>
      Type Parameters:
      E - type of the result error
      Returns:
      successful result containing the value contained by this value container if is is present or a null-error result otherwise
      See Also:
    • asResult

      @NotNull public <E> @NotNull Result<T,E> asResult(Supplier<E> errorSupplier)
      Description copied from interface: ValueContainer
      Converts this value container into a Result.
      Specified by:
      asResult in interface ValueContainer<T>
      Type Parameters:
      E - type of the result error
      Parameters:
      errorSupplier - supplier of the error in case of this value container being empty
      Returns:
      successful result containing the value contained by this value container if is is present or an error result with the error got by using the specified supplier
      See Also:
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • get

      public T get()
      Description copied from interface: ValueContainer
      Gets the value stored in this value container.
      Specified by:
      get in interface Supplier<T>
      Specified by:
      get in interface ValueContainer<T>
      Returns:
      stored value if it is present