src/main/java/com/mxgraph/layout/hierarchical/mxHierarchicalLayout.java
public List<Object> findRoots(Object parent, Set<Object> vertices)
	{
		List<Object> roots = new ArrayList<Object>();

		Object best = null;
		int maxDiff = -100000;
		mxIGraphModel model = graph.getModel();

		for (Object vertex : vertices)
		{
			if (model.isVertex(vertex) && graph.isCellVisible(vertex))
			{
				Object[] conns = this.getEdges(vertex);
				int fanOut = 0;
				int fanIn = 0;

				for (int k = 0; k < conns.length; k++)
				{
					Object src = graph.getView().getVisibleTerminal(conns[k],
							true);

					if (src == vertex)
					{
						fanOut++;
					}
					else
					{
						fanIn++;
					}
				}

				if (fanIn == 0 && fanOut > 0)
				{
					roots.add(vertex);
				}

				int diff = fanOut - fanIn;

				if (diff > maxDiff)
				{
					maxDiff = diff;
					best = vertex;
				}
			}
		}

		if (roots.isEmpty() && best != null)
		{
			roots.add(best);
		}

		return roots;
	}
/**
	 * Returns all visible children in the given parent which do not have
	 * incoming edges. If the result is empty then the children with the
	 * maximum difference between incoming and outgoing edges are returned.
	 * This takes into account edges that are being promoted to the given
	 * root due to invisible children or collapsed cells.
	 * 
	 * @param parent Cell whose children should be checked.
	 * @return List of tree roots in parent.
	 */
Returns all visible children in the given parent which do not have
incoming edges. If the result is empty then the children with the
maximum difference between incoming and outgoing edges are returned.
This takes into account edges that are being promoted to the given
root due to invisible children or collapsed cells.

@param parent Cell whose children should be checked.
@return List of tree roots in parent.
Returns all visible children in the given parent which do not have incoming edges . If the result is empty then the children with the maximum difference between incoming and outgoing edges are returned . This takes into account edges that are being promoted to the given root due to invisible children or collapsed cells . @param parent Cell whose children should be checked . @return List of tree roots in parent .
public List<Object> findRoots(Object parent, Set<Object> vertices)
	{
		List<Object> roots = new ArrayList<Object>();
		Object best = null;
		int maxDiff = -100000;
		mxIGraphModel model = graph.getModel();
		for (Object vertex : vertices)
		{
			if (model.isVertex(vertex) && graph.isCellVisible(vertex))
			{
				Object[] conns = this.getEdges(vertex);
				int fanOut = 0;
				int fanIn = 0;
				for (int k = 0; k < conns.length; k++)
				{
					Object src = graph.getView().getVisibleTerminal(conns[k],
							true);
					if (src == vertex)
					{
						fanOut++;
					}
					else
					{
						fanIn++;
					}
				}
				if (fanIn == 0 && fanOut > 0)
				{
					roots.add(vertex);
				}
				int diff = fanOut - fanIn;
				if (diff > maxDiff)
				{
					maxDiff = diff;
					best = vertex;
				}
			}
		}
		if (roots.isEmpty() && best != null)
		{
			roots.add(best);
		}
		return roots;
	}
public List < Object > findRoots ( Object parent , Set < Object > vertices ) { List < Object > roots = new ArrayList < Object > ( ) ; Object best = null ; int maxDiff = - 100000 ; mxIGraphModel model = graph . getModel ( ) ; for ( Object vertex : vertices ) { if ( model . isVertex ( vertex ) && graph . isCellVisible ( vertex ) ) { Object [ ] conns = this . getEdges ( vertex ) ; int fanOut = 0 ; int fanIn = 0 ; for ( int k = 0 ; k < conns . length ; k ++ ) { Object src = graph . getView ( ) . getVisibleTerminal ( conns [ k ] , true ) ; if ( src == vertex ) { fanOut ++ ; } else { fanIn ++ ; } } if ( fanIn == 0 && fanOut > 0 ) { roots . add ( vertex ) ; } int diff = fanOut - fanIn ; if ( diff > maxDiff ) { maxDiff = diff ; best = vertex ; } } } if ( roots . isEmpty ( ) && best != null ) { roots . add ( best ) ; } return roots ; }
Returns all visible children in the given parent which do not have
 incoming edges.
Returns all visible children in the given parent which do not have incoming edges .