Package com.google.common.graph
Class ElementOrder<T>
- java.lang.Object
-
- com.google.common.graph.ElementOrder<T>
-
public final class ElementOrder<T> extends java.lang.Object
Used to represent the order of elements in a data structure that supports different options for iteration order guarantees.Example usage:
MutableGraph<Integer> graph = GraphBuilder.directed().nodeOrder(ElementOrder.<Integer>natural()).build();
- Since:
- 20.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ElementOrder.Type
The type of ordering that this object specifies.
-
Field Summary
Fields Modifier and Type Field Description private java.util.Comparator<T>
comparator
private ElementOrder.Type
type
-
Constructor Summary
Constructors Modifier Constructor Description private
ElementOrder(ElementOrder.Type type, java.util.Comparator<T> comparator)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) <T1 extends T>
ElementOrder<T1>cast()
java.util.Comparator<T>
comparator()
Returns theComparator
used.(package private) <K extends T,V>
java.util.Map<K,V>createMap(int expectedSize)
Returns an empty mutable map whose keys will respect thisElementOrder
.boolean
equals(java.lang.Object obj)
int
hashCode()
static <S> ElementOrder<S>
insertion()
Returns an instance which specifies that insertion ordering is guaranteed.static <S extends java.lang.Comparable<? super S>>
ElementOrder<S>natural()
Returns an instance which specifies that the natural ordering of the elements is guaranteed.static <S> ElementOrder<S>
sorted(java.util.Comparator<S> comparator)
Returns an instance which specifies that the ordering of the elements is guaranteed to be determined bycomparator
.static <S> ElementOrder<S>
stable()
Returns an instance which specifies that ordering is guaranteed to be always be the same across iterations, and across releases.java.lang.String
toString()
ElementOrder.Type
type()
Returns the type of ordering used.static <S> ElementOrder<S>
unordered()
Returns an instance which specifies that no ordering is guaranteed.
-
-
-
Field Detail
-
type
private final ElementOrder.Type type
-
comparator
private final java.util.Comparator<T> comparator
-
-
Constructor Detail
-
ElementOrder
private ElementOrder(ElementOrder.Type type, java.util.Comparator<T> comparator)
-
-
Method Detail
-
unordered
public static <S> ElementOrder<S> unordered()
Returns an instance which specifies that no ordering is guaranteed.
-
stable
public static <S> ElementOrder<S> stable()
Returns an instance which specifies that ordering is guaranteed to be always be the same across iterations, and across releases. Some methods may have stronger guarantees.This instance is only useful in combination with
incidentEdgeOrder
, e.g.graphBuilder.incidentEdgeOrder(ElementOrder.stable())
.In combination with
incidentEdgeOrder
incidentEdgeOrder(ElementOrder.stable())
guarantees the ordering of the returned collections of the following methods:- For
Graph
andValueGraph
:edges()
: Stable orderadjacentNodes(node)
: Connecting edge insertion orderpredecessors(node)
: Connecting edge insertion ordersuccessors(node)
: Connecting edge insertion orderincidentEdges(node)
: Edge insertion order
- For
Network
:adjacentNodes(node)
: Stable orderpredecessors(node)
: Connecting edge insertion ordersuccessors(node)
: Connecting edge insertion orderincidentEdges(node)
: Stable orderinEdges(node)
: Edge insertion orderoutEdges(node)
: Edge insertion orderadjacentEdges(edge)
: Stable orderedgesConnecting(nodeU, nodeV)
: Edge insertion order
- Since:
- 29.0
- For
-
insertion
public static <S> ElementOrder<S> insertion()
Returns an instance which specifies that insertion ordering is guaranteed.
-
natural
public static <S extends java.lang.Comparable<? super S>> ElementOrder<S> natural()
Returns an instance which specifies that the natural ordering of the elements is guaranteed.
-
sorted
public static <S> ElementOrder<S> sorted(java.util.Comparator<S> comparator)
Returns an instance which specifies that the ordering of the elements is guaranteed to be determined bycomparator
.
-
type
public ElementOrder.Type type()
Returns the type of ordering used.
-
comparator
public java.util.Comparator<T> comparator()
Returns theComparator
used.- Throws:
java.lang.UnsupportedOperationException
- if comparator is not defined
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
createMap
<K extends T,V> java.util.Map<K,V> createMap(int expectedSize)
Returns an empty mutable map whose keys will respect thisElementOrder
.
-
cast
<T1 extends T> ElementOrder<T1> cast()
-
-