package common.graph;

import java.util.Collection;
import java.util.List;
import java.util.function.Function;
import java.util.stream.Stream;

/**
 * <p>A graph whose connection data is stored in adjacency list form, each vertex keeping track of
 * with which other vertices it shares an edge.</p>
 * @author fiveham
 * @author fiveham
 *
 * @param <T>
 * @param <T>@param <T>
 */
public interface Graph<T extends Vertex<T>> extends Iterable<T>{
	
    /**
     * <p>Returns the number of vertices in this Graph.</p>
     * @return the number of vertices in this Graph
     */
	public int size();
	
    /**
     * <p>Returns a stream based on the underlying collection of nodes.</p>
     * @return a stream backed by this Graph's underlying collection of nodes
     */
	public Stream<T> nodeStream();
	
  /**
   * <p>Returns a collection of all the connected components of this Graph.</p>
   * @param seedSrc a function that selects an element from a list of nodes in this Graph from
   * which to begin building a given connected component
   * @return a collection of all the connected components of this Graph
   */
	public Collection<Graph<T>> connectedComponents(Function<List<T>, T> seedSrc);
	
	/**
   * <p>Returns a collection of all the connected components of this Graph. This is a convenience
   * method supplying default arguments to {@link #connectedComponents(List, Function)}.</p>
   * @return a collection of all the connected components of this Graph
   */
	public default Collection<Graph<T>> connectedComponents(){
	  return connectedComponents(Graph::stdSeed);
	}
	
	/**
	 * <p>Removes and returns the last element of {@code list}.</p>
	 * <p>This is the default seed source in {@link #connectedComponents()}.</p>
	 * @param list a modifiable list from which elements can be removed and which has at least one 
	 * element
	 * @return the last element that {@code list} had when it was sent to this method
	 * @throws IndexOutOfBoundsException if {@code list} is empty
	 */
	static <T> T stdSeed(List<T> list){
	  return list.remove(list.size() - 1);
	}
}

@@ -62,19 +62,45 @@
 va.util.
-Lis
+Iterator;%0Aimport java.util.Se
 t;%0Aimpor
@@ -948,14 +948,26 @@
 hat 
-select
+removes and return
 s an
@@ -982,19 +982,18 @@
  from a 
-li
 s
+e
 t of nod
@@ -999,83 +999,37 @@
 des 
+belong
 in
+g
  t
-his Graph from
+o 
 %0A   * 
-which to begin building a given connected component
+this Graph
 %0A   
@@ -1161,19 +1161,18 @@
 unction%3C
-Lis
+Se
 t%3CT%3E, T%3E
@@ -1358,19 +1358,18 @@
 ponents(
-Lis
+Se
 t, Funct
@@ -1601,24 +1601,19 @@
 returns 
-the last
+one
  element
@@ -1623,19 +1623,18 @@
  %7B@code 
-li
 s
+e
 t%7D.%3C/p%3E%0A
@@ -1672,18 +1672,23 @@
  source 
-in
+used by
  %7B@link 
@@ -1727,19 +1727,18 @@
  @param 
-li
 s
+e
 t a modi
@@ -1744,19 +1744,18 @@
 ifiable 
-li
 s
+e
 t from w
@@ -1922,58 +1922,222 @@
 ows 
-IndexOutOfBoundsException if %7B@code list%7D is empty
+NoSuchElementException if %7B@code set%7D is empty%0A%09 * @throws UnsupportedOperationException if %7B@code set%7D's %7B@link Set#iterator() iterator%7D does not %0A%09 * support the optional %7B@link Iterator#remove() remove()%7D method
 %0A%09 *
@@ -2164,61 +2164,111 @@
 eed(
-Lis
+Se
 t%3CT%3E 
-li
 s
+e
 t)%7B%0A%09  
-return list.remove(list.size() - 1)
+Iterator%3CT%3E i = set.iterator();%0A%09  T result = i.next();%0A%09  i.remove();%0A%09  return result
 ;%0A%09%7D

change type for unassigned node pool to Set from List