package lego;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * Class of graph.
 * Based on storage of edges via ArrayList with {@link Edge}.
 */
public class Graph {
    //    List<Long> edges = new ArrayList<>(); // Array with pairs of edges
    private Collection<Edge> edges = new ArrayList<>();

    public Graph() {
        this.edges = new ArrayList<>();
    }

    public Graph(Graph graph) {
        this.edges = graph.edges;
    }

    public boolean isEmpty() {
        return edges.isEmpty();
    }

    public long size() {
        return edges.size();
    }

    /**
     * Make Stream of {@link Edge}
     *
     * @return Stream of {@link Edge}
     */
    public Stream<Edge> getStream() {
        return edges.stream();
    }

    /**
     * Make parallel stream of {@link Edge}
     *
     * @return Parallel stream of {@link Edge}
     */
    public Stream<Edge> getParallelStream() {
        return edges.parallelStream();
    }

    /**
     * Make Stream of vertex ids
     *
     * @return Stream of Long
     */
    public Stream<Long> getVertexStream() {
        Collection<Long> vertices = new ArrayList<>();

        for (Edge edge : edges) {
            if (!vertices.contains(edge.getStart())) {
                vertices.add(edge.getStart());
            }
            if (!vertices.contains(edge.getEnd())) {
                vertices.add(edge.getEnd());
            }
        }

        return vertices.stream();
    }

    /**
     * Parallel stream of getVertexStream()
     *
     * @return Parallel stream of vertex ids
     */
    public Stream<Long> getParallelVertexStream() {
        return this.getVertexStream().parallel();
    }

    /**
     * Make list of incident edges for vertex
     *
     * @param vertexId This is vertex id
     * @return List with edges
     */
    public List<Edge> getIncidentEdges(long vertexId) {
        return this.getStream().filter(edge -> edge.containsVertex(vertexId)).collect(Collectors.toList());
    }

    /**
     * Make list of outgoing edges for vertex
     *
     * @param vertexId This is vertex id
     * @return List with edges
     */
    public List<Edge> getOutgoingEdges(long vertexId) {
        return this.getStream().filter(edge -> edge.getStart() == vertexId).collect(Collectors.toList());
    }

    /**
     * Make list of adjacent vertices by outgoing edges
     *
     * @param vertexId This is vertex id
     * @return List with adjacent vertices
     */
    public List<Long> getAdjacentVertices(long vertexId) {
        return this.getStream().filter(edge -> edge.getStart() == vertexId).map(Edge::getEnd).collect(Collectors.toList());
    }

    /**
     * Add new edge to graph and return them
     *
     * @param edge This is new {@link Edge}
     * @return Current {@link Graph}
     */
    public Graph addEdge(Edge edge) {
        edges.add(edge);
        return this;
    }

    /**
     * Remove edge from graph and return them
     *
     * @param edge This is vertex to be removed
     * @return Current {@link Graph}
     */
    public Graph removeEdge(Edge edge) {
        edges.remove(edge);
        return this;
    }

    /**
     * Check that graph contains edge
     *
     * @param edge This is edge to be checked
     * @return True if contains and False if not
     */
    public boolean containsEdge(Edge edge) {
        return this.getStream().anyMatch(edge::equals);
    }

    /**
     * Check that graph contains vertex
     *
     * @param id This is vertex id
     * @return True if contains and False if not
     */
    public boolean containsVertex(long id) {
        return this.getStream().anyMatch(edge -> edge.containsVertex(id));
    }

}
@@ -340,24 +340,76 @@
 rs of edges%0A
+    /**%0A     * List with edges of the graph%0A     */%0A
     private 
@@ -449,24 +449,65 @@
 yList%3C%3E();%0A%0A
+    /**%0A     * Graph constructor%0A     */%0A
     public G
@@ -570,146 +570,448 @@
     
-public Graph(Graph graph) %7B%0A        this.edges = graph.edges;%0A    %7D%0A%0A    public boolean isEmpty() %7B%0A        return edges.isEmpty();%0A    %7D%0A
+/**%0A     * Copy constructor for graph%0A     *%0A     * @param graph Graph to be copied%0A     */%0A    public Graph(Graph graph) %7B%0A        this.edges = graph.edges;%0A    %7D%0A%0A    /**%0A     * Check that graph do not contains edges%0A     *%0A     * @return True if empty and False if not%0A     */%0A    public boolean isEmpty() %7B%0A        return edges.isEmpty();%0A    %7D%0A%0A    /**%0A     * Size of the graph%0A     *%0A     * @return Count of edges in the graph%0A     */
 %0A   

Add docs