Example #1
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;
  }
Example #2
0
  @Test
  public void checkMaxNodeIndexOnAddAndRemove() {
    assumeTrue(dataStructure instanceof INodeListDatastructure);
    assumeTrue(Node.class.isAssignableFrom(elementClass));
    INodeListDatastructure tempDS = (INodeListDatastructure) dataStructure;

    Node[] dummies = new Node[10];
    for (int i = 0; i < dummies.length; i++) {
      dummies[i] = (Node) mock(this.elementClass);
      when(dummies[i].getIndex()).thenReturn(i);
      assertTrue(tempDS.add(dummies[i]));
      assertEquals(i, tempDS.getMaxNodeIndex());
    }

    /*
     * Since we don't know if the data structure really used the
     * maxNodeIndex property and did not return the count property, we will
     * run some more sophisticated tests now
     */

    Node[] secondDummies = new Node[10];
    int[] prevIndex = new int[10];
    int lastIndex = tempDS.getMaxNodeIndex();

    for (int i = 0; i < secondDummies.length; i++) {
      secondDummies[i] = (Node) mock(this.elementClass);
      prevIndex[i] = lastIndex;
      lastIndex = lastIndex + Rand.rand.nextInt(i + 1) + 1;
      when(secondDummies[i].getIndex()).thenReturn(lastIndex);
      assertTrue(tempDS.add(secondDummies[i]));
      assertEquals(lastIndex, tempDS.getMaxNodeIndex());
    }

    for (int i = secondDummies.length - 1; i >= 0; i--) {
      assertTrue(tempDS.remove(secondDummies[i]));
      assertEquals(prevIndex[i], tempDS.getMaxNodeIndex());
    }

    assertEquals(dummies[dummies.length - 1].getIndex(), tempDS.getMaxNodeIndex());
  }
Example #3
0
 /**
  * Retrieve the highest node index within this graph
  *
  * @return
  */
 public int getMaxNodeIndex() {
   return nodes.getMaxNodeIndex();
 }
Example #4
0
 public boolean removeNode(Node n) {
   return nodes.remove(n);
 }
Example #5
0
 public boolean containsNode(Node n) {
   return nodes.contains(n);
 }
Example #6
0
 public boolean addNode(Node n) {
   return nodes.add(n);
 }
Example #7
0
 /**
  * Retrieve the number of nodes within this graph
  *
  * @return
  */
 public int getNodeCount() {
   return nodes.size();
 }