-
Notifications
You must be signed in to change notification settings - Fork 85
/
ComponentInternalOutgoingComponentExchanges.java
70 lines (58 loc) · 2.35 KB
/
ComponentInternalOutgoingComponentExchanges.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
68
69
70
/*******************************************************************************
* Copyright (c) 2006, 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.core.data.cs.Component;
import org.polarsys.capella.core.data.cs.Part;
import org.polarsys.capella.core.data.fa.ComponentExchange;
import org.polarsys.capella.core.model.helpers.ComponentExchangeExt;
import org.polarsys.capella.core.model.helpers.ComponentExt;
import org.polarsys.capella.core.model.utils.ListExt;
/**
*
* Return internal outgoing component exchanges
*
*/
public class ComponentInternalOutgoingComponentExchanges extends ComponentOutgoingComponentExchange {
@Override
protected Collection<ComponentExchange> getExchanges(Object object) {
List<ComponentExchange> exchanges = new ArrayList<>();
Collection<Part> usedParts = ComponentExt.getAllSubUsedParts((Component) object, true);
for (Part part : usedParts) {
for (ComponentExchange e : ComponentExt.getAllRelatedComponentExchange(part, true)) {
if (super.isValid(e, part.getAbstractType())) {
exchanges.add(e);
}
}
}
usedParts.addAll(getCache(ComponentExt::getRepresentingParts, (Component) object));
List<ComponentExchange> result = new ArrayList<>();
// If source or target is one of the used parts or representing parts, filter
for (ComponentExchange pl : exchanges) {
if (!ListExt.containsAny(ComponentExchangeExt.getSourceParts(pl), usedParts)) {
result.add(pl);
}
if (!ListExt.containsAny(ComponentExchangeExt.getTargetParts(pl), usedParts)) {
result.add(pl);
}
}
return result;
}
@Override
protected boolean isValid(ComponentExchange exchange, Object object) {
return !ComponentExchangeExt.isDelegation(exchange);
}
}