scg.ac.ni.pmf.newgraph.graphdata
Class GraphData

java.lang.Object
  extended by scg.ac.ni.pmf.newgraph.graphdata.GraphData
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable

public final class GraphData
extends java.lang.Object
implements java.lang.Cloneable, java.io.Serializable

The class holds information about a graph. It contains data about:

  1. the structure of the graph
  2. weights of the graph vertices and edges
  3. the current selection
  4. graphical representation of the graph
  5. name of the graph
  6. name of the file where the graph is stored

The structure of the graph are the sets of vertices and edges. Each vertex has ID. ID is the numerical identificator used internally in the program.

The current selection are the vertices and edges selected in the graph edit pane. Each selection has a primary selected vertex and edge, which are the first selected vertex and edge in the selection. The graph edit pane also has a graphical representation of the graph, with each vertex having its X and Y coordinate. Each graph also has a name, which is the name of the file where the graph is stored.

The class also provides three essential tasks with the graph data. It:

  1. provides methods for the basic manipulation of the graph data
  2. enforces the data integrity
  3. provides basic methods to report the structure of the graph

.

The class can not change the graph structure. To change the graph structure, use Graph.

Author:
Vladimir Brankov
See Also:
Graph, EdgeData, VertexData, Serialized Form

Method Summary
 int[][] adjacencyMatrix()
          Creates the adjacency matrix of the graph.
 java.lang.Object clone()
          Clones the object.
 int degree(int id)
          Retrieves the degree of the vertex.
 int[][] distances()
          Retrieves the array of distances between vertices.
 java.util.Enumeration edges()
          Retrieves an enumeration on all the edges of the graph.
 boolean equals(java.lang.Object o)
          Indicates whether some other object is "equal to" this one.
 java.lang.String getAbsolutePath()
          Retrieves the file absolute path.
 java.util.Set getAllWeights()
          Retrieves a set of all the weights defined in the graph.
 java.util.Set getComponent(int id)
          Retrieves the set of all the vertices that are connected to the given vertex.
 java.util.Set getComponentO(int id)
          Retrieves the set of all the vertices that are connected to the given vertex.
 EdgeData getEdge(VertexData va, VertexData vb)
          Retrieves the edge with the given vertices as endpoints, or null, if no such edge exists.
 java.lang.String getFileName()
          Retrieves the name of the file.
 int getIndex(EdgeData edgeData)
          Retrieves the index of the edge data in the edge enumeration.
 int getIndex(VertexData vertexData)
          Retrieves the index of the vertex data in the adjacency matrix, and in the vertex enumeration.
 int getNumberOfEdges()
          Retrieves the number of edges.
 int getOrder()
          Retrieves the order of the graph (the number of vertices).
 EdgeData getPrimarySelectedEdge()
          Retrieves the primary selected edge.
 VertexData getPrimarySelectedVertex()
          Retrieves the primary selected vertex.
 int getSelectedEdgesNo()
          Retrieves the number of selected edges.
 int getSelectedVerticesNo()
          Retrieves the number of selected vertices.
 VertexData getVertex(int id)
          Retrieves the vertex with the given ID, or null, if such vertex does not exist.
 double getWeight(EdgeData e, scg.ac.ni.pmf.newgraph.graphdata.WeightEdgeDouble weight)
          Retrieves the weight double value of the edge.
 int getWeight(EdgeData e, scg.ac.ni.pmf.newgraph.graphdata.WeightEdgeInt weight)
          Retrieves the weight integer value of the edge.
 java.lang.String getWeight(EdgeData e, scg.ac.ni.pmf.newgraph.graphdata.WeightEdgeString weight)
          Retrieves the weight string value of the edge.
 double getWeight(VertexData v, scg.ac.ni.pmf.newgraph.graphdata.WeightVertexDouble weight)
          Retrieves the weight double value of the vertex.
 int getWeight(VertexData v, scg.ac.ni.pmf.newgraph.graphdata.WeightVertexInt weight)
          Retrieves the weight integer value of the vertex.
 java.lang.String getWeight(VertexData v, scg.ac.ni.pmf.newgraph.graphdata.WeightVertexString weight)
          Retrieves the weight string value of the vertex.
 java.util.Map getWeights(EdgeData e)
          Retrieves a map of weights of the edge into weight values.
 java.util.Map getWeights(VertexData v)
          Retrieves a map of weights of the vertex into weight values.
 int hashCode()
          Generates the hash code of the object.
 boolean hasWeight(EdgeData e, scg.ac.ni.pmf.newgraph.graphdata.Weight weight)
          Indicates whether there exist a weight value of the edge.
 boolean hasWeight(VertexData v, scg.ac.ni.pmf.newgraph.graphdata.Weight weight)
          Indicates whether there exist a weight value of the vertex.
 boolean isAdjanced(int idA, int idB)
          Retrieves are the vertices adjanced.
 boolean isAdjanced(VertexData va, VertexData vb)
          Retrieves are the vertices adjanced.
 boolean isDirty()
          Retrieves was the graph changed after the last save.
 boolean isPrimarySelected(Edge edge)
          Retrieves is the edge primary selected.
 boolean isPrimarySelected(EdgeData edge)
          Retrieves is the edge primary selected.
 boolean isPrimarySelected(Element element)
          Retrieves is the given element primary selected.
 boolean isPrimarySelected(ElementData element)
          Retrieves is the given element primary selected.
 boolean isPrimarySelected(int id)
          Indicates whether the vertex with the given ID is primary selected.
 boolean isPrimarySelected(int idA, int idB)
          Retrieves is the edge with the given endpoints primary selected.
 boolean isPrimarySelected(Vertex vertex)
          Indicates whether the vertex is primary selected.
 boolean isPrimarySelected(VertexData vertex)
          Indicates whether the vertex is primary selected.
 boolean isSelected(EdgeData e)
          Retrieves is the edge selected.
 boolean isSelected(int id)
          Retrieves is the vertex selected.
 boolean isSelected(int idA, int idB)
          Retrieves is the specified edge selected.
 boolean isSelected(VertexData v)
          Retrieves is the vertex selected.
 boolean isSelected(VertexData va, VertexData vb)
          Retrieves is the edge selected.
 boolean isSelectionEmpty()
          Retrieves is the selection empty.
 int[][] laplacianMatrix()
          Creates the Laplacian matrix of the graph.
 java.util.Enumeration neighbors(int id)
          Retrieves an enumeration of neighbors of the specified vertex.
 boolean sameStructure(GraphData data)
          Checks if the given graph data has the same structure as the graph data.
 java.util.Enumeration selectedEdges()
          Retrieves an enumeration on all the selected edges.
 java.util.Enumeration selectedVertices()
          Retrieves an enumeration on all the selected vertices.
 java.lang.String toString()
          Retrieves the string representation of the graph data.
 java.util.Enumeration vertices()
          Retrieves an enumeration on all the vertices of the graph.
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Method Detail

