-
Notifications
You must be signed in to change notification settings - Fork 85
/
PhysicalComponent_InternalPhysicalLinks.java
67 lines (57 loc) · 2.4 KB
/
PhysicalComponent_InternalPhysicalLinks.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*******************************************************************************
* Copyright (c) 2017, 2020 THALES GLOBAL SERVICES.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Thales - initial API and implementation
*******************************************************************************/
package org.polarsys.capella.core.semantic.queries.basic.queries;
import static org.polarsys.capella.common.helpers.cache.ModelCache.getCache;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.polarsys.capella.common.helpers.query.IQuery;
import org.polarsys.capella.core.data.cs.Component;
import org.polarsys.capella.core.data.cs.Part;
import org.polarsys.capella.core.data.cs.PhysicalLink;
import org.polarsys.capella.core.data.helpers.cs.services.PhysicalLinkExt;
import org.polarsys.capella.core.model.helpers.ComponentExt;
import org.polarsys.capella.core.model.utils.ListExt;
public class PhysicalComponent_InternalPhysicalLinks implements IQuery {
public PhysicalComponent_InternalPhysicalLinks() {
// do nothing
}
/**
* Gathering recursively all sub physical components : Gathering all internal physical links
*
* @see org.polarsys.capella.common.helpers.query.IQuery#compute(java.lang.Object)
*/
@Override
public List<Object> compute(Object object) {
List<PhysicalLink> allPLs = new ArrayList<>();
List<Object> result = new ArrayList<>();
if (object instanceof Component) {
Component seletectedComponent = (Component) object;
Collection<Part> usedParts = ComponentExt.getAllSubUsedParts(seletectedComponent, true);
for (Part part : usedParts) {
allPLs.addAll(getCache(PhysicalLinkExt::getAllRelatedPhysicalLinks, part));
}
usedParts.addAll(getCache(ComponentExt::getRepresentingParts, seletectedComponent));
// If source or target is one of the used parts or representing parts, filter
for (PhysicalLink pl : allPLs) {
if (!ListExt.containsAny(PhysicalLinkExt.getSourceParts(pl), usedParts)) {
result.add(pl);
}
if (!ListExt.containsAny(PhysicalLinkExt.getTargetParts(pl), usedParts)) {
result.add(pl);
}
}
}
return result;
}
}