N - Node parameter typeE - Edge parameter typepublic abstract class AbstractNetwork<N,E> extends java.lang.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 |
|---|---|
java.util.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. |
private Predicate<E> |
connectedPredicate(N nodePresent,
N nodeToCheck) |
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). |
java.util.Optional<E> |
edgeConnecting(EndpointPair<N> endpoints)
Returns the single edge that directly connects
endpoints (in the order, if any,
specified by endpoints), if one is present, or Optional.empty() if no such edge
exists. |
java.util.Optional<E> |
edgeConnecting(N nodeU,
N nodeV)
Returns the single edge that directly connects
nodeU to nodeV, if one is
present, or Optional.empty() if no such edge exists. |
E |
edgeConnectingOrNull(EndpointPair<N> endpoints)
Returns the single edge that directly connects
endpoints (in the order, if any,
specified by endpoints), if one is present, or null if no such edge exists. |
E |
edgeConnectingOrNull(N nodeU,
N nodeV)
Returns the single edge that directly connects
nodeU to nodeV, if one is
present, or null if no such edge exists. |
private static <N,E> java.util.Map<E,EndpointPair<N>> |
edgeIncidentNodesMap(Network<N,E> network) |
java.util.Set<E> |
edgesConnecting(EndpointPair<N> endpoints)
Returns the set of edges that each directly connect
endpoints (in the order, if any,
specified by endpoints). |
java.util.Set<E> |
edgesConnecting(N nodeU,
N nodeV)
Returns the set of edges that each directly connect
nodeU to nodeV. |
boolean |
equals(java.lang.Object obj)
Returns
true iff object is a Network that has the same elements and the
same structural relationships as those in this network. |
boolean |
hasEdgeConnecting(EndpointPair<N> endpoints)
Returns true if there is an edge that directly connects
endpoints (in the order, if
any, specified by endpoints). |
boolean |
hasEdgeConnecting(N nodeU,
N nodeV)
Returns true if there is an edge that directly connects
nodeU to nodeV. |
int |
hashCode()
Returns the hash code for this network.
|
int |
inDegree(N node)
Returns the count of
node's incoming edges in a directed
network. |
protected boolean |
isOrderingCompatible(EndpointPair<?> endpoints) |
int |
outDegree(N node)
Returns the count of
node's outgoing edges in a directed
network. |
java.lang.String |
toString()
Returns a string representation of this network.
|
protected void |
validateEndpoints(EndpointPair<?> endpoints)
Throws an IllegalArgumentException if the ordering of
endpoints is not compatible with
the directionality of this graph. |
clone, finalize, getClass, notify, notifyAll, wait, wait, waitadjacentNodes, allowsParallelEdges, allowsSelfLoops, edgeOrder, edges, incidentEdges, incidentNodes, inEdges, isDirected, nodeOrder, nodes, outEdges, predecessors, successorspublic Graph<N> asGraph()
NetworkGraph. 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)
Networknode'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)
Networknode'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)
Networknode'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 java.util.Set<E> adjacentEdges(E edge)
Networkincident node in common with
edge. An edge is not considered adjacent to itself.adjacentEdges in interface Network<N,E>public java.util.Set<E> edgesConnecting(N nodeU, N nodeV)
NetworknodeU 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 java.util.Set<E> edgesConnecting(EndpointPair<N> endpoints)
Networkendpoints (in the order, if any,
specified by endpoints).
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(endpoints).asSet()).
If this network is directed, endpoints must be ordered.
edgesConnecting in interface Network<N,E>public java.util.Optional<E> edgeConnecting(N nodeU, N nodeV)
NetworknodeU 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>public java.util.Optional<E> edgeConnecting(EndpointPair<N> endpoints)
Networkendpoints (in the order, if any,
specified by endpoints), if one is present, or Optional.empty() if no such edge
exists.
If this graph is directed, the endpoints must be ordered.
edgeConnecting in interface Network<N,E>@CheckForNull public E edgeConnectingOrNull(N nodeU, N nodeV)
NetworknodeU 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>@CheckForNull public E edgeConnectingOrNull(EndpointPair<N> endpoints)
Networkendpoints (in the order, if any,
specified by endpoints), if one is present, or null if no such edge exists.
If this graph is directed, the endpoints must be ordered.
edgeConnectingOrNull in interface Network<N,E>public boolean hasEdgeConnecting(N nodeU, N nodeV)
NetworknodeU 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 boolean hasEdgeConnecting(EndpointPair<N> endpoints)
Networkendpoints (in the order, if
any, specified by endpoints).
Unlike the other EndpointPair-accepting methods, this method does not throw if the
endpoints are unordered and the graph is directed; it simply returns false. This is for
consistency with Graph.hasEdgeConnecting(EndpointPair) and ValueGraph.hasEdgeConnecting(EndpointPair).
hasEdgeConnecting in interface Network<N,E>protected final void validateEndpoints(EndpointPair<?> endpoints)
endpoints is not compatible with
the directionality of this graph.protected final boolean isOrderingCompatible(EndpointPair<?> endpoints)
public final boolean equals(@CheckForNull
java.lang.Object obj)
Networktrue iff object is a Network that has the same elements and the
same structural relationships as those in this network.
Thus, two networks A and B are equal if all of the following are true:
directedness.
node sets.
edge sets.
Network properties besides directedness do not affect equality.
For example, two networks may be considered equal even if one allows parallel edges and the
other doesn't. Additionally, the order in which nodes or edges are added to the network, and
the order in which they are iterated over, are irrelevant.
A reference implementation of this is provided by equals(Object).
public final int hashCode()
Networkedges to their incident nodes.
A reference implementation of this is provided by hashCode().
public java.lang.String toString()
toString in class java.lang.Objectprivate static <N,E> java.util.Map<E,EndpointPair<N>> edgeIncidentNodesMap(Network<N,E> network)