vertices

public java.util.Enumeration vertices()
Retrieves an enumeration on all the vertices of the graph.

Returns:
Enumeration An enumeration of VertexData.

getOrder

public int getOrder()
Retrieves the order of the graph (the number of vertices).

Returns:
int The order.

getVertex

public VertexData getVertex(int id)
Retrieves the vertex with the given ID, or null, if such vertex does not exist.

Parameters:
id - The ID of the vertex.
Returns:
Vertex The vertex.

getIndex

public int getIndex(VertexData vertexData)
Retrieves the index of the vertex data in the adjacency matrix, and in the vertex enumeration.

Parameters:
vertexData - The vertex data.
Returns:
The index.

edges

public java.util.Enumeration edges()
Retrieves an enumeration on all the edges of the graph.

Returns:
Enumeration An enumeration of EdgeData.

getNumberOfEdges

public int getNumberOfEdges()
Retrieves the number of edges.

Returns:
int The number of edges.

getEdge

public EdgeData getEdge(VertexData va,
                        VertexData vb)
Retrieves the edge with the given vertices as endpoints, or null, if no such edge exists.

Parameters:
va - The first vertex.
vb - The second vertex.
Returns:
EdgeData The edge.

getIndex

public int getIndex(EdgeData edgeData)
Retrieves the index of the edge data in the edge enumeration.

Parameters:
edgeData - The edge data.
Returns:
The index.

isAdjanced

public boolean isAdjanced(int idA,
                          int idB)
Retrieves are the vertices adjanced.

Parameters:
idA - The ID of one of the endpoints.
idB - The ID of the other endpoint.
Returns:
boolean Indicates are the vertices adjanced.

isAdjanced

public boolean isAdjanced(VertexData va,
                          VertexData vb)
