View Javadoc

1   /*
2    * Copyright 2004 Ronald Blaschke.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.rblasch.convert.graph;
17  
18  import java.util.Iterator;
19  import java.util.LinkedList;
20  import java.util.List;
21  
22  public class ListPath implements Path {
23      private final List /* of Vertex, Edge */ path;
24  
25      public ListPath(final List /* of Vertex, Edge */ path) {
26          this.path = path;
27      }
28  
29      public Vertex getStart() {
30          return (Vertex) path.get(0);
31      }
32  
33      public Vertex getEnd() {
34          return (Vertex) path.get(path.size() - 1);
35      }
36  
37      public List /* of Vertex */ getVertices() {
38          final List /* of Vertex */ vertices = new LinkedList();
39          for (final Iterator i = path.iterator(); i.hasNext();) {
40              final Object n = i.next();
41              if (n instanceof Vertex) {
42                  vertices.add(n);
43              }
44          }
45          return vertices;
46      }
47  
48      public List /* of Edge */ getEdges() {
49          final List /* of Edge */ edges = new LinkedList();
50          for (final Iterator i = path.iterator(); i.hasNext();) {
51              final Object n = i.next();
52              if (n instanceof Edge) {
53                  edges.add(n);
54              }
55          }
56          return edges;
57      }
58  
59      public Iterator /* of Vertex, Edge */ iterator() {
60          return path.iterator();
61      }
62  }