Class DynamicGraph.Edges<T>

  • Enclosing class:
    DynamicGraph<T>

    private static class DynamicGraph.Edges<T>
    extends java.lang.Object
    Manage edges and weights between nodes.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.Map<T,​java.util.Map<T,​java.lang.Integer>> m_incomingEdges  
      private java.util.Map<T,​java.util.Map<T,​java.lang.Integer>> m_outgoingEdges  
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private Edges()  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addEdge​(int weight, T from, T to, boolean ignoreCycles)  
      private static <T> void addEdgeToMap​(java.util.Map<T,​java.util.Map<T,​java.lang.Integer>> map, T n1, T n2, int weight)  
      (package private) void appendDotEdges​(java.lang.StringBuilder sb, java.util.Set<T> finished)  
      private java.lang.Integer findReversedEdge​(T from, T to)
      Return the weight of the edge in the graph that is the reversed direction of edge.
      (package private) java.util.Map<T,​java.lang.Integer> from​(T node)  
      (package private) java.util.Set<T> fromNodes()  
      (package private) java.util.Map<T,​java.util.Map<T,​java.lang.Integer>> getEdges()
      Allow raw access to the edges, but protect inside unmodifiableMaps.
      (package private) int getLowestEdgeWeight​(java.util.Set<T> nodes)  
      (package private) boolean hasAllEdgesWithWeight​(T node, int level)  
      private static <T> void removeEdgesFromMap​(java.util.Map<T,​java.util.Map<T,​java.lang.Integer>> map, java.util.Collection<T> nodes, T node)
      Remove edges from a map given a node and a list of destination nodes.
      (package private) void removeNode​(T node)
      Remove a node from the graph and all associated edges.
      (package private) java.util.Map<T,​java.lang.Integer> to​(T node)  
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

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

      • m_incomingEdges

        private final java.util.Map<T,​java.util.Map<T,​java.lang.Integer>> m_incomingEdges
      • m_outgoingEdges

        private final java.util.Map<T,​java.util.Map<T,​java.lang.Integer>> m_outgoingEdges
    • Constructor Detail

      • Edges

        private Edges()
    • Method Detail

      • addEdge

        public void addEdge​(int weight,
                            T from,
                            T to,
                            boolean ignoreCycles)
      • fromNodes

        java.util.Set<T> fromNodes()
        Returns:
        the set of nodes that have outgoing edges.
      • from

        java.util.Map<T,​java.lang.Integer> from​(T node)
      • to

        java.util.Map<T,​java.lang.Integer> to​(T node)
      • findReversedEdge

        private java.lang.Integer findReversedEdge​(T from,
                                                   T to)
        Return the weight of the edge in the graph that is the reversed direction of edge. For example, if edge a -> b exists, and edge b -> a is passed in, then return a -> b.
        Parameters:
        from - - the from edge
        to - - the to edge
        Returns:
        the weight of the reversed edge or null if edge does not exist
      • removeNode

        void removeNode​(T node)
        Remove a node from the graph and all associated edges. Each edge needs to be removed from both maps to keep the maps in sync.
        Parameters:
        node - Node to remove.
      • getLowestEdgeWeight

        int getLowestEdgeWeight​(java.util.Set<T> nodes)
      • hasAllEdgesWithWeight

        boolean hasAllEdgesWithWeight​(T node,
                                      int level)
      • removeEdgesFromMap

        private static <T> void removeEdgesFromMap​(java.util.Map<T,​java.util.Map<T,​java.lang.Integer>> map,
                                                   java.util.Collection<T> nodes,
                                                   T node)
        Remove edges from a map given a node and a list of destination nodes. Given:
        
         m_outgoingEdges:
            a -> b
                 c
                 d
         m_incomingEdges:
            b -> a
            c -> a
            d -> a
        
         
        Then, calling this method to remove node c on both maps as done in removeNode(), would result in a -> c and c -> a edges being removed.
      • addEdgeToMap

        private static <T> void addEdgeToMap​(java.util.Map<T,​java.util.Map<T,​java.lang.Integer>> map,
                                             T n1,
                                             T n2,
                                             int weight)
      • getEdges

        java.util.Map<T,​java.util.Map<T,​java.lang.Integer>> getEdges()
        Allow raw access to the edges, but protect inside unmodifiableMaps. This is for tests, toString and toDot.
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • appendDotEdges

        void appendDotEdges​(java.lang.StringBuilder sb,
                            java.util.Set<T> finished)