Commit b0c25b3c authored by Simon Barner's avatar Simon Barner Committed by Marco Volpe
Browse files

Allocation Service: Manage mutually exclusive allocation types

* Add methods that allow for a given entry type to defines another
  another one that is mutually exclusive it with w.r.t. the
  source/target entity.
* Add methods to query for a given reference entry type the set of all
  entry types that are mutually exclusive w.r.t. source/target entity.
  I.e., from entries that are of one the types in the set, only a single
  one may refer to a particular source/target entity within an
  allocation table.

Issue-Ref: 3561
Issue-Url: https://af3-developer.fortiss.org/issues/3561

Signed-off-by: Simon Barner's avatarSimon Barner <barner@fortiss.org>
parent 07926d8d
AF3AllocationActivator.java fa98bbdbd34d9d3c76f7f2827f2f456105c90fa6 GREEN
IAllocationService.java 9f099734eb339a3fadd601e65ec5821b6e5afb31 GREEN
IAllocationService.java ccbb1e3a5c62a18b5a4f9bb0f8e74282e4cc4d08 YELLOW
......@@ -189,4 +189,42 @@ public interface IAllocationService {
*/
public Collection<Class<? extends AllocationEntry>>
getChildEntryTypes(Class<? extends AllocationEntry> parentEntryType);
/**
* For the given {@link AllocationEntry} type, defines another {@link AllocationEntry} that is
* mutually exclusive it with w.r.t. the source entity. This means that from set of all
* {@link AllocationEntry} types that can be constructed by subsequent calls of this method,
* only a single {@link AllocationEntry} may refer to a particular source entity within an
* {@link AllocationTable}.
*/
public void addSourceEntityMutualEntryTypeExclusion(
Class<? extends AllocationEntry> allocationEntryType,
Class<? extends AllocationEntry> otherAllocationEntryType);
/**
* For the given {@link AllocationEntry} type, defines another {@link AllocationEntry} that is
* mutually exclusive it with w.r.t. the target entity. This means that from set of all
* {@link AllocationEntry} types that can be constructed by subsequent calls of this method,
* only a single {@link AllocationEntry} may refer to a particular target entity within an
* {@link AllocationTable}.
*/
public void addTargetEntityMutualEntryTypeExclusion(
Class<? extends AllocationEntry> allocationEntryType,
Class<? extends AllocationEntry> otherAllocationEntryType);
/**
* For the given reference {@link AllocationEntry} type, returns the set of all
* {@link AllocationEntry} types that are mutually exclusive w.r.t. source entity (including the
* reference element). In case no such types are registered, the method returns {@code null}.
*/
public Collection<Class<? extends AllocationEntry>> getSourceEntityMutuallyExclusiveEntryTypes(
Class<? extends AllocationEntry> referenceEntryType);
/**
* For the given reference {@link AllocationEntry} type, returns the set of all
* {@link AllocationEntry} types that are mutually exclusive w.r.t. target entity (including the
* reference element). In case no such types are registered, the method returns {@code null}.
*/
public Collection<Class<? extends AllocationEntry>> getTargetEntityMutuallyExclusiveEntryTypes(
Class<? extends AllocationEntry> referenceEntryType);
}
AllocationService.java 61c2e101e27142cfad8d710b87cf41de7fd6bfa9 GREEN
AllocationService.java f07a9ba862ec98b32938a3f9ffde4095ec15f6e7 YELLOW
......@@ -18,9 +18,11 @@ package org.fortiss.af3.allocation.internal;
import static java.util.Collections.emptyList;
import static org.fortiss.tooling.common.util.LambdaUtils.filterTypes;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Comparator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import java.util.TreeMap;
......@@ -157,6 +159,20 @@ public final class AllocationService implements IAllocationService, IIntrospecti
private EMFTypeToTypeMap<AllocationEntry, AllocationEntry> childParentEntryTypeMap =
new EMFTypeToTypeMap<AllocationEntry, AllocationEntry>();
/**
* {@link List} of {@link AllocationEntry} sets that are mutually exclusive w.r.t. source
* entities.
*/
private List<TypeSet<AllocationEntry>> sourceEntityMutualExclusions = new ArrayList<>();
/**
* {@link List} of {@link AllocationEntry} sets that are mutually exclusive w.r.t. target
* entities.
*/
private List<TypeSet<AllocationEntry>> targetEntityMutualExclusions = new ArrayList<>();
/** AllocationEntries that are mutually exclusive w.r.t. target entities. */
/** The singleton instance. */
private static final AllocationService INSTANCE = new AllocationService();
......@@ -465,4 +481,79 @@ public final class AllocationService implements IAllocationService, IIntrospecti
return childEntryTypes != null ? childEntryTypes : emptyList();
}
/**
* Helper for {@link #addSourceEntityMutualEntryTypeExclusion(Class, Class)} and
* {@link #addTargetEntityMutualEntryTypeExclusion(Class, Class)}.
*/
private void addMutualExclusionEntityType(List<TypeSet<AllocationEntry>> mutualExclusions,
Class<? extends AllocationEntry> allocationEntryType,
Class<? extends AllocationEntry> otherAllocationEntryType) {
TypeSet<AllocationEntry> entrySet =
getMutualExclusionTypeSet(mutualExclusions, allocationEntryType);
if(entrySet == null) {
entrySet = getMutualExclusionTypeSet(mutualExclusions, otherAllocationEntryType);
} else {
// Set for allocationEntryType has been found: add otherAllocationEntryType
entrySet.add(otherAllocationEntryType);
return;
}
if(entrySet == null) {
entrySet = new TypeSet<AllocationEntry>();
entrySet.add(allocationEntryType);
entrySet.add(otherAllocationEntryType);
// Set has not been found for either of the provided allocation entry types: Create it.
} else {
entrySet.add(allocationEntryType);
// Set for otherAllocationEntryType has been found: add allocationEntryType
entrySet.add(otherAllocationEntryType);
}
}
/** {@inheritDoc} */
@Override
public void addSourceEntityMutualEntryTypeExclusion(Class<? extends AllocationEntry> allocationEntryType,
Class<? extends AllocationEntry> otherAllocationEntryType) {
addMutualExclusionEntityType(sourceEntityMutualExclusions, allocationEntryType,
otherAllocationEntryType);
}
/** {@inheritDoc} */
@Override
public void addTargetEntityMutualEntryTypeExclusion(Class<? extends AllocationEntry> allocationEntryType,
Class<? extends AllocationEntry> otherAllocationEntryType) {
addMutualExclusionEntityType(targetEntityMutualExclusions, allocationEntryType,
otherAllocationEntryType);
}
/**
* Obtains the set that contains the given {@code referenceEntryType} from the given
* List{@link List} of {@link AllocationEntry} type sets. In case it does not exist,
* {@code null} is returned.
*/
private TypeSet<AllocationEntry> getMutualExclusionTypeSet(
List<TypeSet<AllocationEntry>> mutualExclusions,
Class<? extends AllocationEntry> referenceEntryType) {
for(TypeSet<AllocationEntry> entrySet : mutualExclusions) {
if(entrySet.contains(referenceEntryType)) {
return entrySet;
}
}
return null;
}
/** {@inheritDoc} */
@Override
public Collection<Class<? extends AllocationEntry>> getSourceEntityMutuallyExclusiveEntryTypes(
Class<? extends AllocationEntry> referenceEntryType) {
return getMutualExclusionTypeSet(sourceEntityMutualExclusions, referenceEntryType);
}
/** {@inheritDoc} */
@Override
public Collection<Class<? extends AllocationEntry>> getTargetEntityMutuallyExclusiveEntryTypes(
Class<? extends AllocationEntry> referenceEntryType) {
return getMutualExclusionTypeSet(targetEntityMutualExclusions, referenceEntryType);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment