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
    • Constructor Summary

      Constructors 
      Constructor Description
      AbstractNetwork()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.util.Set<E> adjacentEdges​(E edge)
      Returns a live view of 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).
      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.
      protected <T> java.util.Set<T> edgeInvalidatableSet​(java.util.Set<T> set, E edge)
      Returns a Set whose methods throw IllegalStateException when the given edge is not present in this network.
      java.util.Set<E> edgesConnecting​(EndpointPair<N> endpoints)
      Returns a live view of 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 a live view of 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)  
      protected <T> java.util.Set<T> nodeInvalidatableSet​(java.util.Set<T> set, N node)
      Returns a Set whose methods throw IllegalStateException when the given node is not present in this network.
      protected <T> java.util.Set<T> nodePairInvalidatableSet​(java.util.Set<T> set, N nodeU, N nodeV)
      Returns a Set whose methods throw IllegalStateException when either of the given nodes is not present in this network.
      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.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • 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 java.util.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 java.util.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 java.util.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>
      • edgeConnecting

        public java.util.Optional<EedgeConnecting​(N nodeU,
                                                    N nodeV)
        Description copied from interface: Network
        Returns the single edge that directly connects 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).

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

        public java.util.Optional<EedgeConnecting​(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 Optional.empty() if no such edge exists.

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

        Specified by:
        edgeConnecting 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
                                    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
      • edgeInvalidatableSet

        protected final <T> java.util.Set<T> edgeInvalidatableSet​(java.util.Set<T> set,
                                                                  E edge)
        Returns a Set whose methods throw IllegalStateException when the given edge is not present in this network.
        Since:
        33.1.0
      • nodeInvalidatableSet

        protected final <T> java.util.Set<T> nodeInvalidatableSet​(java.util.Set<T> set,
                                                                  N node)
        Returns a Set whose methods throw IllegalStateException when the given node is not present in this network.
        Since:
        33.1.0
      • nodePairInvalidatableSet

        protected final <T> java.util.Set<T> nodePairInvalidatableSet​(java.util.Set<T> set,
                                                                      N nodeU,
                                                                      N nodeV)
        Returns a Set whose methods throw IllegalStateException when either of the given nodes is not present in this network.
        Since:
        33.1.0