package io.mirango;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

class Vertex<T> {
    private T vertex;
    private List<Edge<T>> adjList = new ArrayList<>();

    Vertex(T vertex) {
        this.vertex = vertex;
    }

    private boolean hasEdge(Vertex<T> v) {
        return adjList.stream()
                .anyMatch(x -> x.contains(v));
    }

    private Optional<Edge<T>> containsEdge(Vertex<T> v) {
        return adjList.stream()
                .filter(x -> x.contains(v))
                .findFirst();
    }

    boolean addEdge(Vertex<T> v, T weight) {
        if (this.hasEdge(v)) {
            return false;
        }
        Edge<T> edge = new Edge<>(this, v, weight);
        adjList.add(edge);
        return true;
    }

    boolean removeEdge(Vertex<T> v) {
        if (!this.hasEdge(v)) {
            return false;
        }
        adjList.remove(this.containsEdge(v));
        return true;
    }
}

@@ -408,25 +408,17 @@
 dge%3CT%3E%3E 
-containsE
+e
 dge(Vert
@@ -810,28 +810,70 @@
     
-if (!
+Optional%3CEdge%3CT%3E%3E e = 
 this.
-hasE
+e
 dge(v)
+;%0A        if (!e.isPresent()
 ) %7B%0A
@@ -935,27 +935,14 @@
 ove(
-this.containsEdge(v
+e.get(
 ));%0A

resolve Option<Edge<T>> so it may be removed from list