Class DirectedGraphConnections<N,​V>

  • Type Parameters:
    N - Node parameter type
    V - Value parameter type
    All Implemented Interfaces:
    GraphConnections<N,​V>

    final class DirectedGraphConnections<N,​V>
    extends java.lang.Object
    implements GraphConnections<N,​V>
    An implementation of GraphConnections for directed graphs.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      private static class  DirectedGraphConnections.PredAndSucc
      A wrapper class to indicate a node is both a predecessor and successor while still providing the successor value.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private DirectedGraphConnections​(java.util.Map<N,​java.lang.Object> adjacentNodeValues, int predecessorCount, int successorCount)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addPredecessor​(N node, V unused)
      Add node as a predecessor to the origin node.
      V addSuccessor​(N node, V value)
      Add node as a successor to the origin node.
      java.util.Set<N> adjacentNodes()  
      private static boolean isPredecessor​(java.lang.Object value)  
      private static boolean isSuccessor​(java.lang.Object value)  
      (package private) static <N,​V>
      DirectedGraphConnections<N,​V>
      of()  
      (package private) static <N,​V>
      DirectedGraphConnections<N,​V>
      ofImmutable​(java.util.Set<N> predecessors, java.util.Map<N,​V> successorValues)  
      java.util.Set<N> predecessors()  
      void removePredecessor​(java.lang.Object node)
      Remove node from the set of predecessors.
      V removeSuccessor​(java.lang.Object node)
      Remove node from the set of successors.
      java.util.Set<N> successors()  
      V value​(java.lang.Object node)
      Returns the value associated with the edge connecting the origin node to node, or null if there is no such edge.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • PRED

        private static final java.lang.Object PRED
      • adjacentNodeValues

        private final java.util.Map<N,​java.lang.Object> adjacentNodeValues
      • predecessorCount

        private int predecessorCount
      • successorCount

        private int successorCount
    • Constructor Detail

      • DirectedGraphConnections

        private DirectedGraphConnections​(java.util.Map<N,​java.lang.Object> adjacentNodeValues,
                                         int predecessorCount,
                                         int successorCount)
    • Method Detail

      • ofImmutable

        static <N,​V> DirectedGraphConnections<N,​V> ofImmutable​(java.util.Set<N> predecessors,
                                                                           java.util.Map<N,​V> successorValues)
      • value

        public V value​(java.lang.Object node)
        Description copied from interface: GraphConnections
        Returns the value associated with the edge connecting the origin node to node, or null if there is no such edge.
        Specified by:
        value in interface GraphConnections<N,​V>
      • removeSuccessor

        public V removeSuccessor​(java.lang.Object node)
        Description copied from interface: GraphConnections
        Remove node from the set of successors. Returns the value previously associated with the edge connecting the two nodes.
        Specified by:
        removeSuccessor in interface GraphConnections<N,​V>
      • addPredecessor

        public void addPredecessor​(N node,
                                   V unused)
        Description copied from interface: GraphConnections
        Add node as a predecessor to the origin node. In the case of an undirected graph, it also becomes a successor. Associates value with the edge connecting the two nodes.
        Specified by:
        addPredecessor in interface GraphConnections<N,​V>
      • addSuccessor

        public V addSuccessor​(N node,
                              V value)
        Description copied from interface: GraphConnections
        Add node as a successor to the origin node. In the case of an undirected graph, it also becomes a predecessor. Associates value with the edge connecting the two nodes. Returns the value previously associated with the edge connecting the two nodes.
        Specified by:
        addSuccessor in interface GraphConnections<N,​V>
      • isPredecessor

        private static boolean isPredecessor​(@Nullable
                                             java.lang.Object value)
      • isSuccessor

        private static boolean isSuccessor​(@Nullable
                                           java.lang.Object value)