Class AbstractNetwork<N,​E>

  • Type Parameters:
    N - Node parameter type
    E - Edge parameter type
    All Implemented Interfaces:
    Network<N,​E>, PredecessorsFunction<N>, SuccessorsFunction<N>
    Direct Known Subclasses:
    ImmutableNetwork

    @Beta
    public abstract class AbstractNetwork<N,​E>
    extends Object
    implements Network<N,​E>
    This class provides a skeletal implementation of 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.

    Since:
    20.0
    Author:
    James Sexton
    • Constructor Detail

      • AbstractNetwork

        public AbstractNetwork()
        Constructor for use by subclasses.
    • Method Detail

      • degree

        public int degree​(N node)
        Description copied from interface: Network
        Returns the count of 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.

        Specified by:
        degree in interface Network<N,​E>
      • inDegree

        public int inDegree​(N node)
        Description copied from interface: Network
        Returns the count of 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.

        Specified by:
        inDegree in interface Network<N,​E>
      • adjacentEdges

        public Set<EadjacentEdges​(E edge)
        Description copied from interface: Network
        Returns a live view of the edges which have an incident node in common with edge. An edge is not considered adjacent to itself.

        If edge is removed from the network after this method is called, the Set view returned by this method will be invalidated, and will throw IllegalStateException if it is accessed in any way, with the following exceptions:

        • view.equals(view) evaluates to true (but any other equals() expression involving view will throw)
        • hashCode() does not throw
        • if edge is re-added to the network after having been removed, view's behavior is undefined
        Specified by:
        adjacentEdges in interface Network<N,​E>
      • edgesConnecting

        public Set<EedgesConnecting​(N nodeU,
                                      N nodeV)
        Description copied from interface: Network
        Returns a live view of the set of edges that each directly connect 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()).

        If either nodeU or nodeV are removed from the network after this method is called, the Set view returned by this method will be invalidated, and will throw IllegalStateException if it is accessed in any way, with the following exceptions:

        • view.equals(view) evaluates to true (but any other equals() expression involving view will throw)
        • hashCode() does not throw
        • if nodeU or nodeV are re-added to the network after having been removed, view's behavior is undefined
        Specified by:
        edgesConnecting in interface Network<N,​E>
      • edgesConnecting

        public Set<EedgesConnecting​(EndpointPair<N> endpoints)
        Description copied from interface: Network
        Returns a live view of the set of edges that each directly connect endpoints (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.

        If either element of endpoints is removed from the network after this method is called, the Set view returned by this method will be invalidated, and will throw IllegalStateException if it is accessed in any way, with the following exceptions:

        • view.equals(view) evaluates to true (but any other equals() expression involving view will throw)
        • hashCode() does not throw
        • if either endpoint is re-added to the network after having been removed, view's behavior is undefined
        Specified by:
        edgesConnecting in interface Network<N,​E>
      • edgeConnectingOrNull

        @CheckForNull
        public E edgeConnectingOrNull​(N nodeU,
                                      N nodeV)
        Description copied from interface: Network
        Returns the single edge that directly connects 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).

        Specified by:
        edgeConnectingOrNull in interface Network<N,​E>
      • edgeConnectingOrNull

        @CheckForNull
        public E edgeConnectingOrNull​(EndpointPair<N> endpoints)
        Description copied from interface: Network
        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.

        If this network is directed, the endpoints must be ordered.

        Specified by:
        edgeConnectingOrNull in interface Network<N,​E>
      • hasEdgeConnecting

        public boolean hasEdgeConnecting​(N nodeU,
                                         N nodeV)
        Description copied from interface: Network
        Returns true if there is an edge that directly connects nodeU to nodeV. This is equivalent to nodes().contains(nodeU) && successors(nodeU).contains(nodeV), and to edgeConnectingOrNull(nodeU, nodeV) != null.

        In an undirected network, this is equal to hasEdgeConnecting(nodeV, nodeU).

        Specified by:
        hasEdgeConnecting in interface Network<N,​E>
      • validateEndpoints

        protected final void validateEndpoints​(EndpointPair<?> endpoints)
        Throws an IllegalArgumentException if the ordering of endpoints is not compatible with the directionality of this graph.
      • equals

        public final boolean equals​(@CheckForNull
                                    Object obj)
        Description copied from interface: Network
        Returns true 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:

        • A and B have equal directedness.
        • A and B have equal node sets.
        • A and B have equal edge sets.
        • Every edge in A and B connects the same nodes in the same direction (if any).

        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).

        Specified by:
        equals in interface Network<N,​E>
        Overrides:
        equals in class Object
      • hashCode

        public final int hashCode()
        Description copied from interface: Network
        Returns the hash code for this network. The hash code of a network is defined as the hash code of a map from each of its edges to their incident nodes.

        A reference implementation of this is provided by hashCode().

        Specified by:
        hashCode in interface Network<N,​E>
        Overrides:
        hashCode in class Object