use of org.gephi.io.importer.api.EdgeDirection in project gephi by gephi.
the class ImportContainerImpl method addEdge.
@Override
public void addEdge(EdgeDraft edgeDraft) {
checkElementDraftImpl(edgeDraft);
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;
}
//Check if already exists
if (edgeMap.containsKey(edgeDraftImpl.getId())) {
String message = NbBundle.getMessage(ImportContainerImpl.class, "ImportContainerException_edgeExist", edgeDraftImpl.getId());
report.logIssue(new Issue(message, Level.WARNING));
return;
}
//Self loop
if (edgeDraftImpl.isSelfLoop() && !parameters.isSelfLoops()) {
String message = NbBundle.getMessage(ImportContainerImpl.class, "ImportContainerException_SelfLoop");
report.logIssue(new Issue(message, Level.SEVERE));
return;
}
//Check direction and defaut type
if (edgeDraftImpl.getDirection() != null) {
//Test if the given type match with parameters
switch(edgeDefault) {
case DIRECTED:
if (edgeDraftImpl.getDirection().equals(EdgeDirection.UNDIRECTED)) {
report.logIssue(new Issue(NbBundle.getMessage(ImportContainerImpl.class, "ImportContainerException_Bad_Edge_Type", edgeDefault, edgeDraftImpl.getId()), Level.SEVERE));
return;
}
break;
case UNDIRECTED:
if (edgeDraftImpl.getDirection().equals(EdgeDirection.DIRECTED)) {
report.logIssue(new Issue(NbBundle.getMessage(ImportContainerImpl.class, "ImportContainerException_Bad_Edge_Type", edgeDefault, edgeDraftImpl.getId()), Level.SEVERE));
return;
}
break;
}
}
//Get index
int index = edgeList.size();
//Type
int edgeType = getEdgeType(edgeDraftImpl.getType());
long sourceTargetLong = getLongId(edgeDraftImpl);
ensureLongSetArraySize(edgeType);
Long2ObjectMap<int[]> edgeTypeSet = edgeTypeSets[edgeType];
if (edgeTypeSet.containsKey(sourceTargetLong)) {
if (!parameters.isParallelEdges()) {
report.logIssue(new Issue(NbBundle.getMessage(ImportContainerImpl.class, "ImportContainerException_Parallel_Edge_Forbidden", edgeDraftImpl.getId()), Level.SEVERE));
return;
} else {
int[] edges = edgeTypeSet.get(sourceTargetLong);
int[] newEdges = new int[edges.length + 1];
newEdges[edges.length] = index;
System.arraycopy(edges, 0, newEdges, 0, edges.length);
edgeTypeSet.put(sourceTargetLong, newEdges);
if (!reportedParallelEdges) {
report.logIssue(new Issue(NbBundle.getMessage(ImportContainerImpl.class, "ImportContainerException_Parallel_Edge", edgeDraftImpl.getId()), Level.INFO));
reportedParallelEdges = true;
}
}
} else {
edgeTypeSet.put(sourceTargetLong, new int[] { index });
}
//Self loop
if (edgeDraftImpl.isSelfLoop()) {
selfLoops++;
}
//Direction
EdgeDirection direction = edgeDraftImpl.getDirection();
if (direction != null) {
//Counting
switch(direction) {
case DIRECTED:
directedEdgesCount++;
break;
case UNDIRECTED:
undirectedEdgesCount++;
break;
}
}
//Adding
edgeList.add(edgeDraftImpl);
edgeMap.put(edgeDraft.getId(), index);
}
use of org.gephi.io.importer.api.EdgeDirection in project gephi by gephi.
the class ImportContainerImpl method getLongId.
private long getLongId(EdgeDraftImpl edge) {
EdgeDirection direction = edge.getDirection();
boolean directed = edgeDefault.equals(EdgeDirectionDefault.DIRECTED) || (edgeDefault.equals(EdgeDirectionDefault.MIXED) && ((direction != null && direction == EdgeDirection.DIRECTED) || direction == null));
return getLongId(edge.getSource(), edge.getTarget(), directed);
}
Aggregations