title: How To Create A Java Graph File from .txt file
body: <p>I am trying to create a graph file .I have to read in values from a .gra file(which I think is a .txt file).We were told to tokenise lines based on a space in the format <code>&lt;vertex&gt; &lt;name&gt; &lt;x-coord&gt; &lt;y-coord&gt;</code>,same for edge</p>
  
  <p>I had a look at a couple of related questions,but still cant find the answer.</p>
  
  <p>Here's the code I was given:</p>
  
  <pre><code>        public EdgeListVertex(V element) {
              this.element = element;
          }
  
          @Override
          public V element() {
              return element;
          }
  
          public String toString() {
              return element.toString();
          }
      }
  
      private class EdgeListEdge implements Edge&lt;E&gt; {
          Position&lt;EdgeListEdge&gt; position;
          E element;
          EdgeListVertex start, end;
  
  
          public EdgeListEdge(EdgeListVertex start, EdgeListVertex end, E element) {
              this.start = start;
              this.end = end;
              this.element = element;
          }
  
          @Override
          public E element() {
              return element;
          }
  
          public String toString() {
              return element.toString();
          }
      }
  
      private List&lt;EdgeListVertex&gt; vertices;
      private List&lt;EdgeListEdge&gt; edges;
  
  
      public EdgeListGraph() {
          vertices = new LinkedList&lt;EdgeListVertex&gt;();
          edges = new LinkedList&lt;EdgeListEdge&gt;();
  
      }
  
      @SuppressWarnings("unchecked")
      @Override
      public Vertex&lt;V&gt;[] endVertices(Edge&lt;E&gt; e) {
          EdgeListEdge edge = (EdgeListEdge) e;
          Vertex&lt;V&gt;[] endpoints = (Vertex&lt;V&gt;[]) new Vertex[2];
          endpoints[0] = edge.start;
          endpoints[1] = edge.end;
          return endpoints;
      }
  
      @Override
      public Vertex&lt;V&gt; opposite(Vertex&lt;V&gt; v, Edge&lt;E&gt; e) {
          Vertex&lt;V&gt;[] endpoints = endVertices(e);
          if (endpoints[0].equals(v)) {
              return endpoints[1];
          } else if (endpoints[1].equals(v)) {
              return endpoints[0];
          }
          throw new InvalidVertexException();
      }
  
      @Override
      public boolean areAdjacent(Vertex&lt;V&gt; v, Vertex&lt;V&gt; w) {
          for (EdgeListEdge edge: edges) {
              if ((edge.start.equals(v)) &amp;&amp; (edge.end.equals(w))) return true;
              if ((edge.end.equals(v)) &amp;&amp; (edge.start.equals(w))) return true;
          }
          return false;
      }
  
      @Override
      public V replace(Vertex&lt;V&gt; v, V x) {
          EdgeListVertex vertex = (EdgeListVertex) v;
          V temp = vertex.element;
          vertex.element = x;
          return temp;
      }
  
      @Override
      public E replace(Edge&lt;E&gt; e, E x) {
          EdgeListEdge edge = (EdgeListEdge) e;
          E temp = edge.element;
          edge.element = x;
          return temp;
      }
  
      @Override
      public Vertex&lt;V&gt; insertVertex(V v) {
          EdgeListVertex vertex = new EdgeListVertex(v);
          Position&lt;EdgeListVertex&gt; position = vertices.insertLast(vertex);
          vertex.position = position;
          return vertex;
      }
  
      @Override
      public Edge&lt;E&gt; insertEdge(Vertex&lt;V&gt; v, Vertex&lt;V&gt; w, E o) {
          EdgeListEdge edge = new EdgeListEdge((EdgeListVertex) v, (EdgeListVertex) w, o);
          Position&lt;EdgeListEdge&gt; position = edges.insertLast(edge);
          edge.position = position;
          return edge;
      }
  
      @Override
      public V removeVertex(Vertex&lt;V&gt; v) {
          Iterator&lt;Edge&lt;E&gt;&gt; it = incidentEdges(v).iterator();
          while (it.hasNext()) it.remove();
  
          EdgeListVertex vertex = (EdgeListVertex) v;
          vertices.remove(vertex.position);
          return vertex.element;
      }
  
      @Override
      public E removeEdge(Edge&lt;E&gt; e) {
          EdgeListEdge edge = (EdgeListEdge) e;
          edges.remove(edge.position);
          return edge.element;
      }
  
      @Override
      public List&lt;Edge&lt;E&gt;&gt; incidentEdges(Vertex&lt;V&gt; v) {
          LinkedList&lt;Edge&lt;E&gt;&gt; list = new LinkedList&lt;Edge&lt;E&gt;&gt;();
  
          for (EdgeListEdge edge : edges) {
              if (edge.start.equals(v)) list.insertLast(edge);
              if (edge.end.equals(v)) list.insertLast(edge);
          }
  
          return list;
      }
  
      @Override
      public List&lt;Vertex&lt;V&gt;&gt; vertices() {
          LinkedList&lt;Vertex&lt;V&gt;&gt; list = new LinkedList&lt;Vertex&lt;V&gt;&gt;();
          for (EdgeListVertex vertex : vertices) {
              list.insertLast(vertex);
          }
          return list;
      }
  
      @Override
      public List&lt;Edge&lt;E&gt;&gt; edges() {
          LinkedList&lt;Edge&lt;E&gt;&gt; list = new LinkedList&lt;Edge&lt;E&gt;&gt;();
          for (EdgeListEdge edge : edges) {
              list.insertLast(edge);
          }
          return list;
      }
  
  }
  </code></pre>
  
  <p>Any tips?</p>