N
- Node parameter typeE
- Edge parameter type@Beta public abstract class AbstractNetwork<N,E> extends Object implements Network<N,E>
Network
. It is recommended to extend
this class rather than implement Network
directly.
The methods implemented in this class should not be overridden unless the subclass admits a more efficient implementation.
Constructor and Description |
---|
AbstractNetwork() |
Modifier and Type | Method and Description |
---|---|
Set<E> |
adjacentEdges(E edge)
Returns the edges which have an
incident node in common with
edge . |
Graph<N> |
asGraph()
Returns a live view of this network as a
Graph . |
int |
degree(N node)
Returns the count of
node 's incident edges , counting
self-loops twice (equivalently, the number of times an edge touches node ). |
Optional<E> |
edgeConnecting(N nodeU,
N nodeV)
Returns the single edge directly connecting
nodeU to nodeV , if one is present,
or Optional.empty() if no such edge exists. |
E |
edgeConnectingOrNull(N nodeU,
N nodeV)
Returns the single edge directly connecting
nodeU to nodeV , if one is present,
or null if no such edge exists. |
Set<E> |
edgesConnecting(N nodeU,
N nodeV)
Returns the set of edges directly connecting
nodeU to nodeV . |
boolean |
equals(Object obj)
Indicates whether some other object is "equal to" this one.
|
boolean |
hasEdgeConnecting(N nodeU,
N nodeV)
Returns true if there is an edge directly connecting
nodeU to nodeV . |
int |
hashCode()
Returns a hash code value for the object.
|
int |
inDegree(N node)
Returns the count of
node 's incoming edges in a directed
network. |
int |
outDegree(N node)
Returns the count of
node 's outgoing edges in a directed
network. |
String |
toString()
Returns a string representation of this network.
|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
adjacentNodes, allowsParallelEdges, allowsSelfLoops, edgeOrder, edges, incidentEdges, incidentNodes, inEdges, isDirected, nodeOrder, nodes, outEdges, predecessors, successors
public AbstractNetwork()
public Graph<N> asGraph()
Network
Graph
. The resulting Graph
will have
an edge connecting node A to node B if this Network
has an edge connecting A to B.
If this network allows parallel edges
, parallel edges will be
treated as if collapsed into a single edge. For example, the Network.degree(Object)
of a node
in the Graph
view may be less than the degree of the same node in this Network
.
public int degree(N node)
Network
node
's incident edges
, counting
self-loops twice (equivalently, the number of times an edge touches node
).
For directed networks, this is equal to inDegree(node) + outDegree(node)
.
For undirected networks, this is equal to incidentEdges(node).size()
+ (number of
self-loops incident to node
).
If the count is greater than Integer.MAX_VALUE
, returns Integer.MAX_VALUE
.
public int inDegree(N node)
Network
node
's incoming edges
in a directed
network. In an undirected network, returns the Network.degree(Object)
.
If the count is greater than Integer.MAX_VALUE
, returns Integer.MAX_VALUE
.
public int outDegree(N node)
Network
node
's outgoing edges
in a directed
network. In an undirected network, returns the Network.degree(Object)
.
If the count is greater than Integer.MAX_VALUE
, returns Integer.MAX_VALUE
.
public Set<E> adjacentEdges(E edge)
Network
incident node
in common with
edge
. An edge is not considered adjacent to itself.adjacentEdges
in interface Network<N,E>
public Set<E> edgesConnecting(N nodeU, N nodeV)
Network
nodeU
to nodeV
.
In an undirected network, this is equal to edgesConnecting(nodeV, nodeU)
.
The resulting set of edges will be parallel (i.e. have equal Network.incidentNodes(Object)
.
If this network does not allow parallel edges
, the resulting set
will contain at most one edge (equivalent to edgeConnecting(nodeU, nodeV).asSet()
).
edgesConnecting
in interface Network<N,E>
public Optional<E> edgeConnecting(N nodeU, N nodeV)
Network
nodeU
to nodeV
, if one is present,
or Optional.empty()
if no such edge exists.
In an undirected network, this is equal to edgeConnecting(nodeV, nodeU)
.
edgeConnecting
in interface Network<N,E>
@NullableDecl public E edgeConnectingOrNull(N nodeU, N nodeV)
Network
nodeU
to nodeV
, if one is present,
or null
if no such edge exists.
In an undirected network, this is equal to edgeConnectingOrNull(nodeV, nodeU)
.
edgeConnectingOrNull
in interface Network<N,E>
public boolean hasEdgeConnecting(N nodeU, N nodeV)
Network
nodeU
to nodeV
. This is
equivalent to nodes().contains(nodeU) && successors(nodeU).contains(nodeV)
, and to
edgeConnectingOrNull(nodeU, nodeV) != null
.
In an undirected graph, this is equal to hasEdgeConnecting(nodeV, nodeU)
.
hasEdgeConnecting
in interface Network<N,E>
public final boolean equals(@NullableDecl Object obj)
java.lang.Object
The equals
method implements an equivalence relation
on non-null object references:
x
, x.equals(x)
should return
true
.
x
and y
, x.equals(y)
should return true
if and only if
y.equals(x)
returns true
.
x
, y
, and z
, if
x.equals(y)
returns true
and
y.equals(z)
returns true
, then
x.equals(z)
should return true
.
x
and y
, multiple invocations of
x.equals(y)
consistently return true
or consistently return false
, provided no
information used in equals
comparisons on the
objects is modified.
x
,
x.equals(null)
should return false
.
The equals
method for class Object
implements
the most discriminating possible equivalence relation on objects;
that is, for any non-null reference values x
and
y
, this method returns true
if and only
if x
and y
refer to the same object
(x == y
has the value true
).
Note that it is generally necessary to override the hashCode
method whenever this method is overridden, so as to maintain the
general contract for the hashCode
method, which states
that equal objects must have equal hash codes.
public final int hashCode()
java.lang.Object
HashMap
.
The general contract of hashCode
is:
hashCode
method
must consistently return the same integer, provided no information
used in equals
comparisons on the object is modified.
This integer need not remain consistent from one execution of an
application to another execution of the same application.
equals(Object)
method, then calling the hashCode
method on each of
the two objects must produce the same integer result.
Object.equals(java.lang.Object)
method, then calling the hashCode
method on each of the
two objects must produce distinct integer results. However, the
programmer should be aware that producing distinct integer results
for unequal objects may improve the performance of hash tables.
As much as is reasonably practical, the hashCode method defined by
class Object
does return distinct integers for distinct
objects. (This is typically implemented by converting the internal
address of the object into an integer, but this implementation
technique is not required by the
Java™ programming language.)
hashCode
in interface Network<N,E>
hashCode
in class Object
Object.equals(java.lang.Object)
,
System.identityHashCode(java.lang.Object)
Copyright © 2010–2018. All rights reserved.