@SuppressWarnings("unchecked") private IElement getDummy(Class<? extends IElement> elementClass) { IElement dummy = null; GraphDataStructure tempGDS; EnumMap<ListType, Class<? extends IDataStructure>> listtypes = GraphDataStructure.getList( ListType.GlobalNodeList, DArray.class, ListType.GlobalEdgeList, DArray.class); if (Node.class.isAssignableFrom(elementClass)) { tempGDS = new GraphDataStructure(listtypes, (Class<? extends Node>) elementClass, null); dummy = tempGDS.newNodeInstance(42); } else if (DirectedEdge.class.isAssignableFrom(elementClass)) { tempGDS = new GraphDataStructure(listtypes, null, (Class<? extends Edge>) elementClass); DirectedNode n1 = new DirectedNode(1, tempGDS); DirectedNode n2 = new DirectedNode(2, tempGDS); dummy = tempGDS.newEdgeInstance(n1, n2); } else if (UndirectedEdge.class.isAssignableFrom(elementClass)) { tempGDS = new GraphDataStructure(listtypes, null, (Class<? extends Edge>) elementClass); UndirectedNode n1 = new UndirectedNode(1, tempGDS); UndirectedNode n2 = new UndirectedNode(2, tempGDS); dummy = tempGDS.newEdgeInstance(n1, n2); } else { fail("Cannot identify " + elementClass); } return dummy; }
public void switchDataStructure( ListType type, Class<? extends IDataStructure> newDatastructureType) { IDataStructure newDatastructure; switch (type) { case GlobalEdgeList: newDatastructure = gds.newList(type, newDatastructureType); this.edges = (IEdgeListDatastructure) ((IEdgeListDatastructureReadable) this.edges).switchTo(newDatastructure); break; case GlobalNodeList: newDatastructure = gds.newList(type, newDatastructureType); this.nodes = (INodeListDatastructure) ((INodeListDatastructureReadable) this.nodes).switchTo(newDatastructure); break; case LocalEdgeList: case LocalInEdgeList: case LocalOutEdgeList: case LocalNodeList: for (IElement n : this.getNodes()) { newDatastructure = gds.newList(type, newDatastructureType); ((Node) n).switchDataStructure(type, newDatastructure); } } }
public Graph(String name, long timestamp, GraphDataStructure gds) { this.name = name; this.timestamp = timestamp; this.nodes = (INodeListDatastructure) gds.newList(ListType.GlobalNodeList); this.edges = (IEdgeListDatastructure) gds.newList(ListType.GlobalEdgeList); this.gds = gds; }
@Override public boolean equals(Object obj) { Log.debug("Running equality check for graphs"); if (this == obj) { return true; } if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } Graph other = (Graph) obj; if (gds == null) { if (other.gds != null) { return false; } } else if (!gds.equals(other.gds)) { return false; } if (timestamp != other.timestamp) { return false; } if (name == null) { if (other.name != null) { return false; } } else if (!name.equals(other.name)) { return false; } Log.debug("Basics equal, going for edges and nodes"); if (edges == null) { if (other.edges != null) { return false; } } else if (!this.edges.equals(other.edges)) { Log.debug("Edges not equal (type: " + edges.getClass() + ")"); return false; } if (nodes == null) { if (other.nodes != null) { return false; } } else if (!this.nodes.equals(other.nodes)) { Log.debug("Nodes not equal (type: " + nodes.getClass() + ")"); return false; } return true; }
/** * Retrieve a collection of all nodes within this graph * * @return */ public Iterable<IElement> getNodes() { if (!gds.isReadable(nodes)) throw new RuntimeException("This is not a readable graph"); return (INodeListDatastructureReadable) nodes; }
/** * Retrieve a random node * * @return */ public Node getRandomNode() { if (!gds.isReadable(nodes)) throw new RuntimeException("This is not a readable graph"); return (Node) ((INodeListDatastructureReadable) nodes).getRandom(); }
/** * Retrieve a node by its index * * @param index * @return */ public Node getNode(int index) { if (!gds.isReadable(nodes)) throw new RuntimeException("This is not a readable graph"); return ((INodeListDatastructureReadable) this.nodes).get(index); }
/** * Check whether this is a directed graph or not * * @return true, if the graph is directed; fals otherwise */ public boolean isDirected() { return gds.createsDirected(); }
/** * Retrieve a random edge * * @return */ public Edge getRandomEdge() { if (!gds.isReadable(edges)) throw new RuntimeException("This is not a readable graph"); return (Edge) ((IEdgeListDatastructureReadable) edges).getRandom(); }
/** * Get an edge by its attached nodes * * @param Node n1, Node n2 */ public Edge getEdge(Node n1, Node n2) { if (!gds.isReadable(edges)) throw new RuntimeException("This is not a readable graph"); return ((IEdgeListDatastructureReadable) edges).get(gds.getDummyEdge(n1, n2)); }
public boolean containsEdge(int n1, int n2) { return containsEdge(gds.getDummyEdge(n1, n2)); }
public boolean containsEdge(Node n1, Node n2) { return containsEdge(gds.getDummyEdge(n1, n2)); }