Class GraphImpl<T extends Node<T>>

  • Type Parameters:
    T - The type of a Node in the graph, which must extend Node.
    All Implemented Interfaces:
    java.lang.Iterable<T>, java.util.Collection<T>, java.util.Set<T>, Graph<T>

    public class GraphImpl<T extends Node<T>>
    extends java.util.AbstractSet<T>
    implements Graph<T>
    Implementation of a simple graph.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      (package private) static interface  GraphImpl.NodeVisitor<T extends Node>  
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.Map<T,​NodeData> nodeToData  
    • Constructor Summary

      Constructors 
      Constructor Description
      GraphImpl()  
      GraphImpl​(java.util.Collection<T> coll)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean add​(T obj)  
      private void clearNodeData()  
      private java.util.Set<T> collectRootSet()  
      NodeData getNodeData​(T node)  
      java.util.Set<T> getRoots()  
      java.util.Iterator<T> iterator()  
      private void markNonRoots()  
      int size()  
      (package private) void visitAll​(GraphImpl.NodeVisitor<T> nv)  
      • Methods inherited from class java.util.AbstractSet

        equals, hashCode, removeAll
      • Methods inherited from class java.util.AbstractCollection

        addAll, clear, contains, containsAll, isEmpty, remove, retainAll, toArray, toArray, toString
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.util.Collection

        parallelStream, removeIf, stream, toArray
      • Methods inherited from interface java.lang.Iterable

        forEach
      • Methods inherited from interface java.util.Set

        addAll, clear, contains, containsAll, equals, hashCode, isEmpty, remove, removeAll, retainAll, spliterator, toArray, toArray
    • Field Detail

      • nodeToData

        private java.util.Map<T extends Node<T>,​NodeData> nodeToData
    • Constructor Detail

      • GraphImpl

        public GraphImpl()
      • GraphImpl

        public GraphImpl​(java.util.Collection<T> coll)
    • Method Detail

      • add

        public boolean add​(T obj)
        Specified by:
        add in interface java.util.Collection<T extends Node<T>>
        Specified by:
        add in interface java.util.Set<T extends Node<T>>
        Overrides:
        add in class java.util.AbstractCollection<T extends Node<T>>
      • iterator

        public java.util.Iterator<T> iterator()
        Specified by:
        iterator in interface java.util.Collection<T extends Node<T>>
        Specified by:
        iterator in interface java.lang.Iterable<T extends Node<T>>
        Specified by:
        iterator in interface java.util.Set<T extends Node<T>>
        Specified by:
        iterator in class java.util.AbstractCollection<T extends Node<T>>
      • size

        public int size()
        Specified by:
        size in interface java.util.Collection<T extends Node<T>>
        Specified by:
        size in interface java.util.Set<T extends Node<T>>
        Specified by:
        size in class java.util.AbstractCollection<T extends Node<T>>
      • clearNodeData

        private void clearNodeData()
      • markNonRoots

        private void markNonRoots()
      • collectRootSet

        private java.util.Set<T> collectRootSet()
      • getRoots

        public java.util.Set<T> getRoots()
        Specified by:
        getRoots in interface Graph<T extends Node<T>>