package graph.emufog;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * Represents a general node of graph with the basic functionality.
 * Can connect to other nodes via edges and contains the geographically placement on a plain.
 */
public abstract class Node {

    /* unique identifier of the node */
    final int id;

    /* autonomous system this node belongs to */
    final AS as;

    /* list of edges associated with the node */
    Edge[] edges;

    /* emulation settings for this node */
    EmulationSettings emulationSettings;

    /**
     * Creates a node of the graph with the initial parameter given.
     *
     * @param id unique identifier
     * @param as autonomous system the belongs to
     */
    Node(int id, AS as) {
        this.id = id;
        this.as = as;
        edges = new Edge[0];
        addToAS();
    }

    /**
     * Adds this node to the respective AS.
     */
    abstract void addToAS();

    /**
     * Returns the emulation settings associated. If there are none returns null.
     *
     * @return emulation  settings or null
     */
    public EmulationSettings getEmulationNode() {
        return emulationSettings;
    }

    /**
     * Returns identification if this node can be emulated with existing settings.
     *
     * @return true if it can be emulated, false otherwise
     */
    public boolean hasEmulationSettings() {
        return emulationSettings != null;
    }

    /**
     * Returns the unique identifier of the node.
     *
     * @return unique identifier
     */
    public int getID() {
        return id;
    }

    /**
     * Returns an array of all edges associated with the node.
     *
     * @return array of the node's edges
     */
    public Edge[] getEdges() {
        return edges;
    }

    /**
     * Returns a list of all edges that point to a node in the same AS as this node.
     *
     * @return list of edges in the same AS
     */
    public List<Edge> getSameASEdges() {
        List<Edge> result = new ArrayList<>();

        for (Edge e : edges) {
            if (!e.isCrossASEdge()) {
                result.add(e);
            }
        }

        return result;
    }

    /**
     * Returns the name of the node.
     *
     * @return name of the node
     */
    public abstract String getName();

    /**
     * Returns the edge degree of the node.
     *
     * @return number of edges associated with the node
     */
    public int getDegree() {
        return edges.length;
    }

    /**
     * Returns the autonomous system consisting the node.
     *
     * @return node's AS
     */
    public AS getAS() {
        return as;
    }

    /**
     * Adds an edge to the array of edges associated with this node. Grows the array by one to add an edge.
     *
     * @param edge edge to add to node
     */
    void addEdge(Edge edge) {
        edges = Arrays.copyOf(edges, edges.length + 1);
        edges[edges.length - 1] = edge;
    }

    @Override
    public boolean equals(Object o) {
        boolean result = false;

        if (o instanceof Node) {
            result = ((Node) o).id == id;
        }

        return result;
    }

    @Override
    public int hashCode() {
        return id;
    }

    @Override
    public String toString() {
        return getName();
    }
}

@@ -42,60 +42,9 @@
 rray
-List;%0Aimport java.util.Arrays;%0Aimport java.util.List
+s
 ;%0A%0A/
@@ -1758,404 +1758,8 @@
  %7D%0A%0A
-    /**%0A     * Returns a list of all edges that point to a node in the same AS as this node.%0A     *%0A     * @return list of edges in the same AS%0A     */%0A    public List%3CEdge%3E getSameASEdges() %7B%0A        List%3CEdge%3E result = new ArrayList%3C%3E();%0A%0A        for (Edge e : edges) %7B%0A            if (!e.isCrossASEdge()) %7B%0A                result.add(e);%0A            %7D%0A        %7D%0A%0A        return result;%0A    %7D%0A%0A
     

remove sameASEdge call