1 25 43 package org.jgrapht.graph; 44 45 import java.io.*; 46 47 import java.util.*; 48 49 import org.jgrapht.*; 50 import org.jgrapht.util.*; 51 52 53 78 public class AsUndirectedGraph<V, E> 79 extends GraphDelegator<V, E> 80 implements Serializable, UndirectedGraph<V, E> 81 { 82 83 85 private static final long serialVersionUID = 3257845485078065462L; private static final String NO_EDGE_ADD = 87 "this graph does not support edge addition"; 88 private static final String UNDIRECTED = 89 "this graph only supports undirected operations"; 90 91 93 99 public AsUndirectedGraph(DirectedGraph<V, E> g) 100 { 101 super(g); 102 } 103 104 106 109 public Set<E> getAllEdges(V sourceVertex, V targetVertex) 110 { 111 Set<E> forwardList = super.getAllEdges(sourceVertex, targetVertex); 112 113 if (sourceVertex.equals(targetVertex)) { 114 return forwardList; 116 } 117 118 Set<E> reverseList = super.getAllEdges(targetVertex, sourceVertex); 119 Set<E> list = 120 new ArrayUnenforcedSet<E>( 121 forwardList.size() + reverseList.size()); 122 list.addAll(forwardList); 123 list.addAll(reverseList); 124 125 return list; 126 } 127 128 131 public E getEdge(V sourceVertex, V targetVertex) 132 { 133 E edge = super.getEdge(sourceVertex, targetVertex); 134 135 if (edge != null) { 136 return edge; 137 } 138 139 return super.getEdge(targetVertex, sourceVertex); 141 } 142 143 146 public E addEdge(V sourceVertex, V targetVertex) 147 { 148 throw new UnsupportedOperationException (NO_EDGE_ADD); 149 } 150 151 154 public boolean addEdge(V sourceVertex, V targetVertex, E e) 155 { 156 throw new UnsupportedOperationException (NO_EDGE_ADD); 157 } 158 159 162 public int degreeOf(V vertex) 163 { 164 return super.inDegreeOf(vertex) + super.outDegreeOf(vertex); 166 } 167 168 171 public int inDegreeOf(V vertex) 172 { 173 throw new UnsupportedOperationException (UNDIRECTED); 174 } 175 176 179 public Set<E> incomingEdgesOf(V vertex) 180 { 181 throw new UnsupportedOperationException (UNDIRECTED); 182 } 183 184 187 public int outDegreeOf(V vertex) 188 { 189 throw new UnsupportedOperationException (UNDIRECTED); 190 } 191 192 195 public Set<E> outgoingEdgesOf(V vertex) 196 { 197 throw new UnsupportedOperationException (UNDIRECTED); 198 } 199 200 203 public String toString() 204 { 205 return super.toStringFromSets(vertexSet(), edgeSet(), false); 206 } 207 } 208 | Popular Tags |