- java.lang.Object
-
- org.jgrapht.alg.util.VertexDegreeComparator<V,E>
-
- Type Parameters:
V
- the graph vertex typeE
- the graph edge type
- All Implemented Interfaces:
Comparator<V>
public class VertexDegreeComparator<V,E> extends Object implements Comparator<V>
Compares two vertices based on their degree.Used by greedy algorithms that need to sort vertices by their degree. Two vertices are considered equal if their degrees are equal.
- Author:
- Linda Buisman
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
VertexDegreeComparator.Order
Deprecated, for removal: This API element is subject to removal in a future version.useof(Graph)
-
Constructor Summary
Constructors Constructor Description VertexDegreeComparator(Graph<V,E> g)
Deprecated, for removal: This API element is subject to removal in a future version.useof(Graph)
VertexDegreeComparator(Graph<V,E> g, VertexDegreeComparator.Order order)
Deprecated, for removal: This API element is subject to removal in a future version.useof(Graph)
for ascending order orreverse the comparator
for descending order.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description int
compare(V v1, V v2)
Deprecated, for removal: This API element is subject to removal in a future version.useof(Graph)
static <V> Comparator<V>
of(Graph<V,?> g)
Returns aComparator
that compares vertices by their degrees in the specified graph.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.util.Comparator
equals, reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
-
-
-
-
Constructor Detail
-
VertexDegreeComparator
@Deprecated(forRemoval=true, since="1.5.1") public VertexDegreeComparator(Graph<V,E> g)
Deprecated, for removal: This API element is subject to removal in a future version.useof(Graph)
Creates a comparator for comparing the degrees of vertices in the specified graph. The comparator compares in ascending order of degrees (lowest first).- Parameters:
g
- graph with respect to which the degree is calculated.
-
VertexDegreeComparator
@Deprecated(forRemoval=true, since="1.5.1") public VertexDegreeComparator(Graph<V,E> g, VertexDegreeComparator.Order order)
Deprecated, for removal: This API element is subject to removal in a future version.useof(Graph)
for ascending order orreverse the comparator
for descending order.Creates a comparator for comparing the degrees of vertices in the specified graph.- Parameters:
g
- graph with respect to which the degree is calculated.order
- order in which the vertices are sorted (ascending or descending)
-
-
Method Detail
-
of
public static <V> Comparator<V> of(Graph<V,?> g)
Returns aComparator
that compares vertices by their degrees in the specified graph.The comparator compares in ascending order of degrees (lower degree first). To obtain a comparator that compares in descending order call
Comparator.reversed()
on the returned comparator.- Type Parameters:
V
- the graph vertex type- Parameters:
g
- graph with respect to which the degree is calculated.- Returns:
- a
Comparator
to compare vertices by their degree in ascending order
-
compare
@Deprecated(forRemoval=true, since="1.5.1") public int compare(V v1, V v2)
Deprecated, for removal: This API element is subject to removal in a future version.useof(Graph)
Compare the degrees ofv1
andv2
, taking into account whether ascending or descending order is used.- Specified by:
compare
in interfaceComparator<V>
- Parameters:
v1
- the first vertex to be compared.v2
- the second vertex to be compared.- Returns:
- -1 if
v1
comes beforev2
, +1 ifv1
comes afterv2
, 0 if equal.
-
-