1 25 41 package org.jgrapht.alg; 42 43 import java.util.*; 44 45 import org.jgrapht.*; 46 47 48 59 abstract class AbstractPathElement<V, E> 60 { 61 62 64 67 protected int nHops; 68 69 72 protected E prevEdge; 73 74 77 protected AbstractPathElement<V, E> prevPathElement; 78 79 82 private V vertex; 83 84 86 92 protected AbstractPathElement( 93 Graph<V, E> graph, 94 AbstractPathElement<V, E> pathElement, 95 E edge) 96 { 97 this.vertex = 98 Graphs.getOppositeVertex( 99 graph, 100 edge, 101 pathElement.getVertex()); 102 this.prevEdge = edge; 103 this.prevPathElement = pathElement; 104 105 this.nHops = pathElement.getHopCount() + 1; 106 } 107 108 113 protected AbstractPathElement(AbstractPathElement<V, E> original) 114 { 115 this.nHops = original.nHops; 116 this.prevEdge = original.prevEdge; 117 this.prevPathElement = original.prevPathElement; 118 this.vertex = original.vertex; 119 } 120 121 126 protected AbstractPathElement(V vertex) 127 { 128 this.vertex = vertex; 129 this.prevEdge = null; 130 this.prevPathElement = null; 131 132 this.nHops = 0; 133 } 134 135 137 142 public List<E> createEdgeListPath() 143 { 144 List<E> path = new ArrayList<E>(); 145 AbstractPathElement<V, E> pathElement = this; 146 147 while (pathElement.getPrevEdge() != null) { 149 path.add(pathElement.getPrevEdge()); 150 151 pathElement = pathElement.getPrevPathElement(); 152 } 153 154 Collections.reverse(path); 155 156 return path; 157 } 158 159 164 public int getHopCount() 165 { 166 return this.nHops; 167 } 168 169 174 public E getPrevEdge() 175 { 176 return this.prevEdge; 177 } 178 179 184 public AbstractPathElement<V, E> getPrevPathElement() 185 { 186 return this.prevPathElement; 187 } 188 189 194 public V getVertex() 195 { 196 return this.vertex; 197 } 198 } 199 | Popular Tags |