-
Notifications
You must be signed in to change notification settings - Fork 85
/
AbstractComponentFilteredComponentExchange.java
72 lines (61 loc) · 2.53 KB
/
AbstractComponentFilteredComponentExchange.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
71
72
/*******************************************************************************
* 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.common.helpers.query.IQuery;
import org.polarsys.capella.core.data.cs.Component;
import org.polarsys.capella.core.data.ctx.SystemComponent;
import org.polarsys.capella.core.data.fa.ComponentExchange;
import org.polarsys.capella.core.data.la.LogicalComponent;
import org.polarsys.capella.core.data.pa.PhysicalComponent;
import org.polarsys.capella.core.data.pa.PhysicalComponentNature;
import org.polarsys.capella.core.model.helpers.ComponentExt;
/**
* Return incoming or outgoing component exchanges of given AbstractActor, System, LC or PC
*
*/
public abstract class AbstractComponentFilteredComponentExchange implements IQuery {
/**
* current.componentPorts.outgoingFlows
*
* @see org.polarsys.capella.common.helpers.query.IQuery#compute(java.lang.Object)
*/
public List<Object> compute(Object object) {
List<Object> result = new ArrayList<Object>();
if (isValidComponentForComponentExchanges(object)) {
for (ComponentExchange exchange : getExchanges(object)) {
if (isValid(exchange, object)) {
result.add(exchange);
}
}
}
return result;
}
protected boolean isValid(ComponentExchange exchange, Object object) {
return false;
}
protected Collection<ComponentExchange> getExchanges(Object object) {
return getCache(ComponentExt::getAllRelatedComponentExchange, (Component) object);
}
/**
* check for valid exchanges that can have component exchanges
*/
public boolean isValidComponentForComponentExchanges(Object object) {
return (object instanceof Component && ((Component) object).isActor()) || //
(object instanceof SystemComponent || object instanceof LogicalComponent || (object instanceof PhysicalComponent
&& ((PhysicalComponent) object).getNature() != PhysicalComponentNature.NODE));
}
}