Commit a51d41e9 authored by Alexander Diewald's avatar Alexander Diewald
Browse files

Style improvements:

* Rework confusing loop constructs.
* Follow the coding convention.
refs 3193
parent 3bc6a740
......@@ -19,6 +19,7 @@ package org.fortiss.af3.deployment.utils;
import static org.eclipse.emf.ecore.util.EcoreUtil.isAncestor;
import static org.fortiss.tooling.base.utils.AnnotationUtils.getAnnotation;
import static org.fortiss.tooling.kernel.utils.EcoreUtils.getChildrenWithType;
import static org.fortiss.tooling.kernel.utils.KernelModelElementUtils.computeFullyQualifiedName;
import static org.fortiss.tooling.kernel.utils.KernelModelElementUtils.getParentElement;
import static org.fortiss.tooling.kernel.utils.KernelModelElementUtils.getRootElement;
......@@ -170,36 +171,13 @@ public class DeploymentUtils {
* class of the architecture to search in
* @return the list of hierarchical elements in the architecture
*/
public static <T extends IProjectRootElement> ArrayList<IHierarchicElement>
public static <T extends IProjectRootElement> List<IHierarchicElement>
getListOfHierarchicElements(EObject hook, Class<T> architectureClass) {
T architecture = getRootElement(hook, architectureClass);
ArrayList<IHierarchicElement> list = new ArrayList<IHierarchicElement>();
if(architecture == null) {
return list;
}
for(IHierarchicElement child : ((IHierarchicElementContainer)architecture)
.getContainedElements()) {
iterateChildren(child, list);
}
return list;
}
/**
* Recursive helper method to assemble list of IHierarchicElements.
*
* @param element
* is a {@link IHierarchicElement}
* @param list
* is a Array List of {@link IHierarchicElement}s
*
* */
private static void iterateChildren(IHierarchicElement element,
ArrayList<IHierarchicElement> list) {
list.add(element);
for(IHierarchicElement subelement : element.getContainedElements()) {
iterateChildren(subelement, list);
return Collections.emptyList();
}
return getChildrenWithType(architecture, IHierarchicElement.class);
}
/**
......@@ -211,36 +189,13 @@ public class DeploymentUtils {
* class of the architecture to search in
* @return the list of connectors in the architecture
*/
public static <T extends IProjectRootElement> ArrayList<IConnector> getListOfConnectors(
public static <T extends IProjectRootElement> List<IConnector> getListOfConnectors(
EObject hook, Class<T> architectureClass) {
T architecture = getRootElement(hook, architectureClass);
ArrayList<IConnector> list = new ArrayList<IConnector>();
if(architecture == null) {
return list;
}
for(IHierarchicElement subelement : ((IHierarchicElementContainer)architecture)
.getContainedElements()) {
iterateChildrenConnectors(subelement, list);
}
return list;
}
/**
* Recursive helper method to assemble list of {@link IConnector}s.
*
* @param element
* corresponds to a {@link IHierarchicElement}
*
* @param list
* corresponds to an {@link ArrayList} of {@link IConnector}s
*/
private static void iterateChildrenConnectors(IHierarchicElement element,
ArrayList<IConnector> list) {
list.addAll(element.getConnectors());
for(IHierarchicElement subelement : element.getContainedElements()) {
iterateChildrenConnectors(subelement, list);
return Collections.emptyList();
}
return getChildrenWithType(architecture, IConnector.class);
}
/**
......@@ -278,15 +233,13 @@ public class DeploymentUtils {
*/
public static ExecutionUnit findECUforDeployedSubComponent(Component component,
Deployment deployment) {
while(component != null) {
IHierarchicElementContainer itElement = component;
while(itElement instanceof Component) {
ExecutionUnit unit = findECUforDeployedComponent(component, deployment);
if(unit != null) {
return unit;
}
if(component.eContainer() instanceof Component)
component = (Component)component.eContainer();
else
return null;
itElement = component.getContainer();
}
return null;
}
......@@ -711,8 +664,9 @@ public class DeploymentUtils {
* Checks if two given {@link Component}s are deployed on different {@link ExecutionUnit}s and
* if there exists a {@link TransmissionUnit} connection (e.g., a bus) between them.
*/
public static boolean existsHardwareConnection(Deployment d, Component c1, Component c2) {
return getTransmissionUnitConnection(d, c1, c2) == null ? false : true;
// TODO:
public static boolean existsHardwareConnection(Deployment depl, Component c1, Component c2) {
return getTransmissionUnitConnection(depl, c1, c2) == null ? false : true;
}
/**
......@@ -720,37 +674,38 @@ public class DeploymentUtils {
* if there exists a {@link TransmissionUnit} connection (e.g., a bus) between them. If so,
* returns the {@link TransmissionUnit}.
*/
public static TransmissionUnit getTransmissionUnitConnection(Deployment d, Component c1,
Component c2) {
ExecutionUnit c1Deployed = null;
ExecutionUnit c2Deployed = null;
for(ComponentAllocation ca : d.getComponentAllocations()) {
if(ca.getComponent().equals(c1)) {
c1Deployed = ca.getExecutionUnit();
public static TransmissionUnit getTransmissionUnitConnection(Deployment deployment,
Component deployedCompA, Component deployedCompB) {
ExecutionUnit deplTargetA = null;
ExecutionUnit deplTargetB = null;
for(ComponentAllocation ca : deployment.getComponentAllocations()) {
if(ca.getComponent().equals(deployedCompA)) {
deplTargetA = ca.getExecutionUnit();
break;
}
}
for(ComponentAllocation ca : d.getComponentAllocations()) {
if(ca.getComponent().equals(c2)) {
c2Deployed = ca.getExecutionUnit();
for(ComponentAllocation ca : deployment.getComponentAllocations()) {
if(ca.getComponent().equals(deployedCompB)) {
deplTargetB = ca.getExecutionUnit();
break;
}
}
if(c1Deployed == null || c2Deployed == null)
if(deplTargetA == null || deplTargetB == null) {
return null;
if(c1Deployed.equals(c2Deployed)) {
}
if(deplTargetA.equals(deplTargetB)) {
return null;
}
List<TransmissionUnit> transmissionUnits =
PlatformArchitectureUtils.findAtomicTransmissionUnits((PlatformArchitecture)d
.getPlatformArchitectureReference().getReference());
PlatformArchitectureUtils
.findAtomicTransmissionUnits((PlatformArchitecture)deployment
.getPlatformArchitectureReference().getReference());
for(TransmissionUnit ts : transmissionUnits) {
List<IHierarchicElement> connectedElements =
PlatformArchitectureUtils.getConnectedElements(ts);
if(connectedElements.contains(c1Deployed) && connectedElements.contains(c2Deployed)) {
if(connectedElements.contains(deployedCompA) &&
connectedElements.contains(deployedCompB)) {
return ts;
}
}
......@@ -771,7 +726,6 @@ public class DeploymentUtils {
*/
public static List<TransceiverPort> getTransceiverPorts(VirtualLink virtualLink,
IPlatformResource resource) {
List<TransceiverPort> transceiverPorts = new ArrayList<TransceiverPort>();
Queue<Segment> segmentQueue = new LinkedList<Segment>();
......@@ -819,7 +773,6 @@ public class DeploymentUtils {
<E extends TransceiverPort, P extends TransceiverPort>
E
getEndPointTransceiverPort(P transceiverPort, Class<E> endPointType, IModelElement scope) {
if(transceiverPort.getSegment() == null) {
return null;
}
......@@ -902,7 +855,6 @@ public class DeploymentUtils {
Collection<InputPort> recvPorts = new ArrayList<>();
for(TransceiverPort recvPort : getAnnotation(virtualLink, VlReceivers.class).getValue()) {
Port port = getPort(recvPort);
if(port instanceof InputPort) {
recvPorts.add((InputPort)port);
}
......@@ -917,7 +869,6 @@ public class DeploymentUtils {
public static VirtualLink getVirtualLink(Deployment deployment, OutputPort outputPort) {
for(VirtualLink virtualLink : deployment.getRoute().getVirtualLinks()) {
OutputPort senderPort = getSenderPort(virtualLink);
if(senderPort == outputPort) {
return virtualLink;
}
......@@ -932,7 +883,6 @@ public class DeploymentUtils {
public static VirtualLink getVirtualLink(Deployment deployment, InputPort inputPort) {
for(VirtualLink virtualLink : deployment.getRoute().getVirtualLinks()) {
Collection<InputPort> recvPorts = getReceiverPorts(virtualLink);
if(recvPorts.contains(inputPort)) {
return virtualLink;
}
......@@ -952,7 +902,6 @@ public class DeploymentUtils {
try {
annotation = getAnnotation(virtualLink, VlSender.class);
} catch(NullPointerException e) {
// e.printStackTrace();
annotation = null;
}
if(annotation == null) {
......@@ -1031,7 +980,6 @@ public class DeploymentUtils {
public static Collection<InputPort> getReceiverComponentPorts(VirtualLink virtualLink,
TransceiverPort transceiverPort) {
Collection<InputPort> recvPorts = new ArrayList<>();
for(TransceiverPort tPort : getReachableReceiverPortsOf(virtualLink, transceiverPort)) {
Port recvComponentPort = DeploymentUtils.getPort(tPort);
// If a receiver Port is not an InputPort, there is a problem with the Component
......@@ -1039,7 +987,6 @@ public class DeploymentUtils {
assert (recvComponentPort instanceof InputPort);
recvPorts.add((InputPort)recvComponentPort);
}
return recvPorts;
}
}
Supports Markdown
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