T
- the type of product create by this Bazaarpublic interface Bazaar<T>
Vendor
is queried. Vendor
request certain parameters to create a product.
This is queried from the BazaarContext
. If a AllPermission
parameters requested by a
Vendor
are present in the BazaarContext
, a Vendor
will do a Bid
. The
Vendor
with the highest Bid
will finally create a product.
If two or more Vendor
do the same bid, the registered Bazaar.PriorityOverlapCallBack
will be notified,
an arbitrary Vendor
with the same Bid
will create the product in this case.
To transform parameter in the BazaarContext
into parameters Vendor
s expect, you can register
BazaarContextFunction
s at the Bazaar
.Modifier and Type | Interface and Description |
---|---|
static class |
Bazaar.Builder<T>
A fluent builder of
Bazaar s. |
static interface |
Bazaar.PriorityOverlapCallBack<T>
If two or more
Vendor s make the same bid, the registered
Bazaar.PriorityOverlapCallBack will be
notified,
an arbitrary Vendor with the same Bid will create the product in this case. |
Modifier and Type | Method and Description |
---|---|
void |
addContextFunction(String key,
BazaarContextFunction contextFunction)
Adds a
BazaarContextFunction to this Bazaar to exchange existing parameters to a parameter
requested by a Vendor . |
void |
addVendor(Vendor<? extends T> vendor)
Adds a
Vendor to the bazaar. |
T |
createProduct(BazaarContext context)
Creates a product of type T, provided by the
Vendor with the highest Bid and which is statisfied
by the parameters in the BazaarContext . |
List<T> |
createProducts(BazaarContext context)
Creates a list of products of type T, provided by
Vendor s which are statisfied by the parameters in the
BazaarContext , ordered by their Bid . |
void |
removeVendor(Vendor<? extends T> vendor)
Removes a
Vendor from the bazaar. |
void |
setPriorityOverlapCallBack(Bazaar.PriorityOverlapCallBack<? super T> priorityOverlapCallBack)
|
void addVendor(Vendor<? extends T> vendor)
Vendor
to the bazaar. Will be queried if a product is requested, the best fitting will create the
product. Has no effect if the vendor
is already present in this bazaar.vendor
- the Vendor
void removeVendor(Vendor<? extends T> vendor)
Vendor
from the bazaar. Has no effect if the vendor
is not present in this bazaar.vendor
- the Vendor
to removevoid addContextFunction(String key, BazaarContextFunction contextFunction)
BazaarContextFunction
to this Bazaar
to exchange existing parameters to a parameter
requested by a Vendor
.key
- the key of a requested parameter, which can be exchanged from other available parameters in the
BazaarContext
by this BazaarContextFunction
contextFunction
- the BazaarContextFunction
being able to exchange to the requested parameterT createProduct(BazaarContext context)
Vendor
with the highest Bid
and which is statisfied
by the parameters in the BazaarContext
. In case of tied bids, the Bazaar.PriorityOverlapCallBack
if one is set will be notified of which vendor is chosen to break the tie. Note that during the
bidding process, ties may have to be broken in this way that are later defeated by a higher bid.context
- the BazaarContext
, which is used to provide requested parameters for Vendor
Vendor
setPriorityOverlapCallBack(PriorityOverlapCallBack)
List<T> createProducts(BazaarContext context)
Vendor
s which are statisfied by the parameters in the
BazaarContext
, ordered by their Bid
. Ties are not broken as all bids are successful
and are used only for ordering.context
- the BazaarContext
, which is used to provide requested parameters for Vendor
Bid
void setPriorityOverlapCallBack(Bazaar.PriorityOverlapCallBack<? super T> priorityOverlapCallBack)
priorityOverlapCallBack
- a PriorityOverlapCallBackCopyright © 2019. All rights reserved.