Class Bazaar.Builder<T>

  • Type Parameters:
    T - the type of product provided by the bazaar
    Enclosing interface:
    Bazaar<T>

    public static final class Bazaar.Builder<T>
    extends java.lang.Object
    A fluent builder of Bazaars.
    Author:
    Christian W. Damus
    • Method Detail

      • empty

        public static <T> Bazaar.Builder<T> empty()
        Creates a new empty bazaar builder.
        Type Parameters:
        T - the type of product provided by the Bazaar
        Returns:
        an initially empty builder
      • with

        public static <T> Bazaar.Builder<T> with​(java.util.Collection<? extends Vendor<? extends T>> vendors)
        Creates a new bazaar builder with the given initial vendors.
        Type Parameters:
        T - the type of product provided by the Bazaar
        Parameters:
        vendors - initial vendors
        Returns:
        an initialized builder
      • add

        public Bazaar.Builder<T> add​(Vendor<? extends T> vendor)
        Adds a vendor.
        Parameters:
        vendor - the vendor to add
        Returns:
        this builder
      • add

        public Bazaar.Builder<T> add​(Vendor<? extends T> vendor1,
                                     Vendor<? extends T> vendor2,
                                     Vendor<? extends T>... more)
        Adds vendors.
        Parameters:
        vendor1 - a vendor to add
        vendor2 - another vendor to add
        more - optional additional vendors to add
        Returns:
        this builder
      • addAll

        public Bazaar.Builder<T> addAll​(java.util.Collection<? extends Vendor<? extends T>> vendors)
        Adds vendors.
        Parameters:
        vendors - vendors to add
        Returns:
        this builder
      • addContextFunction

        public Bazaar.Builder<T> addContextFunction​(java.lang.Class<?> type,
                                                    BazaarContextFunction contextFunction)
        Add a context function.
        Parameters:
        type - the context value type provided by the function
        contextFunction - the context function to add
        Returns:
        this Bazaar.Builder
      • addContextFunction

        public Bazaar.Builder<T> addContextFunction​(java.lang.String key,
                                                    BazaarContextFunction contextFunction)
        Add a context function.
        Parameters:
        key - the context key for the function
        contextFunction - the context function to add
        Returns:
        this Bazaar.Builder
      • onPriorityOverlap

        public Bazaar.Builder<T> onPriorityOverlap​(Bazaar.PriorityOverlapCallBack<? super T> overlapHandler)
        Set the handler for priority overlaps. This may only be set once.
        Parameters:
        overlapHandler - the overlap handler to set
        Returns:
        this builder
      • threadSafe

        public Bazaar.Builder<T> threadSafe()
        Request that the bazaar be thread-safe. This is useful for bazaars that may be accessed arbitrarily by concurrent threads. By default, the builder creates bazaars that are not thread-safe.
        Returns:
        this builder
      • build

        public Bazaar<T> build()
        Create the bazaar. Further updates to the builder will have no effect on the resulting bazaar.
        Returns:
        the bazaar