Commit f4ff4c7a authored by Simon Barner's avatar Simon Barner
Browse files

1) Introduce IAllocationType marker interface

 - Used to semantically mark AllocationTables and AllocationEntries (e.g., which layers of the system are connected by allocation, and which system entities)
 - Add IAllocationService.addAllocationEntryType() and getAllocationEntryTypes() to register and query IAllocationTypes
 - Apply IAllocationTypes specializations to Task, Partition and Hardware architecture allocations

2) Move TaskToExecutionUnitAllocationTable and TaskWcetTable to af3.task (to avoid circular dependencies that would arise from the introduction of IAllocationType)

3) Schedule model UI
 - Use IAllocationTypes to provide unified generic UI in af3.schedule.ui
 - Remove most of the temporary hacks since allocation[.ui] is now in the build
 - TODO: Remove SystemScheduleDeploymentPropertySection once Deployment has fully been replaced by AllocationTable

refs 2950,3188,3067
parent 16854dee
......@@ -20,26 +20,4 @@
</modelElementClass>
</modelEditorBinding>
</extension>
<!-- Property Section Contributions -->
<extension point="org.eclipse.ui.views.properties.tabbed.propertySections">
<propertySections contributorId="org.fortiss.tooling.kernel.ui.properties.Contributor">
<propertySection
afterSection="org.fortiss.tooling.kernel.ui.internal.properties.NamedCommentedPropertySection"
class="org.fortiss.af3.schedule.ui.properties.SystemScheduleDeploymentPropertySection"
enablesFor="1"
id="org.fortiss.af3.schedule.ui.properties.SystemScheduleDeploymentPropertySection"
tab="org.fortiss.tooling.kernel.ui.property.tab.general">
<input type="org.fortiss.af3.schedule.model.SystemSchedule"/>
</propertySection>
<propertySection
afterSection="org.fortiss.af3.schedule.ui.properties.SystemScheduleDeploymentPropertySection"
class="org.fortiss.af3.schedule.ui.properties.SystemScheduleAllocationPropertySection"
enablesFor="1"
id="org.fortiss.af3.schedule.ui.properties.SystemScheduleAllocationPropertySection"
tab="org.fortiss.tooling.kernel.ui.property.tab.general">
<input type="org.fortiss.af3.schedule.model.SystemSchedule"/>
</propertySection>
</propertySections>
</extension>
</plugin>
......@@ -14,6 +14,40 @@
<eTypeArguments eClassifier="#//AllocationTable"/>
</eGenericType>
</eOperations>
<eOperations name="getAllocationTables">
<eAnnotations source="http://www.eclipse.org/emf/2002/GenModel">
<details key="documentation" value="Returns the {@link org.fortiss.af3.allocation.model.AllocationTable}s contained by this {@link org.fortiss.af3.allocation.model.AllocationTableCollection} that are of the given {@link IAllocationType}."/>
<details key="body" value="return AllocationTableCollectionStaticImpl.getAllocationTables(this, allocationType);"/>
</eAnnotations>
<eGenericType eClassifier="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EEList">
<eTypeArguments eClassifier="#//AllocationTable"/>
</eGenericType>
<eParameters name="allocationType">
<eGenericType eClassifier="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EJavaClass">
<eTypeArguments>
<eUpperBound eClassifier="#//IAllocationType"/>
</eTypeArguments>
</eGenericType>
</eParameters>
</eOperations>
<eOperations name="getAllocationTables">
<eAnnotations source="http://www.eclipse.org/emf/2002/GenModel">
<details key="documentation" value="Returns the {@link org.fortiss.af3.allocation.model.AllocationTable}s contained by this {@link org.fortiss.af3.allocation.model.AllocationTableCollection} that are of the given {@link IAllocationType}s."/>
<details key="body" value="return AllocationTableCollectionStaticImpl.getAllocationTables(this, allocationTypes);"/>
</eAnnotations>
<eGenericType eClassifier="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EEList">
<eTypeArguments eClassifier="#//AllocationTable"/>
</eGenericType>
<eParameters name="allocationTypes">
<eGenericType eClassifier="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EEList">
<eTypeArguments eClassifier="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EJavaClass">
<eTypeArguments>
<eUpperBound eClassifier="#//IAllocationType"/>
</eTypeArguments>
</eTypeArguments>
</eGenericType>
</eParameters>
</eOperations>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="AllocationTable" abstract="true" eSuperTypes="platform:/resource/org.fortiss.tooling.base/model/base.ecore#//base/HierarchicElementBase">
<eAnnotations source="http://www.eclipse.org/emf/2002/GenModel">
......@@ -332,7 +366,18 @@
<details key="documentation" value="Maker interface to specify that an {@link AllocationEntry} is bidirectional, i.e. that the mapping between target elements and source elements is unique (i.e., target elements may be used in only one {@link AllocationEntry})."/>
</eAnnotations>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="ParameterTable" abstract="true" eSuperTypes="#//AllocationTable">
<eClassifiers xsi:type="ecore:EClass" name="IAllocationType" abstract="true" interface="true">
<eAnnotations source="http://www.eclipse.org/emf/2002/GenModel">
<details key="documentation" value="Marker interface to denote the semantics of {@link AllocationTable}s and {@link AllocationEntry}s."/>
</eAnnotations>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="IAllocationTypeParameter" abstract="true"
interface="true" eSuperTypes="#//IAllocationType">
<eAnnotations source="http://www.eclipse.org/emf/2002/GenModel">
<details key="documentation" value="Marker interface to denote {@link AllocationTable}s and {@link AllocationEntry} that provide parameters (see {@link ParameterTable} and {@link ParameterEntry})."/>
</eAnnotations>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="ParameterTable" abstract="true" eSuperTypes="#//AllocationTable #//IAllocationTypeParameter">
<eAnnotations source="http://www.eclipse.org/emf/2002/GenModel">
<details key="documentation" value="An {@link AllocationTable} specialization used to provide parameters for the cross-product of the model-elements of a source and a target viewpoint. The values are provides as {@link IAnnotatedSpecification}s to the {@link ParameterEntry}s contained in this table."/>
</eAnnotations>
......@@ -354,7 +399,7 @@
</eParameters>
</eOperations>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="ParameterEntry" abstract="true" eSuperTypes="#//OneToOneAllocationEntry #//IUnidirectional platform:/resource/org.fortiss.tooling.kernel/model/kernel.ecore#//INamedElement">
<eClassifiers xsi:type="ecore:EClass" name="ParameterEntry" abstract="true" eSuperTypes="#//OneToOneAllocationEntry #//IUnidirectional platform:/resource/org.fortiss.tooling.kernel/model/kernel.ecore#//INamedElement #//IAllocationTypeParameter">
<eAnnotations source="http://www.eclipse.org/emf/2002/GenModel">
<details key="documentation" value="Base class for entries of {@link ParameterTable} specializations. The acutal parameter values are provided as {@link IAnnotatedSpecification}s of specializations of this class."/>
</eAnnotations>
......
......@@ -13,6 +13,12 @@
ecorePackage="allocation.ecore#/">
<genClasses ecoreClass="allocation.ecore#//AllocationTableCollection">
<genOperations ecoreOperation="allocation.ecore#//AllocationTableCollection/getAllocationTables"/>
<genOperations ecoreOperation="allocation.ecore#//AllocationTableCollection/getAllocationTables.1">
<genParameters ecoreParameter="allocation.ecore#//AllocationTableCollection/getAllocationTables.1/allocationType"/>
</genOperations>
<genOperations ecoreOperation="allocation.ecore#//AllocationTableCollection/getAllocationTables.2">
<genParameters ecoreParameter="allocation.ecore#//AllocationTableCollection/getAllocationTables.2/allocationTypes"/>
</genOperations>
</genClasses>
<genClasses ecoreClass="allocation.ecore#//AllocationTable">
<genFeatures notify="false" createChild="false" propertySortChoices="true" ecoreFeature="ecore:EReference allocation.ecore#//AllocationTable/sourceView"/>
......@@ -90,6 +96,8 @@
<genClasses image="false" ecoreClass="allocation.ecore#//IDirection"/>
<genClasses image="false" ecoreClass="allocation.ecore#//IUnidirectional"/>
<genClasses image="false" ecoreClass="allocation.ecore#//IBidirectional"/>
<genClasses image="false" ecoreClass="allocation.ecore#//IAllocationType"/>
<genClasses image="false" ecoreClass="allocation.ecore#//IAllocationTypeParameter"/>
<genClasses ecoreClass="allocation.ecore#//ParameterTable">
<genOperations ecoreOperation="allocation.ecore#//ParameterTable/getParameter">
<genParameters ecoreParameter="allocation.ecore#//ParameterTable/getParameter/sourceElement"/>
......
AF3AllocationActivator.java db64a468f2e3079907f0c82be9c675ef3932f786 GREEN
IAllocationService.java d978593a040eea44d81391f734069f1f13cf90cf YELLOW
IAllocationService.java 4a9168dd5c02753155658bc9590ca286f2f841a7 YELLOW
......@@ -20,6 +20,7 @@ import java.util.Collection;
import org.fortiss.af3.allocation.internal.AllocationService;
import org.fortiss.af3.allocation.model.AllocationEntry;
import org.fortiss.af3.allocation.model.AllocationTable;
import org.fortiss.af3.allocation.model.IAllocationType;
import org.fortiss.tooling.base.model.element.IModelElement;
import org.fortiss.tooling.kernel.model.IProjectRootElement;
......@@ -41,6 +42,31 @@ public interface IAllocationService {
/** Initializes the service. */
public void initializeService();
/**
* Registers an {@link AllocationEntry} specialization with a given {@link AllocationTable}
* specialization.
*/
public
<T extends AllocationTable & IAllocationType, E extends AllocationEntry & IAllocationType>
void addAllocationEntryType(Class<? extends T> allocationTableType,
Class<? extends E> allocationEntryType);
/**
* Returns the {@link AllocationEntry} types of the given {@code allocationType} that are
* registered to the given {@link AllocationTable} type.
*
* @param allocationTableType
* {@link AllocationTable} for which to obtain {@link AllocationEntry} types.
* @param allocationTypes
* Desired {@link IAllocationType}s (optional)
* @return {@link AllocationEntry} types of the given {@code allocationType} that are
* registered to the given {@link AllocationTable} type.
*/
public <E extends AllocationEntry & IAllocationType, A extends IAllocationType>
Collection<Class<? extends AllocationEntry>> getAllocationEntryTypes(
Class<? extends AllocationTable> allocationTableType,
@SuppressWarnings("unchecked") Class<? extends A>... allocationTypes);
/** Registers a source model entity type with the given {@link AllocationEntry} specialization. */
public void addSourceEntityType(Class<? extends AllocationEntry> allocationEntryType,
Class<? extends IModelElement> sourceEntityType);
......
......@@ -16,15 +16,19 @@
package org.fortiss.af3.allocation.internal;
import static java.util.Collections.emptyList;
import static org.fortiss.tooling.common.util.LambdaUtils.filterTypes;
import java.util.Collection;
import java.util.HashMap;
import java.util.Comparator;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import org.eclipse.emf.ecore.EClass;
import org.fortiss.af3.allocation.IAllocationService;
import org.fortiss.af3.allocation.model.AllocationEntry;
import org.fortiss.af3.allocation.model.AllocationTable;
import org.fortiss.af3.allocation.model.IAllocationType;
import org.fortiss.tooling.base.model.element.IModelElement;
import org.fortiss.tooling.kernel.introspection.IIntrospectionDetailsItem;
import org.fortiss.tooling.kernel.introspection.IIntrospectionItem;
......@@ -38,60 +42,104 @@ import org.fortiss.tooling.kernel.service.IKernelIntrospectionSystemService;
* @author barner
*/
public final class AllocationService implements IAllocationService, IIntrospectiveKernelService {
/**
* Base class to map an EMF type to a target type. For a given {@link EClass} {@code Foo}, the
* map considers the generated interface class {@code Foo} and the corresponding implementation
* class {@code FooImpl} identical.
*/
private abstract class EMFTypeMap<S, T> extends TreeMap<Class<? extends S>, T> {
/**
* Suffix used by EMF to denote implementation classes of the Java interfaces corresponding
* to EClasses.
*/
private static final String IMPL_CLASS_SUFFIX = "Impl";
/** Constructor. */
public EMFTypeMap() {
super(new Comparator<Class<? extends S>>() {
@SuppressWarnings("unchecked")
private Class<? extends S> getInterfaceType(Class<? extends S> c) {
final String className = c.getSimpleName();
if(className.endsWith(IMPL_CLASS_SUFFIX)) {
final String ifaceName =
className.substring(0,
className.length() - IMPL_CLASS_SUFFIX.length());
for(Class<?> iFace : c.getInterfaces()) {
if(iFace.getSimpleName().equals(ifaceName)) {
return (Class<? extends S>)iFace;
}
}
}
return c;
}
/** {@inheritDoc} */
@Override
public int compare(Class<? extends S> c1, Class<? extends S> c2) {
Class<? extends S> i1 = getInterfaceType(c1);
Class<? extends S> i2 = getInterfaceType(c2);
if(i1 == i2) {
return 0;
}
return i1.getCanonicalName().compareTo(i2.getCanonicalName());
}
});
}
}
/** Maps a given EMF type to a {@link Set} of types. */
private class EMFTypeToTypeSetMap<S, T> extends EMFTypeMap<S, TypeSet<T>> {
// Nothing to do
}
/** Target type for {@link EMFTypeToTypeSetMap}. */
private class TypeSet<T> extends LinkedHashSet<Class<? extends T>> {
// Nothing to do
}
/** Maps {@link AllocationEntry}s to source/target entity types. */
private class EntityTypeMap
extends
HashMap<Class<? extends AllocationEntry>, LinkedHashSet<Class<? extends IModelElement>>> {
/** Maps a given EMF type to another type. */
private class EMFTypeToTypeMap<S, T> extends EMFTypeMap<S, Class<? extends T>> {
// Nothing to do
}
/** Maps an {@link AllocationEntry} to the list of admissible source element types. */
private EntityTypeMap sourceEntityTypeMap = new EntityTypeMap();
private EMFTypeToTypeSetMap<AllocationEntry, IModelElement> sourceEntityTypeMap =
new EMFTypeToTypeSetMap<AllocationEntry, IModelElement>();
/** Maps an {@link AllocationEntry} to the list of admissible target element types. */
private EntityTypeMap targetEntityTypeMap = new EntityTypeMap();
private EMFTypeToTypeSetMap<AllocationEntry, IModelElement> targetEntityTypeMap =
new EMFTypeToTypeSetMap<AllocationEntry, IModelElement>();
/** Maps an {@link AllocationTable} type to a source model type. */
private Map<Class<? extends AllocationTable>, Class<? extends IProjectRootElement>> sourceModelTypeMap =
new HashMap<Class<? extends AllocationTable>, Class<? extends IProjectRootElement>>();
private EMFTypeToTypeMap<AllocationTable, IProjectRootElement> sourceModelTypeMap =
new EMFTypeToTypeMap<AllocationTable, IProjectRootElement>();
/** Maps an {@link AllocationTable} type to a target model type. */
private Map<Class<? extends AllocationTable>, Class<? extends IProjectRootElement>> targetModelTypeMap =
new HashMap<Class<? extends AllocationTable>, Class<? extends IProjectRootElement>>();
/**
* Type used to map {@link AllocationTable}s to model types are covered by it in addition to
* their source and target model types.
*/
private class CoveredModelTypeMap
extends
HashMap<Class<? extends AllocationTable>, LinkedHashSet<Class<? extends IProjectRootElement>>> {
// Nothing to do
}
private EMFTypeToTypeMap<AllocationTable, IProjectRootElement> targetModelTypeMap =
new EMFTypeToTypeMap<AllocationTable, IProjectRootElement>();
/**
* Maps {@link AllocationTable}s to model types are covered by it in addition to their
* source and target model types.
*/
private CoveredModelTypeMap coveredModelTypeMap = new CoveredModelTypeMap();
private EMFTypeToTypeSetMap<AllocationTable, IProjectRootElement> coveredModelTypeMap =
new EMFTypeToTypeSetMap<AllocationTable, IProjectRootElement>();
/**
* Type used to map a given {@link AllocationTable} to {@link AllocationTable}s that may exist
* Maps a given {@link AllocationTable} to {@link AllocationTable}s that may exist
* together with it despite overlapping source/target model types.
*/
private class AdmissibleAllocationTableTypeMap
extends
HashMap<Class<? extends AllocationTable>, LinkedHashSet<Class<? extends AllocationTable>>> {
// Nothing to do
}
private EMFTypeToTypeSetMap<AllocationTable, AllocationTable> admissibleAllocationTableTypeMap =
new EMFTypeToTypeSetMap<AllocationTable, AllocationTable>();
/**
* Maps a given {@link AllocationTable} to {@link AllocationTable}s that may exist
* together with it despite overlapping source/target model types.
* Maps {@link AllocationTable} types to the {@link AllocationEntry} types that may be added to
* them.
*/
private AdmissibleAllocationTableTypeMap admissibleAllocationTableTypeMap =
new AdmissibleAllocationTableTypeMap();
private EMFTypeToTypeSetMap<AllocationTable, AllocationEntry> allocationTableEntryTypeMap =
new EMFTypeToTypeSetMap<AllocationTable, AllocationEntry>();
/** The singleton instance. */
private static final AllocationService INSTANCE = new AllocationService();
......@@ -115,17 +163,46 @@ public final class AllocationService implements IAllocationService, IIntrospecti
// nothing to do here
}
/** {@inheritDoc} */
@Override
public
<T extends AllocationTable & IAllocationType, E extends AllocationEntry & IAllocationType>
void addAllocationEntryType(Class<? extends T> allocationTableType,
Class<? extends E> allocationEntryType) {
TypeSet<AllocationEntry> allocationEntryTypes =
allocationTableEntryTypeMap.get(allocationTableType);
if(allocationEntryTypes == null) {
allocationEntryTypes = new TypeSet<AllocationEntry>();
allocationTableEntryTypeMap.put(allocationTableType, allocationEntryTypes);
}
allocationEntryTypes.add(allocationEntryType);
}
/** {@inheritDoc} */
@SafeVarargs
@Override
public final <E extends AllocationEntry & IAllocationType, A extends IAllocationType>
Collection<Class<? extends AllocationEntry>> getAllocationEntryTypes(
Class<? extends AllocationTable> allocationTableType,
Class<? extends A>... allocationTypes) {
final LinkedHashSet<Class<? extends AllocationEntry>> entries =
allocationTableEntryTypeMap.get(allocationTableType);
return entries != null ? filterTypes(entries, allocationTypes) : emptyList();
}
/**
* Helper to implement {@link #addSourceEntityType(Class, Class)} and
* {@link #addTargetEntityType(Class, Class)}.
*/
private void addEntityType(EntityTypeMap entityTypeMap,
private void addEntityType(EMFTypeToTypeSetMap<AllocationEntry, IModelElement> entityTypeMap,
Class<? extends AllocationEntry> allocationEntryType,
Class<? extends IModelElement> entityType) {
LinkedHashSet<Class<? extends IModelElement>> sourceEntityTypes =
entityTypeMap.get(allocationEntryType);
TypeSet<IModelElement> sourceEntityTypes = entityTypeMap.get(allocationEntryType);
if(sourceEntityTypes == null) {
sourceEntityTypes = new LinkedHashSet<Class<? extends IModelElement>>();
sourceEntityTypes = new TypeSet<IModelElement>();
entityTypeMap.put(allocationEntryType, sourceEntityTypes);
}
......@@ -208,10 +285,10 @@ public final class AllocationService implements IAllocationService, IIntrospecti
@Override
public void addCoveredModelType(Class<? extends AllocationTable> allocationTableType,
Class<? extends IProjectRootElement> targetModelType) {
LinkedHashSet<Class<? extends IProjectRootElement>> coveredModelTypes =
TypeSet<IProjectRootElement> coveredModelTypes =
coveredModelTypeMap.get(allocationTableType);
if(coveredModelTypes == null) {
coveredModelTypes = new LinkedHashSet<Class<? extends IProjectRootElement>>();
coveredModelTypes = new TypeSet<IProjectRootElement>();
coveredModelTypeMap.put(allocationTableType, coveredModelTypes);
}
......@@ -230,10 +307,10 @@ public final class AllocationService implements IAllocationService, IIntrospecti
/** Helper to implement {@link #addAdmissibleAllocationTablePair(Class, Class)}. */
private void addAdmissibleAllocationTablePairInternal(Class<? extends AllocationTable> atType1,
Class<? extends AllocationTable> atType2) {
LinkedHashSet<Class<? extends AllocationTable>> allocationTableTypes =
TypeSet<AllocationTable> allocationTableTypes =
admissibleAllocationTableTypeMap.get(atType1);
if(allocationTableTypes == null) {
allocationTableTypes = new LinkedHashSet<Class<? extends AllocationTable>>();
allocationTableTypes = new TypeSet<AllocationTable>();
admissibleAllocationTableTypeMap.put(atType1, allocationTableTypes);
}
......
AF3AllocationFactoryImplCustom.java 46630be40ab1aa52cd8312c2abac7572cef06f41 GREEN
AllocationEntryStaticImpl.java c32ceaafa60123f19e852b63860e62613ed98802 YELLOW
AllocationTableCollectionStaticImpl.java 27131d10e64c7640339337e900257c11427ce9d2 GREEN
AllocationTableStaticImpl.java f22462d5f66a4327834d29799ed1028ab2ce8da3 YELLOW
AllocationTableCollectionStaticImpl.java c8c413bf4c09cbba4bf1b47a86b693b5417b4062 YELLOW
AllocationTableStaticImpl.java f3e9d5d6ac65b11dedd0a82aa054e55db03735ff YELLOW
ParameterEntryStaticImpl.java 06582395715b198d2ffbfe0bafb81f10897a3149 YELLOW
ParameterTableStaticImpl.java cd90fc207370734ea590bdabc65a30efa8cb6e79 YELLOW
......@@ -15,12 +15,16 @@
+--------------------------------------------------------------------------*/
package org.fortiss.af3.allocation.model.impl;
import static org.eclipse.emf.common.util.ECollections.singletonEList;
import static org.fortiss.tooling.common.util.LambdaUtils.filterByTypes;
import static org.fortiss.tooling.kernel.utils.EcoreUtils.pickInstanceOf;
import org.eclipse.emf.common.util.BasicEList;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EOperation;
import org.fortiss.af3.allocation.model.AllocationTable;
import org.fortiss.af3.allocation.model.AllocationTableCollection;
import org.fortiss.af3.allocation.model.IAllocationType;
/**
* Implementation of {@link EOperation}s of class {@link AllocationTableCollection}.
......@@ -44,4 +48,49 @@ public class AllocationTableCollectionStaticImpl {
return pickInstanceOf(AllocationTable.class,
allocationTableCollection.getContainedElements());
}
/**
* Returns the {@link AllocationTable}s contained by the given {@link AllocationTableCollection}
* that are of the given {@link IAllocationType}s.
* .
*
* @param allocationTableCollection
* {@link AllocationTableCollection} for which to the return the contained
* {@link AllocationTable}s.
*
* @param allocationType
* Desired {@link IAllocationType}s.
*
* @return {@link AllocationTable}s contained by the given {@link AllocationTableCollection}
* that are of the given {@link IAllocationType}.
*/
public static EList<AllocationTable> getAllocationTables(
AllocationTableCollectionImpl allocationTableCollection,
Class<? extends IAllocationType> allocationType) {
return getAllocationTables(allocationTableCollection, singletonEList(allocationType));
}
/**
* Returns the {@link AllocationTable}s contained by the given {@link AllocationTableCollection}
* that are of the given {@link IAllocationType}s.
* .
*
* @param allocationTableCollection
* {@link AllocationTableCollection} for which to the return the contained
* {@link AllocationTable}s.
*
* @param allocationTypes
* Desired {@link IAllocationType}s.
*
* @return {@link AllocationTable}s contained by the given {@link AllocationTableCollection}
* that are of the given {@link IAllocationType}.
*/
public static EList<AllocationTable> getAllocationTables(
AllocationTableCollection allocationTableCollection,
final EList<Class<? extends IAllocationType>> allocationTypes) {
EList<AllocationTable> ats = getAllocationTables(allocationTableCollection);
Class<?>[] types = new Class<?>[allocationTypes.size()];
return new BasicEList<AllocationTable>(filterByTypes(ats, allocationTypes.toArray(types)));
}
}
......@@ -16,6 +16,7 @@
package org.fortiss.af3.allocation.model.impl;
import static java.util.stream.Collectors.toCollection;
import static org.eclipse.emf.common.util.ECollections.singletonEList;
import static org.fortiss.tooling.kernel.utils.EcoreUtils.pickInstanceOf;
import java.util.HashSet;
......@@ -39,6 +40,11 @@ import org.fortiss.tooling.base.model.element.IModelElement;
* @author barner
*/
public class AllocationTableStaticImpl {
/** Converts the given {@link Set} into an {@link EList}. */
private static <T> EList<T> toEList(Set<T> set) {
return set.stream().collect(toCollection(BasicEList<T>::new));
}
/**
* Returns the {@link AllocationEntry}s contained by the given {@link AllocationTable}.
*
......@@ -71,6 +77,12 @@ public class AllocationTableStaticImpl {
return pickInstanceOf(type, allocationTable.getContainedElements());
}
/** Clears all {@link AllocationEntry}s from the given {@link AllocationTable}. */
public static void clearAllocationEntries(AllocationTable allocationTable) {
// Compositors ensure that AllocationEntries are the only child elements of AllocationTables
allocationTable.getContainedElements().clear();
}
/**
* Returns the target element to which the given source element is mapped in a
* {@link IBidirectional} {@link OneToOneAllocationEntry}, or {@code null} in case no such
......@@ -137,13 +149,8 @@ public class AllocationTableStaticImpl {
}
/**
* Returns the target elements to which the given source element is mapped in a
* <ul>
* <li>a {@link IBidirectional} {@link OneToManyAllocationEntry},</li>
* <li>one or more {@link IUnidirectional} {@link OneToManyAllocationEntry}s,</li>
* <li>one or more {@link IUnidirectional} {@link OneToOneAllocationEntry}s.</li>
* </ul>
* Returns {@code null} in case no such mapping has been defined.
* Returns the target elements to which the given source element is mapped ({@code null} in case
* no such mapping has been defined).
*
* @param allocationTable
* {@link AllocationTable} in which to lookup target model element for given source
......@@ -151,57 +158,51 @@ public class AllocationTableStaticImpl {
* @param sourceElement
* Source model element to lookup in given {@link AllocationTable}.
* @param type
* Underlying 1:n or 1:1 {@link AllocationEntry} type.
* Underlying {@link AllocationEntry} type.
* @return Source elements which are mapped to the given target element or {@code null} in case
* no such mapping has been defined.
*
* @throws RuntimeException
* in case of an inapplicable {@link AllocationEntry} {@code type}.
*/
@SuppressWarnings("unchecked")
public static <T extends AllocationEntry> EList<IModelElement> getTargetElements(
AllocationTable allocationTable, IModelElement sourceElement, Class<T> type) {
Set<IModelElement> rval = new HashSet<IModelElement>();
if(OneToManyAllocationEntry.class.isAssignableFrom(type)) {
if(IBidirectional.class.isAssignableFrom(type)) {
for(OneToManyAllocationEntry ae : getAllocationEntries(allocationTable,
(Class<OneToManyAllocationEntry>)type)) {
if(ae.getSourceElement() == sourceElement) {
for(OneToManyAllocationEntry ae : getAllocationEntries(allocationTable,
(Class<OneToManyAllocationEntry>)type)) {
if(ae.getSourceElement() == sourceElement) {
if(IBidirectional.class.isAssignableFrom(type)) {
return ae.getTargetElements();
}
}
} else if(IUnidirectional.class.isAssignableFrom(type)) {
Set<IModelElement> rval = new HashSet<IModelElement>();
for(OneToManyAllocationEntry ae : getAllocationEntries(allocationTable,
(Class<OneToManyAllocationEntry>)type)) {
if(ae.getSourceElement