public void write ( Tree < ? , ? > tree ) throws IOException { this . writer . append ( "digraph G" ) ; //$NON-NLS-1$ this . writer . append ( Integer . toString ( this . graphIndex ++ ) ) ; this . writer . append ( " {\n" ) ; //$NON-NLS-1$ if ( tree != null ) { // Write the node attributes Iterator < ? extends TreeNode < ? , ? > > iterator = tree . broadFirstIterator ( ) ; TreeNode < ? , ? > node ; int dataCount ; while ( iterator . hasNext ( ) ) { node = iterator . next ( ) ; dataCount = node . getUserDataCount ( ) ; final String name = "NODE" + Integer . toHexString ( System . identityHashCode ( node ) ) ; //$NON-NLS-1$ final String label = Integer . toString ( dataCount ) ; this . writer . append ( "\t" ) ; //$NON-NLS-1$ this . writer . append ( name ) ; this . writer . append ( " [label=\"" ) ; //$NON-NLS-1$ this . writer . append ( label ) ; this . writer . append ( "\"]\n" ) ; //$NON-NLS-1$ } this . writer . append ( "\n" ) ; //$NON-NLS-1$ // Write the node links iterator = tree . broadFirstIterator ( ) ; Class < ? extends Enum < ? > > partitionType ; TreeNode < ? , ? > child ; String childName ; while ( iterator . hasNext ( ) ) { node = iterator . next ( ) ; final String name = "NODE" + Integer . toHexString ( System . identityHashCode ( node ) ) ; //$NON-NLS-1$ if ( ! node . isLeaf ( ) ) { partitionType = node . getPartitionEnumeration ( ) ; final int childCount = node . getChildCount ( ) ; for ( int i = 0 ; i < childCount ; ++ i ) { child = node . getChildAt ( i ) ; if ( child != null ) { childName = "NODE" + Integer . toHexString ( System . identityHashCode ( child ) ) ; //$NON-NLS-1$ final String label ; if ( partitionType != null ) { label = partitionType . getEnumConstants ( ) [ i ] . name ( ) ; } else { label = Integer . toString ( i ) ; } this . writer . append ( "\t" ) ; //$NON-NLS-1$ this . writer . append ( name ) ; this . writer . append ( "->" ) ; //$NON-NLS-1$ this . writer . append ( childName ) ; this . writer . append ( " [label=\"" ) ; //$NON-NLS-1$ this . writer . append ( label ) ; this . writer . append ( "\"]\n" ) ; //$NON-NLS-1$ } } } } } this . writer . append ( "}\n\n" ) ; //$NON-NLS-1$ }
Write the given tree inside the . dot output stream .