package cnetmap;

import java.util.ArrayList;
import java.util.List;
import javax.swing.AbstractListModel;

/**
 *
 * @author Dominik Janura
 */
public class NodeListModel extends AbstractListModel {

  private List<NetNode> NodeList;

  public NodeListModel() {
    this.NodeList = null;
  }

  public void add(List<NetNode> nodeList) {
    int startPos = this.getEnd();
    List<NetNode> newList = new ArrayList<>();
    if (this.NodeList != null) {
      newList = new ArrayList<>(this.NodeList);
    }
    newList.addAll(nodeList);
    this.NodeList = newList;
    fireIntervalAdded(this, startPos, this.getEnd());
  }

  public void clear() {
    int endPos = this.getEnd();
    this.NodeList = null;
    fireContentsChanged(this, 0, endPos);
  }

  @Override
  public int getSize() {
    if (this.NodeList == null) {
      return 0;
    } else {
      return this.NodeList.size();
    }
  }

  public int getEnd() {
    if (this.NodeList == null) {
      return 0;
    } else {
      return this.getSize();
    }
  }

  @Override
  public NetNode getElementAt(int index) {
    return this.NodeList.get(index);
  }

}