/**
   * Creates a spring between the two given nodes with the given strength. If the two nodes not
   * directly connected by an edge already have a spring between them, it will be replaced by this
   * one.
   *
   * @param node1 First of the two nodes to have a spring between them.
   * @param node2 Second of the two nodes to have a spring between them.
   * @param length The length of this spring (natural rest distance at which the two nodes would
   *     sit).
   * @param strength The strength of this new spring.
   * @return True if the viewer contains the two nodes and a spring between them has been created.
   */
  public boolean addSpring(N node1, N node2, float length, float strength) {
    Particle p1 = nodes.get(node1);
    if (p1 == null) {
      return false;
    }
    Particle p2 = nodes.get(node2);
    if (p2 == null) {
      return false;
    }

    // We may have to remove existing spring if it exists between these two nodes.
    for (int i = 0; i < physics.getNumSprings(); i++) {
      Spring spring = physics.getSpring(i);
      if ((((spring.getOneEnd() == p1) && (spring.getTheOtherEnd() == p2))
              || ((spring.getOneEnd() == p2) && (spring.getTheOtherEnd() == p1)))
          && (spring.strength() != EDGE_STRENGTH)) {
        physics.removeSpring(spring);
        break;
      }
    }

    // Add the new force.
    physics.makeSpring(p1, p2, strength, DAMPING, length);
    return false;
  }