Class BazaarImpl<T>
- java.lang.Object
-
- org.eclipse.emfforms.bazaar.internal.BazaarImpl<T>
-
- Type Parameters:
T
- the type of product produced by thisBazaar
- All Implemented Interfaces:
Bazaar<T>
- Direct Known Subclasses:
ThreadSafeBazaar
public class BazaarImpl<T> extends java.lang.Object implements Bazaar<T>
Implementation of aBazaar
using theIEclipseContext
for dependency injection.- Author:
- jonas
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.eclipse.emfforms.bazaar.Bazaar
Bazaar.Builder<T>, Bazaar.PriorityOverlapCallBack<T>
-
-
Constructor Summary
Constructors Constructor Description BazaarImpl()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addContextFunction(java.lang.String key, BazaarContextFunction contextFunction)
Adds aBazaarContextFunction
to thisBazaar
to exchange existing parameters to a parameter requested by aVendor
.org.eclipse.e4.core.contexts.IEclipseContext
addContextFunctions(org.eclipse.e4.core.contexts.IEclipseContext context)
Transforms allBazaarContextFunction
s toIContextFunction
s and attaches those to anIEclipseContext
.void
addVendor(Vendor<? extends T> vendor)
Adds aVendor
to the bazaar.boolean
checkPreConditions(Vendor<? extends T> vendor, org.eclipse.e4.core.contexts.IEclipseContext context)
Checks thePrecondition
s for a given vendor.org.eclipse.e4.core.contexts.IEclipseContext
createEclipseContext(BazaarContext bazaarContext)
Creates anIEclipseContext
from aBazaarContext
.T
createProduct(BazaarContext bazaarContext)
Creates a product of type T, provided by theVendor
with the highestBid
and which is statisfied by the parameters in theBazaarContext
.T
createProduct(Vendor<? extends T> vendor, org.eclipse.e4.core.contexts.IEclipseContext context)
Returns the product which is provided with the highest priority by anyVendor
.java.util.List<T>
createProducts(BazaarContext bazaarContext)
Creates a list of products of type T, provided byVendor
s which are statisfied by the parameters in theBazaarContext
, ordered by theirBid
.Vendor<? extends T>
getBestVendor(org.eclipse.e4.core.contexts.IEclipseContext context)
void
removeVendor(Vendor<? extends T> vendor)
Removes aVendor
from the bazaar.void
setPriorityOverlapCallBack(Bazaar.PriorityOverlapCallBack<? super T> priorityOverlapCallBack)
-
-
-
Method Detail
-
addVendor
public void addVendor(Vendor<? extends T> vendor)
Description copied from interface:Bazaar
Adds aVendor
to the bazaar. Will be queried if a product is requested, the best fitting will create the product. Has no effect if thevendor
is already present in this bazaar.
-
removeVendor
public void removeVendor(Vendor<? extends T> vendor)
Description copied from interface:Bazaar
Removes aVendor
from the bazaar. Has no effect if thevendor
is not present in this bazaar.- Specified by:
removeVendor
in interfaceBazaar<T>
- Parameters:
vendor
- theVendor
to remove
-
createProduct
public T createProduct(Vendor<? extends T> vendor, org.eclipse.e4.core.contexts.IEclipseContext context)
Returns the product which is provided with the highest priority by anyVendor
.
-
addContextFunctions
public org.eclipse.e4.core.contexts.IEclipseContext addContextFunctions(org.eclipse.e4.core.contexts.IEclipseContext context)
Transforms allBazaarContextFunction
s toIContextFunction
s and attaches those to anIEclipseContext
.- Parameters:
context
- theIEclipseContext
to attacheIContextFunction
s to- Returns:
- the
IEclipseContext
with attachedIContextFunction
-
createEclipseContext
public org.eclipse.e4.core.contexts.IEclipseContext createEclipseContext(BazaarContext bazaarContext)
Creates anIEclipseContext
from aBazaarContext
. If the bazaar context contains an Eclipse context, then it is used and will have all other values set into it from the bazaar context.- Parameters:
bazaarContext
- theBazaarContext
to get key / values from- Returns:
- a
IEclipseContext
containign all key / values provided by theBazaarContext
-
getBestVendor
public Vendor<? extends T> getBestVendor(org.eclipse.e4.core.contexts.IEclipseContext context)
- Parameters:
context
- the Eclipse injection context- Returns:
- obtains the best available vendor for the give
context
-
setPriorityOverlapCallBack
public void setPriorityOverlapCallBack(Bazaar.PriorityOverlapCallBack<? super T> priorityOverlapCallBack)
Description copied from interface:Bazaar
- Specified by:
setPriorityOverlapCallBack
in interfaceBazaar<T>
- Parameters:
priorityOverlapCallBack
- a PriorityOverlapCallBack
-
addContextFunction
public void addContextFunction(java.lang.String key, BazaarContextFunction contextFunction)
Description copied from interface:Bazaar
Adds aBazaarContextFunction
to thisBazaar
to exchange existing parameters to a parameter requested by aVendor
.- Specified by:
addContextFunction
in interfaceBazaar<T>
- Parameters:
key
-contextFunction
-
-
createProduct
public T createProduct(BazaarContext bazaarContext)
Description copied from interface:Bazaar
Creates a product of type T, provided by theVendor
with the highestBid
and which is statisfied by the parameters in theBazaarContext
. In case of tied bids, theBazaar.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.- Specified by:
createProduct
in interfaceBazaar<T>
- Parameters:
bazaarContext
- theBazaarContext
, which is used to provide requested parameters forVendor
- Returns:
- the product provided by the best
Vendor
- See Also:
Bazaar.createProduct(org.eclipse.emfforms.bazaar.BazaarContext)
-
createProducts
public java.util.List<T> createProducts(BazaarContext bazaarContext)
Description copied from interface:Bazaar
Creates a list of products of type T, provided byVendor
s which are statisfied by the parameters in theBazaarContext
, ordered by theirBid
. Ties are not broken as all bids are successful and are used only for ordering.- Specified by:
createProducts
in interfaceBazaar<T>
- Parameters:
bazaarContext
- theBazaarContext
, which is used to provide requested parameters forVendor
- Returns:
- a list of products ordered by the highest
Bid
- See Also:
Bazaar.createProducts(org.eclipse.emfforms.bazaar.BazaarContext)
-
checkPreConditions
public boolean checkPreConditions(Vendor<? extends T> vendor, org.eclipse.e4.core.contexts.IEclipseContext context)
Checks thePrecondition
s for a given vendor.- Parameters:
vendor
- TheVendor
to check thePrecondition
for.context
- TheIEclipseContext
to provide thePrecondition
- Returns:
- whether the
Precondition
s are fulfilled
-
-