Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Changing control flow naming to tilde #24

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public class DataFlowDiagramConverter extends Converter {
private final Logger logger = Logger.getLogger(DataFlowDiagramConverter.class);
protected final static String DELIMITER_PIN_NAME = "|";
protected final static String DELIMITER_MULTI_PIN = ",";
private final static String CONTROL_FLOW_NAME = "~";

private BehaviorConverter behaviorConverter;

Expand Down Expand Up @@ -263,22 +264,50 @@ private void createNodes(DataFlowDiagram dataFlowDiagram, List<Child> children,
}

private void createFlows(DataFlowDiagram dataFlowDiagram, List<Child> children) {
var controlFlowNameMap = createControlFlowNameMap(dataFlowDiagram);
for (Flow flow : dataFlowDiagram.getFlows()) {
fillPinToFlowNamesMap(inputPinToFlowNamesMap,flow);
children.add(createFlow(flow));
fillPinToFlowNamesMap(inputPinToFlowNamesMap,flow, controlFlowNameMap);
children.add(createFlow(flow, controlFlowNameMap));
}
}

private HashMap<Flow, String> createControlFlowNameMap(DataFlowDiagram dataFlowDiagram) {
var controlFlowNameMap = new HashMap<Flow, String>();
dataFlowDiagram.getNodes().forEach(node -> {
var controlFlows = dataFlowDiagram.getFlows().stream()
.filter(flow -> flow.getDestinationNode().equals(node))
.filter(flow -> flow.getEntityName().equals("")).toList();

String controlFlowName = "" + CONTROL_FLOW_NAME;
for (var flow : controlFlows) {
controlFlowNameMap.put(flow, controlFlowName);
controlFlowName += CONTROL_FLOW_NAME;
}
});
return controlFlowNameMap;
}

private Child createFlow(Flow flow) {
private Child createFlow(Flow flow, HashMap<Flow, String> controlFlowNameMap) {
String id = flow.getId();
String type = "edge:arrow";
String sourceId = flow.getSourcePin()
.getId();
String targetId = flow.getDestinationPin()
.getId();
String text = flow.getEntityName();
.getId();
String text = controlFlowNameMap.getOrDefault(flow, flow.getEntityName());
return new Child(text, null, null, id, type, sourceId, targetId, null, new ArrayList<>());
}

private void fillPinToFlowNamesMap(Map<Pin,List<String>> map,Flow flow, HashMap<Flow, String> controlFlowNameMap) {
if (map.containsKey(flow.getDestinationPin())) {
map.get(flow.getDestinationPin())
.add(controlFlowNameMap.getOrDefault(flow, flow.getEntityName()));
} else {
List<String> flowNames = new ArrayList<>();
flowNames.add(controlFlowNameMap.getOrDefault(flow, flow.getEntityName()));
map.put(flow.getDestinationPin(), flowNames);
}
}

private Map<Pin, List<AbstractAssignment>> mapping(Node node) {
Map<Pin, List<AbstractAssignment>> mapPinToAssignments = new HashMap<>();
Expand Down Expand Up @@ -344,15 +373,5 @@ private String getStringFromInputPins (List<Pin> inputPins) {
return String.join(DELIMITER_MULTI_PIN, pinNamesAsString);
}

private void fillPinToFlowNamesMap(Map<Pin,List<String>> map,Flow flow) {
if (map.containsKey(flow.getDestinationPin())) {
map.get(flow.getDestinationPin())
.add(flow.getEntityName());
} else {
List<String> flowNames = new ArrayList<>();
flowNames.add(flow.getEntityName());
map.put(flow.getDestinationPin(), flowNames);
}
}

}