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 java.lang.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
    • 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>
      • edgesConnecting

        public java.util.Set<EedgesConnecting​(N nodeU,
                                                N nodeV)
        Description copied from interface: Network
        Returns 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()).

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

        public java.util.Set<EedgesConnecting​(EndpointPair<N> endpoints)
        Description copied from interface: Network
        Returns 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.

        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 graph 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 graph, 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
                                    java.lang.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 java.lang.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 java.lang.Object
      • toString

        public java.lang.String toString()
        Returns a string representation of this network.
        Overrides:
        toString in class java.lang.Object