Retrieves are the vertices adjanced.

Parameters:
va - The first vertex.
vb - The second vertex.
Returns:
boolean Indicates are the vertices adjanced.

selectedVertices

public java.util.Enumeration selectedVertices()
Retrieves an enumeration on all the selected vertices.

Returns:
Enumeration An enumeration of VertexData.

isSelected

public boolean isSelected(int id)
Retrieves is the vertex selected.

Parameters:
id - The vertex.
Returns:
boolean Indicates is the vertex selected.

isSelected

public boolean isSelected(VertexData v)
Retrieves is the vertex selected.

Parameters:
v - The vertex data.
Returns:
boolean Indicates is the vertex selected.

getSelectedVerticesNo

public int getSelectedVerticesNo()
Retrieves the number of selected vertices.

Returns:
int The number of selected vertices.

selectedEdges

public java.util.Enumeration selectedEdges()
Retrieves an enumeration on all the selected edges.

Returns:
Enumeration An enumeration of EdgeData.

isSelected

public boolean isSelected(int idA,
                          int idB)
Retrieves is the specified edge selected.

Parameters:
idA - The ID of one of the endpoints.
idB - The ID of the other endpoint.
Returns:
boolean Indicates is the edge selected.

isSelected

public boolean isSelected(EdgeData e)
Retrieves is the edge selected.

Parameters:
e - The edge data.
Returns:
boolean Indicates is the edge selected.

isSelected

public boolean isSelected(VertexData va,
                          VertexData vb)
Retrieves is the edge selected.

Parameters:
va - One of the edge endpoints.
vb - The other edge endpoint.
Returns:
boolean Indicates is the edge selected.

getSelectedEdgesNo

public int getSelectedEdgesNo()
Retrieves the number of selected edges.

Returns:
int The number of selected edges.

isSelectionEmpty

public boolean isSelectionEmpty()
Retrieves is the selection empty.

Returns:
boolean If the selection is empty.

getPrimarySelectedVertex

public VertexData getPrimarySelectedVertex()
Retrieves the primary selected vertex.

Returns:
VertexData The vertex data.

isPrimarySelected

public boolean isPrimarySelected(int id)
Indicates whether the vertex with the given ID is primary selected.

Parameters:
id - The ID of the vertex.
Returns:
boolean Indicates whether the vertex is primary selected.

isPrimarySelected

public boolean isPrimarySelected(VertexData vertex)
Indicates whether the vertex is primary selected.

Parameters:
vertex - The vertex data.
Returns:
boolean Indicates whether the vertex is primary selected.

isPrimarySelected

public boolean isPrimarySelected(Vertex vertex)
Indicates whether the vertex is primary selected.

Parameters:
vertex - The vertex.
Returns:
boolean Indicates whether the vertex is primary selected.

getPrimarySelectedEdge

public EdgeData getPrimarySelectedEdge()
Retrieves the primary selected edge.

Returns:
EdgeData The edge data.

isPrimarySelected

public boolean isPrimarySelected(int idA,
                                 int idB)
Retrieves is the edge with the given endpoints primary selected.

Parameters:
idA - The ID of one of the endpoints.
idB - The ID of the other endpoint.
Returns:
boolean Indicates whether the edge is primary selected.

isPrimarySelected

public boolean isPrimarySelected(EdgeData edge)
Retrieves is the edge primary selected.

Parameters:
edge - The edge data.

isPrimarySelected

public boolean isPrimarySelected(Edge edge)
Retrieves is the edge primary selected.

Parameters:
edge - The edge.

isPrimarySelected

public boolean isPrimarySelected(ElementData element)
Retrieves is the given element primary selected.

Parameters:
element - The element data.
Returns:
boolean Indicates whether the element is primary selected.

isPrimarySelected

public boolean isPrimarySelected(Element element)
Retrieves is the given element primary selected.

Parameters:
element - The element.
Returns:
boolean Indicates whether the element is primary selected.

getFileName

public java.lang.String getFileName()
Retrieves the name of the file.

Returns:
String The name of the file.

getAbsolutePath

public java.lang.String getAbsolutePath()
Retrieves the file absolute path.

Returns:
String The file absolute path.

isDirty

public boolean isDirty()
Retrieves was the graph changed after the last save.

Returns:
boolean

degree

public int degree(int id)
Retrieves the degree of the vertex.

