Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## edu.uci.ics.jung.graph.impl
Class AbstractSparseGraph

    java.lang.Object
      edu.uci.ics.jung.utils.UserDataDelegate
          edu.uci.ics.jung.graph.impl.AbstractArchetypeGraph
              edu.uci.ics.jung.graph.impl.AbstractSparseGraph

All Implemented Interfaces:
  ArchetypeGraph, Cloneable, Graph, UserDataContainer

Direct Known Subclasses:
  SparseGraph

public abstract class AbstractSparseGraph
extends AbstractArchetypeGraph
implements Graph, Cloneable

This class provides a skeletal implementation of the `Graph` interface to minimize the effort required to implement this interface. This graph implementation stores vertices and edges in Sets. It is appropriate for sparse graphs (those in which each vertex has only a few neighbors). For dense graphs (those in which each vertex is connected to most other vertices), a different implementation (for example, one which represents a graph via a matrix) may be more appropriate.

Currently, the addition and removal methods will notify their arguments that they have been added to or removed from this graph only if they are instances of `AbstractSparseVertex` or `AbstractSparseEdge`.

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

Constraints imposed by this class:

system (invisible, unmodifiable) constraints: `NotInGraphVertexPredicate`, `NotInGraphEdgePredicate`
user (visible, modifiable via `getEdgeConstraints`): none

Author:
  Scott D. White, Danyel Fisher, Joshua O'Madadhain

Nested Class Summary

Nested classes inherited from class edu.uci.ics.jung.graph.impl.AbstractArchetypeGraph
`AbstractArchetypeGraph.Requirements`

Nested classes inherited from class edu.uci.ics.jung.utils.UserDataContainer
`UserDataContainer.CopyAction`

Field Summary
`protected Set` | `mEdges` The set of edges registered with the graph.
`protected Set` | `mVertices` The set of vertices registered with the graph.

Fields inherited from class edu.uci.ics.jung.graph.impl.AbstractArchetypeGraph
`edge_requirements, mEdgeIDs, mGraphListenerHandler, mVertexIDs, vertex_requirements`

Fields inherited from class edu.uci.ics.jung.utils.UserDataDelegate
`factory, udc_delegate`

Fields inherited from interface edu.uci.ics.jung.graph.Graph
`DIRECTED_EDGE, NOT_PARALLEL_EDGE, SIMPLE_EDGE, UNDIRECTED_EDGE`

Fields inherited from interface edu.uci.ics.jung.graph.ArchetypeGraph
`SUBSET_MANAGER`

Constructor Summary
`AbstractSparseGraph()` Creates an instance of a sparse graph.

Method Summary
`Edge` | `addEdge(Edge e)` Adds `e` to this graph, and returns a reference to the added vertex.
`Vertex` | `addVertex(Vertex v)` Adds `v` to this graph, and returns a reference to the added vertex.
`Set` | `getEdges()` Returns an unmodifiable set view of the edges in this graph.
`Set` | `getVertices()` Returns an unmodifiable set view of the vertices in this graph.
`protected void` | `initialize()` Initializes all of the graph's internal data structures.
`boolean` | `isDirected()` Returns `true` if each edge of this graph is directed, and `false` if each edge of this graph is undirected.
`void` | `removeEdge(Edge e)` Removes the edge from the graph, and notifies that the edge and its incident vertices that it has been removed.
`void` | `removeEdges(Set edges)` Removes all vertices in the specified set from `g`.
`void` | `removeVertex(Vertex v)` Removes all edges adjacent to the specified vertex, removes the vertex, and notifies the vertex that it has been removed.
`void` | `removeVertices(Set vertices)` Removes all vertices in the specified set from `g`.

