Interface Inbox

  • All Superinterfaces:
    java.lang.Iterable<java.lang.Object>
    All Known Implementing Classes:
    TestInbox

    public interface Inbox
    extends java.lang.Iterable<java.lang.Object>
    A subset of Queue<Object> API restricted to the consumer side, with additional support for bulk draining operations.
    Since:
    Jet 3.0
    • Method Summary

      All Methods Instance Methods Abstract Methods Default Methods 
      Modifier and Type Method Description
      void clear()
      Removes all items from the inbox.
      default <E> int drain​(java.util.function.Consumer<E> consumer)
      Passes each of this object's items to the supplied consumer until it is empty.
      default <E> int drainTo​(java.util.Collection<E> target)
      Drains all elements into the provided Collection.
      default <E> int drainTo​(java.util.Collection<E> target, int limit)
      Drains at most limit elements into the provided Collection.
      default <E,​M>
      int
      drainTo​(java.util.Collection<M> target, int limit, java.util.function.Function<E,​M> mapper)
      Drains and maps at most limit elements into the provided Collection.
      boolean isEmpty()
      Returns true if this inbox contains no elements, false otherwise.
      java.util.Iterator<java.lang.Object> iterator()
      Returns an iterator over the items in the inbox in the order they would be returned by the poll() method.
      java.lang.Object peek()
      Retrieves, but does not remove, the head of this inbox, or returns null if it is empty.
      java.lang.Object poll()
      Retrieves and removes the head of this inbox, or returns null if it is empty.
      void remove()
      Removes the head of this inbox.
      int size()
      Returns the number of objects in the inbox.
      • Methods inherited from interface java.lang.Iterable

        forEach, spliterator
    • Method Detail

      • isEmpty

        boolean isEmpty()
        Returns true if this inbox contains no elements, false otherwise.
      • peek

        @Nullable
        java.lang.Object peek()
        Retrieves, but does not remove, the head of this inbox, or returns null if it is empty.
      • poll

        @Nullable
        java.lang.Object poll()
        Retrieves and removes the head of this inbox, or returns null if it is empty.
      • remove

        void remove()
        Removes the head of this inbox. This method throws an exception if the inbox is empty.
        Throws:
        java.util.NoSuchElementException - if this inbox is empty
      • iterator

        @Nonnull
        java.util.Iterator<java.lang.Object> iterator()
        Returns an iterator over the items in the inbox in the order they would be returned by the poll() method.

        The returned iterator doesn't support the Iterator.remove() method.

        Specified by:
        iterator in interface java.lang.Iterable<java.lang.Object>
      • clear

        void clear()
        Removes all items from the inbox.
      • drainTo

        default <E> int drainTo​(java.util.Collection<E> target)
        Drains all elements into the provided Collection.
        Parameters:
        target - the collection to drain this object's items into
        Returns:
        the number of elements actually drained
      • drainTo

        default <E> int drainTo​(@Nonnull
                                java.util.Collection<E> target,
                                int limit)
        Drains at most limit elements into the provided Collection.
        Parameters:
        target - the collection to drain this object's items into
        limit - the maximum amount of items to drain
        Returns:
        the number of elements actually drained
        Since:
        Jet 4.0
      • drainTo

        default <E,​M> int drainTo​(@Nonnull
                                        java.util.Collection<M> target,
                                        int limit,
                                        @Nonnull
                                        java.util.function.Function<E,​M> mapper)
        Drains and maps at most limit elements into the provided Collection.
        Parameters:
        target - the collection to drain this object's items into
        limit - the maximum amount of items to drain
        mapper - mapping function to apply to this object's items
        Returns:
        the number of elements actually drained
        Since:
        Jet 4.1
      • drain

        default <E> int drain​(@Nonnull
                              java.util.function.Consumer<E> consumer)
        Passes each of this object's items to the supplied consumer until it is empty.
        Returns:
        the number of elements drained
      • size

        int size()
        Returns the number of objects in the inbox.