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

java.lang.Object
  extended byedu.uci.ics.jung.utils.UserData
      extended byedu.uci.ics.jung.graph.impl.AbstractSparseEdge
All Implemented Interfaces:
ArchetypeEdge, java.lang.Cloneable, Edge, UserDataContainer
Direct Known Subclasses:
DirectedSparseEdge, UndirectedSparseEdge

public abstract class AbstractSparseEdge
extends UserData
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 inherited from class edu.uci.ics.jung.utils.UserDataContainer
UserDataContainer.CopyAction
 
Field Summary
 
Fields inherited from class edu.uci.ics.jung.utils.UserData
CLONE, REMOVE, SHARED
 
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 nGraph, and copies this edge's user data to the new edge.
 boolean equals(java.lang.Object o)
          Returns true if o is an instance of ArchetypeEdge that is equivalent to this edge.
 Pair getEndpoints()
          Returns a pair consisting of both incident vertices.
 ArchetypeEdge getEqualEdge(ArchetypeGraph ag)
          Returns the edge in graph g, if any, that is equivalent to this edge.
 ArchetypeEdge getEquivalentEdge(ArchetypeGraph ag)
          Deprecated. As of version 1.4, renamed to getEqualEdge(ag).
 ArchetypeGraph getGraph()
          Returns a reference to the graph that contains this edge.
 java.util.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.
 int hashCode()
           
 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.
 java.lang.String toString()
          Returns a human-readable representation of this edge.
 
Methods inherited from class edu.uci.ics.jung.utils.UserData
addUserDatum, containsUserDatumKey, getUserDatum, getUserDatumCopyAction, getUserDatumKeyIterator, importUserData, removeUserDatum, setUserDatum
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface edu.uci.ics.jung.utils.UserDataContainer
addUserDatum, containsUserDatumKey, getUserDatum, getUserDatumCopyAction, getUserDatumKeyIterator, importUserData, removeUserDatum, setUserDatum
 

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:
java.lang.IllegalArgumentException
Method Detail

toString

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

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

getGraph

public ArchetypeGraph getGraph()
Description copied from interface: ArchetypeEdge
Returns a reference to the graph that contains this edge. If this edge is not contained by any graph (is an "orphaned" edge), returns null.

Specified by:
getGraph in interface ArchetypeEdge
See Also:
ArchetypeEdge.getGraph()

getIncidentVertices

public java.util.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)

getEqualEdge

public ArchetypeEdge getEqualEdge(ArchetypeGraph ag)
Description copied from interface: ArchetypeEdge
Returns the edge in graph g, if any, that is equivalent to this edge. Two edges are equivalent if one of them is an ancestor (via copy()) of the other.

Specified by:
getEqualEdge in interface ArchetypeEdge
See Also:
ArchetypeEdge.getEqualEdge(edu.uci.ics.jung.graph.ArchetypeGraph)

getEquivalentEdge

public ArchetypeEdge getEquivalentEdge(ArchetypeGraph ag)
Deprecated. As of version 1.4, renamed to getEqualEdge(ag).

Specified by:
getEquivalentEdge in interface ArchetypeEdge

hashCode

public int hashCode()
See Also:
Object.hashCode()

equals

public boolean equals(java.lang.Object o)
Returns true if o is an instance of ArchetypeEdge that is equivalent to this edge. Respects the edge equivalences which are established by copy() and referenced by getEquivalentEdge().

See Also:
Object.equals(java.lang.Object), ArchetypeEdge.getEqualEdge(ArchetypeGraph), ArchetypeEdge.copy(edu.uci.ics.jung.graph.ArchetypeGraph)

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
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
See Also:
ArchetypeEdge.isIncident(ArchetypeVertex)

copy

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

Specified by:
copy in interface ArchetypeEdge
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()