Methods inherited from class edu.uci.ics.jung.graph.impl.AbstractArchetypeGraph
`addAllNotInitializers, addListener, checkConstraints, copy, getEdgeConstraints, getVertexConstraints, listenersExist, newInstance, numEdges, numVertices, removeAllEdges, removeAllVertices, removeListener, toString`

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
`equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Methods inherited from interface edu.uci.ics.jung.graph.ArchetypeGraph
`addListener, copy, getEdgeConstraints, getVertexConstraints, newInstance, numEdges, numVertices, removeAllEdges, removeAllVertices, removeListener`

Methods inherited from interface edu.uci.ics.jung.utils.UserDataContainer
`addUserDatum, clone, containsUserDatumKey, getUserDatum, getUserDatumCopyAction, getUserDatumKeyIterator, importUserData, removeUserDatum, setUserDatum`

Field Detail

### mVertices

    protected Set mVertices

  The set of vertices registered with the graph.

### mEdges

    protected Set mEdges

  The set of edges registered with the graph.

Constructor Detail

### AbstractSparseGraph

    public AbstractSparseGraph()

  Creates an instance of a sparse graph. Invokes `initialize()` to set up the local data structures.

See Also:
  `initialize()`

Method Detail

### initialize

    protected void initialize()

  Description copied from class: `AbstractArchetypeGraph`
  Initializes all of the graph's internal data structures. Should always be called by any mechanism that creates a new instance of AbstractSparseGraph (for example, constructors and implementations of newInstance()). If you add predicates here, please set their isInitializeFlag to TRUE.

  Note: this method is not a substitute for `removeAllVertices()`, as it will not notify the vertices and edges that they have been removed from the graph.

  Overrides:
    `initialize` in class `AbstractArchetypeGraph`

### getVertices

    public Set getVertices()

  Returns an unmodifiable set view of the vertices in this graph. Will reflect changes made to the graph after the view is generated.

  Specified by:
    `getVertices` in interface `ArchetypeGraph`
  See Also:
    `ArchetypeGraph.getVertices()`, `Collections.unmodifiableSet(java.util.Set)`

### getEdges

    public Set getEdges()

  Returns an unmodifiable set view of the edges in this graph. Will reflect changes made to the graph after the view is generated.

  Specified by:
    `getEdges` in interface `ArchetypeGraph`
  See Also:
    `ArchetypeGraph.getEdges()`, `Collections.unmodifiableSet(java.util.Set)`

### addEdge

    public Edge addEdge(Edge e)

  Description copied from interface: `Graph`
  Adds `e` to this graph, and returns a reference to the added vertex.

  Specified by:
    `addEdge` in interface `Graph`
  Parameters:
    `e` - the edge to be added
  See Also:
    `Graph.addEdge(edu.uci.ics.jung.graph.Edge)`

### addVertex

    public Vertex addVertex(Vertex v)

  Description copied from interface: `Graph`
  Adds `v` to this graph, and returns a reference to the added vertex.

  Specified by:
    `addVertex` in interface `Graph`
  Parameters:
    `v` - the vertex to be added
  See Also:
    `Graph.addVertex(edu.uci.ics.jung.graph.Vertex)`

### removeVertex

    public void removeVertex(Vertex v)

  Removes all edges adjacent to the specified vertex, removes the vertex, and notifies the vertex that it has been removed. Note: the vertex will not be notified unless it is an instance of `AbstractSparseVertex`.

  Specified by:
    `removeVertex` in interface `Graph`

### removeEdge

    public void removeEdge(Edge e)

  Removes the edge from the graph, and notifies that the edge and its incident vertices that it has been removed. Note: the edge will not be notified unless it is an instance of `AbstractSparseEdge`, and the incident vertices will not be notified unless they are instances of `AbstractSparseVertex`.

  Specified by:
    `removeEdge` in interface `Graph`

### isDirected

    public boolean isDirected()

  Deprecated. As of version 1.4, the semantics of this method have changed; it no longer returns a boolean value that is hardwired into the class definition, but checks to see whether one of the requirements of this graph is that it only accepts directed edges.

  Description copied from interface: `Graph`
  Returns `true` if each edge of this graph is directed, and `false` if each edge of this graph is undirected. If some edges are directed and some are not, throws `FatalException`.

  Specified by:
    `isDirected` in interface `Graph`
  See Also:
    `Graph.isDirected()`

### removeVertices

    public void removeVertices(Set vertices)

  Removes all vertices in the specified set from `g`. Syntactic sugar for a loop that calls `g.removeVertex` on all elements of the set. If any element of `vertices` is not part of this graph, then throws `IllegalArgumentException`. If this exception is thrown, any vertices that may have been removed already are not guaranteed to be restored to the graph.

  Specified by:
    `removeVertices` in interface `ArchetypeGraph`
  Parameters:
    `vertices` - the set of vertices to be removed

### removeEdges

    public void removeEdges(Set edges)

  Removes all vertices in the specified set from `g`. Syntactic sugar for a loop that calls `g.removeVertex` on all elements of the set. If any element of `edges` is not part of this graph, then throws `IllegalArgumentException`. If this exception is thrown, any edges that may have been removed already are not guaranteed to be restored to the graph.

  Specified by:
    `removeEdges` in interface `ArchetypeGraph`

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD