edu.uci.ics.jung.graph.impl
Class AbstractSparseEdge

java.lang.Object
  extended by edu.uci.ics.jung.utils.UserDataDelegate
      extended by edu.uci.ics.jung.graph.impl.AbstractElement
          extended by edu.uci.ics.jung.graph.impl.AbstractArchetypeEdge
              extended by edu.uci.ics.jung.graph.impl.AbstractSparseEdge
All Implemented Interfaces:
ArchetypeEdge, Edge, Element, UserDataContainer, Cloneable
Direct Known Subclasses:
DirectedSparseEdge, UndirectedSparseEdge

public abstract class AbstractSparseEdge
extends AbstractArchetypeEdge
implements Edge

This class provides a skeletal implementation of the Edge interface to minimize the effort required to implement this interface. It is appropriate for sparse graphs (those in which each vertex is connected to only a few other vertices); for dense graphs (those in which each vertex is connected to most other vertices), another implementation might be more appropriate.

This class extends UserData, which provides storage and retrieval mechanisms for user-defined data for each edge instance. This allows users to attach data to edges without having to extend this class.

Author:
Joshua O'Madadhain, Danyel Fisher, Scott White
See Also:
AbstractSparseGraph, AbstractSparseVertex

Nested Class Summary
 
Nested classes/interfaces inherited from interface edu.uci.ics.jung.utils.UserDataContainer
UserDataContainer.CopyAction
 
Field Summary
protected  Vertex mFrom
          One of the two incident vertices of this edge.
protected  Vertex mTo
          One of the two incident vertices of this edge.
 
Fields inherited from class edu.uci.ics.jung.graph.impl.AbstractElement
id, m_Graph
 
Fields inherited from class edu.uci.ics.jung.utils.UserDataDelegate
factory, udc_delegate
 
Constructor Summary
AbstractSparseEdge(Vertex from, Vertex to)
          Creates an edge connecting vertices from and to.
 
Method Summary
 ArchetypeEdge copy(ArchetypeGraph newGraph)
          Creates a copy of this edge in the specified graph newGraph, and copies this edge's user data to the new edge.
 Pair getEndpoints()
          Returns a pair consisting of both incident vertices.
 Set getIncidentVertices()
          Returns the set of vertices which are incident to this edge.
 Vertex getOpposite(Vertex vertex)
          Returns the vertex at the opposite end of this edge from the specified vertex v.
 boolean isIncident(ArchetypeVertex v)
          Returns true if the specified vertex v is incident to this edge, and false otherwise.
 int numVertices()
          Returns the number of vertices which are incident to this edge.
 String toString()
          Returns a human-readable representation of this edge.
 
Methods inherited from class edu.uci.ics.jung.graph.impl.AbstractArchetypeEdge
equals, getEqualEdge, getEquivalentEdge, getIncidentElements
 
Methods inherited from class edu.uci.ics.jung.graph.impl.AbstractElement
addGraph_internal, getGraph, hashCode, initialize, removeGraph_internal
 
Methods inherited from class edu.uci.ics.jung.utils.UserDataDelegate
addUserDatum, clone, containsUserDatumKey, getUserDatum, getUserDatumCopyAction, getUserDatumKeyIterator, importUserData, removeUserDatum, setUserDataFactory, setUserDatum
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface edu.uci.ics.jung.graph.ArchetypeEdge
getEqualEdge, getEquivalentEdge
 
Methods inherited from interface edu.uci.ics.jung.graph.Element
getGraph, getIncidentElements
 
Methods inherited from interface edu.uci.ics.jung.utils.UserDataContainer
addUserDatum, clone, containsUserDatumKey, getUserDatum, getUserDatumCopyAction, getUserDatumKeyIterator, importUserData, removeUserDatum, setUserDatum
 

Field Detail

mFrom

protected Vertex mFrom
One of the two incident vertices of this edge. If this edge is directed, this is its source.


mTo

protected Vertex mTo
One of the two incident vertices of this edge. If this edge is directed, this is its destination.

Constructor Detail

AbstractSparseEdge

public AbstractSparseEdge(Vertex from,
                          Vertex to)
Creates an edge connecting vertices from and to. The order of the arguments is significant for implementations of DirectedEdge which extend this class, and is not significant for implementations of UndirectedEdge which extend this class.

Disallows the following:

Any of these will cause an IllegalArgumentException to be thrown.

Parameters:
from - one incident vertex (if edge is directed, the source)
to - the other incident vertex (if edge is directed, the destination)
Throws:
IllegalArgumentException
Method Detail

toString

public String toString()
Returns a human-readable representation of this edge.

Overrides:
toString in class Object
See Also:
Object.toString()

getIncidentVertices

public Set getIncidentVertices()
Description copied from interface: ArchetypeEdge
Returns the set of vertices which are incident to this edge. Each of the vertices returned should implement ArchetypeVertex. For example, returns the source and destination vertices of a directed edge.

Specified by:
getIncidentVertices in interface ArchetypeEdge
Returns:
the vertices incident to this edge
See Also:
ArchetypeEdge.getIncidentVertices()

getOpposite

public Vertex getOpposite(Vertex vertex)
Description copied from interface: Edge
Returns the vertex at the opposite end of this edge from the specified vertex v. Throws IllegalArgumentException if v is not incident to this edge.

For example, if this edge connects vertices a and b, this.getOpposite(a) returns b.

Specified by:
getOpposite in interface Edge
See Also:
Edge.getOpposite(Vertex)

numVertices

public int numVertices()
Description copied from interface: ArchetypeEdge
Returns the number of vertices which are incident to this edge.

Specified by:
numVertices in interface ArchetypeEdge
Overrides:
numVertices in class AbstractArchetypeEdge
See Also:
ArchetypeEdge.numVertices()

isIncident

public boolean isIncident(ArchetypeVertex v)
Description copied from interface: ArchetypeEdge
Returns true if the specified vertex v is incident to this edge, and false otherwise. The behavior of this method is undefined if v is not an element of this edge's graph.

Specified by:
isIncident in interface ArchetypeEdge
Overrides:
isIncident in class AbstractArchetypeEdge
See Also:
ArchetypeEdge.isIncident(ArchetypeVertex)

copy

public ArchetypeEdge copy(ArchetypeGraph newGraph)
Creates a copy of this edge in the specified graph newGraph, and copies this edge's user data to the new edge.

Specified by:
copy in interface ArchetypeEdge
Overrides:
copy in class AbstractArchetypeEdge
Parameters:
newGraph - the graph in which the copied edge will be placed
Returns:
the edge created
See Also:
ArchetypeEdge.copy(edu.uci.ics.jung.graph.ArchetypeGraph)

getEndpoints

public Pair getEndpoints()
Description copied from interface: Edge
Returns a pair consisting of both incident vertices. This is equivalent to getIncidentVertices, except that it returns the data in the form of a Pair rather than a Set. This allows easy access to the two vertices. Note that the pair is in no particular order.

Specified by:
getEndpoints in interface Edge
See Also:
Edge.getEndpoints()