Class LazyResettableImpl<C>

java.lang.Object
com.linkedin.venice.utils.lazy.LazyResettableImpl<C>
All Implemented Interfaces:
Lazy<C>, LazyResettable<C>
Direct Known Subclasses:
LazyResettableWithTearDown

public class LazyResettableImpl<C> extends Object implements LazyResettable<C>
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected Lazy<C>
     

    Fields inherited from interface com.linkedin.venice.utils.lazy.Lazy

    FALSE, TRUE
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    filter(Predicate<? super C> predicate)
    If a value is initialized, and the value matches the given predicate, return an Optional describing the value, otherwise return an empty Optional.
    <U> Optional<U>
    flatMap(Function<? super C,Optional<U>> mapper)
    If a value is initialized, apply the provided Optional-bearing mapping function to it, return that result, otherwise return an empty Optional.
    get()
     
    void
    ifPresent(Consumer<? super C> consumer)
     
    boolean
     
    <U> Optional<U>
    map(Function<? super C,? extends U> mapper)
    If a value is initialized, apply the provided mapping function to it, and if the result is non-null, return an Optional describing the result.
    orElse(C other)
    Return the value if initialized, otherwise return other.
    orElseGet(Supplier<? extends C> other)
    Return the value if initialized, otherwise invoke other and return the result of that invocation.
    <X extends Throwable>
    C
    orElseThrow(Supplier<? extends X> exceptionSupplier)
    Return the contained value, if initialized, otherwise throw an exception to be created by the provided supplier.
    void
    Returns to the uninitialized state.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • lazy

      protected Lazy<C> lazy
  • Constructor Details

    • LazyResettableImpl

      public LazyResettableImpl(Supplier<C> supplier)
  • Method Details

    • reset

      public void reset()
      Description copied from interface: LazyResettable
      Returns to the uninitialized state.
      Specified by:
      reset in interface LazyResettable<C>
    • get

      public C get()
      Specified by:
      get in interface Lazy<C>
      Returns:
      the wrapped value, with the side-effect of initializing it has not happened yet
    • ifPresent

      public void ifPresent(Consumer<? super C> consumer)
      Specified by:
      ifPresent in interface Lazy<C>
      Parameters:
      consumer - to pass the wrapped value to, only if it has already been initialized
    • isPresent

      public boolean isPresent()
      Specified by:
      isPresent in interface Lazy<C>
      Returns:
      true if there is a value present (i.e. initialized), otherwise false
    • filter

      public Optional<C> filter(Predicate<? super C> predicate)
      Description copied from interface: Lazy
      If a value is initialized, and the value matches the given predicate, return an Optional describing the value, otherwise return an empty Optional.
      Specified by:
      filter in interface Lazy<C>
      Parameters:
      predicate - a predicate to apply to the value, if initialized
      Returns:
      an Optional describing the value of this Optional if a value is present and the value matches the given predicate, otherwise an empty Optional
    • map

      public <U> Optional<U> map(Function<? super C,? extends U> mapper)
      Description copied from interface: Lazy
      If a value is initialized, apply the provided mapping function to it, and if the result is non-null, return an Optional describing the result. Otherwise return an empty Optional.
      Specified by:
      map in interface Lazy<C>
      Type Parameters:
      U - The type of the result of the mapping function
      Parameters:
      mapper - a mapping function to apply to the value, if initialized
      Returns:
      an Optional describing the result of applying a mapping function to the value of this Optional, if a value is initialized, otherwise an empty Optional
    • flatMap

      public <U> Optional<U> flatMap(Function<? super C,Optional<U>> mapper)
      Description copied from interface: Lazy
      If a value is initialized, apply the provided Optional-bearing mapping function to it, return that result, otherwise return an empty Optional. This method is similar to Lazy.map(Function), but the provided mapper is one whose result is already an Optional, and if invoked, flatMap does not wrap it with an additional Optional.
      Specified by:
      flatMap in interface Lazy<C>
      Type Parameters:
      U - The type parameter to the Optional returned by the mapping function
      Parameters:
      mapper - a mapping function to apply to the value, if initialized
      Returns:
      the result of applying an Optional-bearing mapping function to the value of this Optional, if a value is initialized, otherwise an empty Optional
    • orElse

      public C orElse(C other)
      Description copied from interface: Lazy
      Return the value if initialized, otherwise return other.
      Specified by:
      orElse in interface Lazy<C>
      Parameters:
      other - the value to be returned if there is no value initialized, may be null
      Returns:
      the value, if initialized, otherwise other
    • orElseGet

      public C orElseGet(Supplier<? extends C> other)
      Description copied from interface: Lazy
      Return the value if initialized, otherwise invoke other and return the result of that invocation.
      Specified by:
      orElseGet in interface Lazy<C>
      Parameters:
      other - a Supplier whose result is returned if no value is initialized
      Returns:
      the value if initialized otherwise the result of other.get()
    • orElseThrow

      public <X extends Throwable> C orElseThrow(Supplier<? extends X> exceptionSupplier) throws X
      Description copied from interface: Lazy
      Return the contained value, if initialized, otherwise throw an exception to be created by the provided supplier.
      Specified by:
      orElseThrow in interface Lazy<C>
      Type Parameters:
      X - Type of the exception to be thrown
      Parameters:
      exceptionSupplier - The supplier which will return the exception to be thrown
      Returns:
      the initialized value
      Throws:
      X - if there is no value initialized