docs: public final void build(GraphIterator<ST, PT> iterator, SubGraphBuildListener<ST, PT> listener) {
  		assert iterator != null;
  		final Set<ComparableWeakReference<PT>> reachedPoints = new TreeSet<>();
  		GraphIterationElement<ST, PT> element;
  		ST segment;
  		PT point;
  		PT firstPoint = null;
  
  		this.parentGraph = new WeakReference<>(iterator.getGraph());
  		this.segments.clear();
  		this.pointNumber = 0;
  		this.terminalPoints.clear();
  
  		while (iterator.hasNext()) {
  			element = iterator.nextElement();
  			point = element.getPoint();
  			segment = element.getSegment();
  
  			// First reached segment
  			if (this.segments.isEmpty()) {
  				firstPoint = point;
  			}
  
  			this.segments.add(segment);
  			if (listener != null) {
  				listener.segmentAdded(this, element);
  			}
  
  			// Register terminal points
  			point = segment.getOtherSidePoint(point);
  			final ComparableWeakReference<PT> ref = new ComparableWeakReference<>(point);
  			if (element.isTerminalSegment()) {
  				if (!reachedPoints.contains(ref)) {
  					this.terminalPoints.add(ref);
  					if (listener != null) {
  						listener.terminalPointReached(this, point, segment);
  					}
  				}
  			} else {
  				this.terminalPoints.remove(ref);
  				reachedPoints.add(ref);
  				if (listener != null) {
  					listener.nonTerminalPointReached(this, point, segment);
  				}
  			}
  		}
  
  		if (firstPoint != null) {
  			final ComparableWeakReference<PT> ref = new ComparableWeakReference<>(firstPoint);
  			if (!reachedPoints.contains(ref)) {
  				this.terminalPoints.add(ref);
  			}
  		}
  
  		this.pointNumber = this.terminalPoints.size() + reachedPoints.size();
  
  		reachedPoints.clear();
  	}