Module iu.util
Package edu.iu

Class IuVisitor<T>

java.lang.Object
edu.iu.IuVisitor<T>
Type Parameters:
T - element type
All Implemented Interfaces:
Consumer<T>

public class IuVisitor<T> extends Object implements Consumer<T>
Implements a basic visitor pattern for tracking disparate uniform instances of a specific element type.

This resource is thread-safe and intended for use in high-volume and time-sensitive component initialization scenarios. Elements are weakly held, so will may only be visited until cleared by the garbage collector.

UML Class Diagram

  • Constructor Details

    • IuVisitor

      public IuVisitor()
      Default constructor.
  • Method Details

    • visit

      public <V> Optional<V> visit(Function<T,Optional<V>> visitor)
      Applies a function to each element until a generic condition is satisfied.
      Type Parameters:
      V - value type
      Parameters:
      visitor - Function to apply each element to until an Optional value is returned. null will be applied last if no elements result in an Optional value. The function may return null to continue to the next element, and may always return null to always visit all elements. A non-null Optional result indicates the visited element satisfied a generic condition of some sort and so no other elements should be visited; the Optional is immediately returned as-is.
      Returns:
      Optional result of the first terminal condition satisfied; null if a terminal condition was not met.
    • accept

      public void accept(T element)
      Accepts an element to be observed.
      Specified by:
      accept in interface Consumer<T>
      Parameters:
      element - to observe
    • clear

      public void clear(T element)
      Removes an element from observation queue without waiting for the garbage collector to clear it.

      This method does not tear down or take any other action on the element, the controlling component should handle all tear down logic related to this visitor instance prior to clearing the reference, typically invoking this method last in a managed instance's lifecycle teardown process.

      This method has no effect if the element is not in the observation queue.

      API Note: Since elements are weakly held, this method is only necessary when hooking in to an external instance management mechanism. Typically, instances may simply be discarded rather then explicitly cleared.

      Parameters:
      element - element to clear
    • subject

      public IuAsynchronousSubject<T> subject()
      Gets a IuAsynchronousSubject originated by non-cleared references to accepted elements.

      Each call to this method returns an independent subject instance. The controller responsible for providing elements to the visitor must independently provide the same values to, and close its own, subject instance to ensure continuity for subscribers.

      Returns:
      IuAsynchronousSubject