Ejemplo n.º 1
0
  @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;
  }
Ejemplo n.º 2
0
 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);
       }
   }
 }
Ejemplo n.º 3
0
 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;
 }
Ejemplo n.º 4
0
  @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;
  }
Ejemplo n.º 5
0
 /**
  * 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;
 }
Ejemplo n.º 6
0
 /**
  * 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();
 }
Ejemplo n.º 7
0
 /**
  * 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);
 }
Ejemplo n.º 8
0
 /**
  * Check whether this is a directed graph or not
  *
  * @return true, if the graph is directed; fals otherwise
  */
 public boolean isDirected() {
   return gds.createsDirected();
 }
Ejemplo n.º 9
0
 /**
  * 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();
 }
Ejemplo n.º 10
0
 /**
  * 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));
 }
Ejemplo n.º 11
0
 public boolean containsEdge(int n1, int n2) {
   return containsEdge(gds.getDummyEdge(n1, n2));
 }
Ejemplo n.º 12
0
 public boolean containsEdge(Node n1, Node n2) {
   return containsEdge(gds.getDummyEdge(n1, n2));
 }