Parameters:
id - The ID of the vertex.
Returns:
int The degree.

neighbors

public java.util.Enumeration neighbors(int id)
Retrieves an enumeration of neighbors of the specified vertex.

Parameters:
id - The ID of the vertex.
Returns:
Enumeration An enumeration of VertexData.

adjacencyMatrix

public int[][] adjacencyMatrix()
Creates the adjacency matrix of the graph.

Returns:
boolean The adjacency matrix.

laplacianMatrix

public int[][] laplacianMatrix()
Creates the Laplacian matrix of the graph.

Returns:
boolean The adjacency matrix.

distances

public int[][] distances()
Retrieves the array of distances between vertices. Implements the Dijkstra's algorithm.

Returns:
int[][] The array of distances.

getComponent

public java.util.Set getComponent(int id)
Retrieves the set of all the vertices that are connected to the given vertex.

Parameters:
id - The ID of the vertex.
Returns:
Set The set of VertexData.

getComponentO

public java.util.Set getComponentO(int id)
Retrieves the set of all the vertices that are connected to the given vertex.

Parameters:
id - The ID of the vertex.
Returns:
Set The set of Vertex.

clone

public java.lang.Object clone()
Clones the object.

Overrides:
clone in class java.lang.Object

equals

public boolean equals(java.lang.Object o)
Indicates whether some other object is "equal to" this one.

Overrides:
equals in class java.lang.Object
See Also:
Object.equals(Object)

sameStructure

public boolean sameStructure(GraphData data)
Checks if the given graph data has the same structure as the graph data.

Parameters:
data - The graph data.
Returns:
Indicates whether the structure is the same.

toString

public java.lang.String toString()
Retrieves the string representation of the graph data.

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

hashCode

public int hashCode()
Generates the hash code of the object.

Overrides:
hashCode in class java.lang.Object
See Also:
Object.hashCode()

getWeight

public int getWeight(VertexData v,
                     scg.ac.ni.pmf.newgraph.graphdata.WeightVertexInt weight)
Retrieves the weight integer value of the vertex.

Parameters:
v - The vertex.
weight - The weight.

getWeight

public double getWeight(VertexData v,
                        scg.ac.ni.pmf.newgraph.graphdata.WeightVertexDouble weight)
Retrieves the weight double value of the vertex.

Parameters:
v - The vertex.
weight - The weight.

getWeight

public java.lang.String getWeight(VertexData v,
                                  scg.ac.ni.pmf.newgraph.graphdata.WeightVertexString weight)
Retrieves the weight string value of the vertex.

Parameters:
v - The vertex.
weight - The weight.

hasWeight

public boolean hasWeight(VertexData v,
                         scg.ac.ni.pmf.newgraph.graphdata.Weight weight)
Indicates whether there exist a weight value of the vertex.

Parameters:
v - The vertex.
weight - The weight.

getWeights

public java.util.Map getWeights(VertexData v)
Retrieves a map of weights of the vertex into weight values.

Parameters:
v - The vertex.

getWeight

public int getWeight(EdgeData e,
                     scg.ac.ni.pmf.newgraph.graphdata.WeightEdgeInt weight)
Retrieves the weight integer value of the edge.

Parameters:
e - The edge.
weight - The weight.

getWeight

public double getWeight(EdgeData e,
                        scg.ac.ni.pmf.newgraph.graphdata.WeightEdgeDouble weight)
Retrieves the weight double value of the edge.

Parameters:
e - The edge.
weight - The weight.

getWeight

public java.lang.String getWeight(EdgeData e,
                                  scg.ac.ni.pmf.newgraph.graphdata.WeightEdgeString weight)
Retrieves the weight string value of the edge.

Parameters:
e - The edge.
weight - The weight.

hasWeight

public boolean hasWeight(EdgeData e,
                         scg.ac.ni.pmf.newgraph.graphdata.Weight weight)
Indicates whether there exist a weight value of the edge.

Parameters:
e - The edge.
weight - The weight.

getWeights

public java.util.Map getWeights(EdgeData e)
Retrieves a map of weights of the edge into weight values.

Parameters:
e - The edge.

getAllWeights

public java.util.Set getAllWeights()
Retrieves a set of all the weights defined in the graph.

Returns:
The set of all the weights defined in the graph.


Copyright © 2004 Dragan Stevanovic, Vladimir Brankov.