The mathIT Library
A Java™ API for mathematics
org.mathIT.graphs

Class Edge<V extends Vertible<V>>

• Type Parameters:
`V` - Vertex type

```public class Edge<V extends Vertible<V>>
extends Object```
Objects of this class represent edges of general graphs. Although an edge of this class does not play the fundamental role internally in the math IT graph framework (edges are represented primarily on the adjacency matrix matrix of the `Graph class`), it is needed as basis for some additional tasks, e.g., graph visualization.
Version:
1.0
Author:
Andreas de Vries
• Field Summary

Fields
Modifier and Type Field and Description
`protected boolean` `directed`
Flag indicating whether this edge is directed.
`protected V` `end`
The end vertex of this edge.
`protected String` `label`
The label of thius graph.
`protected V` `start`
The start vertex of this edge.
`protected double` `weight`
The weight of this edge.
`protected boolean` `weighted`
Flag indicating whether this edge is directed.
• Constructor Summary

Constructors
Constructor and Description
```Edge(String label, V startVertex, V endVertex)```
```Edge(String label, V startVertex, V endVertex, boolean directed)```
```Edge(String label, V startVertex, V endVertex, boolean directed, double weight)```
```Edge(V startVertex, V endVertex)```
Creates a directed edge with the specified vertices.
```Edge(V v, V w, boolean directed)```
Creates an edge with the specified properties.
```Edge(V startVertex, V endVertex, boolean directed, double weight)```
Creates a weighted edge with the specified properties.
• Method Summary

All Methods
Modifier and Type Method and Description
`V` `getEndVertex()`
Returns the end vertex of this edge.
`V` `getStartVertex()`
Returns the start vertex of this edge.
`double` `getWeight()`
Returns the weight of this edge.
`boolean` `isDirected()`
Returns true if and only if this edge is directed.
`boolean` `isWeighted()`
Returns true if and only if this edge is weighted.
`String` `toString()`
Returns the label of this edge, or the weight if the edge is weighted.
• Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`
• Field Detail

• label

`protected String label`
The label of thius graph.
• start

`protected V extends Vertible<V> start`
The start vertex of this edge.
• end

`protected V extends Vertible<V> end`
The end vertex of this edge.
• directed

`protected boolean directed`
Flag indicating whether this edge is directed.
• weighted

`protected boolean weighted`
Flag indicating whether this edge is directed.
• weight

`protected double weight`
The weight of this edge. It is zero by default.
• Constructor Detail

• Edge

```public Edge(V startVertex,
V endVertex)```
Creates a directed edge with the specified vertices. The label is specified as the string "(vs,ve)" where vs denotes the start vertex and ve the end vertex.
Parameters:
`startVertex` - the start vertex of this edge
`endVertex` - the end vertex of this edge
• Edge

```public Edge(V v,
V w,
boolean directed)```
Creates an edge with the specified properties. The label is specified as the string "(v, w)" if the edge is directed, and as the string "{v, w}" if the edge is undirected,
Parameters:
`v` - the start vertex of this edge
`w` - the end vertex of this edge
`directed` - flag indicating whether this edge is directed
• Edge

```public Edge(String label,
V startVertex,
V endVertex)```
Parameters:
`label` - the label of this edge
`startVertex` - the start vertex of this edge
`endVertex` - the end vertex of this edge
• Edge

```public Edge(String label,
V startVertex,
V endVertex,
boolean directed)```
Parameters:
`label` - the label of this edge
`startVertex` - the start vertex of this edge
`endVertex` - the end vertex of this edge
`directed` - flag indicating whether this edge is directed
• Edge

```public Edge(V startVertex,
V endVertex,
boolean directed,
double weight)```
Creates a weighted edge with the specified properties. The label is set to the weight.
Parameters:
`startVertex` - the start vertex of this edge
`endVertex` - the end vertex of this edge
`directed` - flag indicating whether this edge is directed
`weight` - the weight of this edge
• Edge

```public Edge(String label,
V startVertex,
V endVertex,
boolean directed,
double weight)```
Parameters:
`label` - the label of this edge
`startVertex` - the start vertex of this edge
`endVertex` - the end vertex of this edge
`directed` - flag indicating whether this edge is directed
`weight` - the weight of this edge
• Method Detail

• getStartVertex

`public V getStartVertex()`
Returns the start vertex of this edge.
Returns:
the start vertex of this edge
• getEndVertex

`public V getEndVertex()`
Returns the end vertex of this edge.
Returns:
the end vertex of this edge
• isDirected

`public boolean isDirected()`
Returns true if and only if this edge is directed.
Returns:
true if and only if this edge is directed
• isWeighted

`public boolean isWeighted()`
Returns true if and only if this edge is weighted.
Returns:
true if and only if this edge is weighted
• getWeight

```public double getWeight()
throws IllegalArgumentException```
Returns the weight of this edge.
Returns:
the weight of this edge
Throws:
`IllegalArgumentException` - if this method is called in case of an unweighted edge
• toString

`public String toString()`
Returns the label of this edge, or the weight if the edge is weighted.
Overrides:
`toString` in class `Object`
Returns:
the label of this edge or the weight if the edge is weighted