Package com.gengoai.graph
Class Edge<V>
- java.lang.Object
-
- com.gengoai.graph.Edge<V>
-
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
DirectedEdge
,UndirectedEdge
public abstract class Edge<V> extends Object implements Serializable
Defines an edge in a graph, which minimally is made up of two vertices (source and target in directed edges).
- Author:
- David B. Bracewell
- See Also:
- Serialized Form
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static <V> DirectedEdge<V>
directedEdge(V from, V to)
Creates a new directed edgestatic <V> DirectedEdge<V>
directedEdge(V from, V to, double weight)
Creates a new directed edgeV
getFirstVertex()
V
getOppositeVertex(V vertex)
Gets the vertex opposite of the one givenV
getSecondVertex()
double
getWeight()
abstract boolean
isDirected()
boolean
isWeighted()
void
setWeight(double weight)
Sets the weight of the edgestatic <V> UndirectedEdge<V>
undirectedEdge(V from, V to)
Creates a new undirected edgestatic <V> UndirectedEdge<V>
undirectedEdge(V from, V to, double weight)
Creates a new undirected edge
-
-
-
Method Detail
-
directedEdge
public static <V> DirectedEdge<V> directedEdge(V from, V to)
Creates a new directed edge- Type Parameters:
V
- The vertex type- Parameters:
from
- The from vertexto
- The to vertex- Returns:
- The created edge
-
directedEdge
public static <V> DirectedEdge<V> directedEdge(V from, V to, double weight)
Creates a new directed edge- Type Parameters:
V
- The vertex type- Parameters:
from
- The from vertexto
- The to vertexweight
- The edge weight- Returns:
- The created edge
-
undirectedEdge
public static <V> UndirectedEdge<V> undirectedEdge(V from, V to)
Creates a new undirected edge- Type Parameters:
V
- The vertex type- Parameters:
from
- The from vertexto
- The to vertex- Returns:
- The created edge
-
undirectedEdge
public static <V> UndirectedEdge<V> undirectedEdge(V from, V to, double weight)
Creates a new undirected edge- Type Parameters:
V
- The vertex type- Parameters:
from
- The from vertexto
- The to vertexweight
- The edge weight- Returns:
- The created edge
-
getFirstVertex
public V getFirstVertex()
- Returns:
- The first (from) vertex
-
getOppositeVertex
public V getOppositeVertex(V vertex)
Gets the vertex opposite of the one given- Parameters:
vertex
- The vertex whose opposite we want- Returns:
- The other vertex in the edge
-
getSecondVertex
public V getSecondVertex()
- Returns:
- The second (to) vertex
-
getWeight
public double getWeight()
- Returns:
- The weight of the edge or 1 if none
-
isDirected
public abstract boolean isDirected()
- Returns:
- True if the edge is directed, False if not
-
isWeighted
public boolean isWeighted()
- Returns:
- True if the edge has a weight, false otherwise
-
setWeight
public void setWeight(double weight)
Sets the weight of the edge- Parameters:
weight
- the weight
-
-