throw new NullPointerException();
}
EdgeDraftImpl edgeDraftImpl = (EdgeDraftImpl) edgeDraft;
if (edgeDraftImpl.getSource() == null) {
String message = NbBundle.getMessage(ImportContainerImpl.class, "ImportContainerException_MissingNodeSource");
report.logIssue(new Issue(message, Level.SEVERE));
return;
}
if (edgeDraftImpl.getTarget() == null) {
String message = NbBundle.getMessage(ImportContainerImpl.class, "ImportContainerException_MissingNodeTarget");
report.logIssue(new Issue(message, Level.SEVERE));
return;
}
//Self loop
if (edgeDraftImpl.getSource() == edgeDraftImpl.getTarget() && !parameters.isSelfLoops()) {
String message = NbBundle.getMessage(ImportContainerImpl.class, "ImportContainerException_SelfLoop");
report.logIssue(new Issue(message, Level.SEVERE));
return;
}
if (edgeDraftImpl.getType() != null) {
//Counting
switch (edgeDraftImpl.getType()) {
case DIRECTED:
directedEdgesCount++;
break;
case UNDIRECTED:
undirectedEdgesCount++;
break;
case MUTUAL:
directedEdgesCount += 2;
break;
}
//Test if the given type match with parameters
switch (parameters.getEdgeDefault()) {
case DIRECTED:
EdgeDraft.EdgeType type1 = edgeDraftImpl.getType();
if (type1.equals(EdgeDraft.EdgeType.UNDIRECTED)) {
report.logIssue(new Issue(NbBundle.getMessage(ImportContainerImpl.class, "ImportContainerException_Bad_Edge_Type"), Level.WARNING));
}
break;
case UNDIRECTED:
EdgeDraft.EdgeType type2 = edgeDraftImpl.getType();
if (type2.equals(EdgeDraft.EdgeType.DIRECTED)) {
report.logIssue(new Issue(NbBundle.getMessage(ImportContainerImpl.class, "ImportContainerException_Bad_Edge_Type"), Level.WARNING));
}
break;
case MIXED:
break;
}
}
String id = edgeDraftImpl.getId();
String sourceTargetId = edgeDraftImpl.getSource().getId() + "-" + edgeDraftImpl.getTarget().getId();
if (edgeMap.containsKey(id) || edgeSourceTargetMap.containsKey(sourceTargetId)) {
if (!parameters.isParallelEdges()) {
report.logIssue(new Issue(NbBundle.getMessage(ImportContainerImpl.class, "ImportContainerException_edgeExist"), Level.WARNING));
return;
} else {
EdgeDraftImpl existingEdge = edgeMap.get(id);
if (existingEdge == null) {
existingEdge = edgeSourceTargetMap.get(sourceTargetId);
}
//Manage parallel edges
if (parameters.isMergeParallelEdgesWeight()) {
existingEdge.setWeight(existingEdge.getWeight() + edgeDraftImpl.getWeight());
}
if (parameters.isMergeParallelEdgesAttributes()) {
mergeAttributes(existingEdge.getAttributeRow(), edgeDraftImpl.getAttributeRow());
}
report.logIssue(new Issue(NbBundle.getMessage(ImportContainerImpl.class, "ImportContainerException_Parallel_Edge", id), Level.INFO));
return;
}
}
edgeSourceTargetMap.put(sourceTargetId, edgeDraftImpl);
edgeMap.put(id, edgeDraftImpl);
//Mutual
if (edgeDraftImpl.getType() != null && edgeDraftImpl.getType().equals(EdgeDraft.EdgeType.MUTUAL)) {
id = edgeDraftImpl.getId() + "-mutual";
sourceTargetId = edgeDraftImpl.getTarget().getId() + "-" + edgeDraftImpl.getSource().getId();
if (edgeSourceTargetMap.containsKey(sourceTargetId)) {
if (!parameters.isParallelEdges()) {
report.logIssue(new Issue(NbBundle.getMessage(ImportContainerImpl.class, "ImportContainerException_edgeExist"), Level.WARNING));
return;
} else {
EdgeDraftImpl existingEdge = edgeSourceTargetMap.get(sourceTargetId);
//Manage parallel edges
if (parameters.isMergeParallelEdgesWeight()) {
existingEdge.setWeight(existingEdge.getWeight() + edgeDraftImpl.getWeight());
}
if (parameters.isMergeParallelEdgesAttributes()) {
mergeAttributes(existingEdge.getAttributeRow(), edgeDraftImpl.getAttributeRow());
}
report.logIssue(new Issue(NbBundle.getMessage(ImportContainerImpl.class, "ImportContainerException_Parallel_Edge", id), Level.INFO));
return;
}
}
edgeSourceTargetMap.put(sourceTargetId, edgeDraftImpl);