@ Override public List < ? extends Tree > getAncestors ( ) { if ( getParent ( ) == null ) return null ; List < Tree > ancestors = new ArrayList < Tree > ( ) ; Tree t = this ; t = t . getParent ( ) ; while ( t != null ) { ancestors . add ( 0 , t ) ; // insert at start t = t . getParent ( ) ; } return ancestors ; }
Return a list of all ancestors of this node . The first node of list is the root and the last is the parent of this node .