private ComponentSet addComponents(
      Map<String, Connectable> connectables, int rows, int cols, Elements componentElements) {
    ComponentSet set;
    set = new ComponentSet(cols, rows);
    for (int i = 0; i < componentElements.size(); i++) {
      Element componentElement = componentElements.get(i);
      String type = componentElement.getAttributeValue("type");
      String name = componentElement.getAttributeValue("name");

      Connectable connectable = factory.make(type, name);
      if (connectable != null) {
        connectables.put(name, connectable);
        if (connectable instanceof Component) {
          Component component = (Component) connectable;
          component.setxLoc(Integer.parseInt(componentElement.getAttributeValue("col")));
          component.setyLoc(Integer.parseInt(componentElement.getAttributeValue("row")));
          component.setInverted(Boolean.parseBoolean(componentElement.getAttributeValue("inv")));
          set.addComponent(component);
        } else if (connectable instanceof Endpoint) {
          set.addEndpoint((Endpoint) connectable);
        }
      }
    }
    return set;
  }
  private ComponentSet addComponentsWithAutoLocate(
      Map<String, Connectable> connectables, int rows, int cols, Elements componentElements) {
    ComponentSet set;
    set = new AutoAddComponentSet(cols, rows);
    for (int i = 0; i < componentElements.size(); i++) {
      Element componentElement = componentElements.get(i);
      String type = componentElement.getAttributeValue("type");
      String name = componentElement.getAttributeValue("name");

      Connectable connectable = factory.make(type, name);
      if (connectable != null) {
        connectables.put(name, connectable);
        if (connectable instanceof Component) {
          ((AutoAddComponentSet) set).addComponent((Component) connectable);
        } else if (connectable instanceof Endpoint) {
          set.addEndpoint((Endpoint) connectable);
        }
      }
    }
    return set;
  }