private String getSphereCode ( List < TreeNode > sphereNodes ) throws CDKException { if ( sphereNodes == null || sphereNodes . size ( ) < 1 ) { return sphereDelimiters [ sphere - 1 ] ; } TreeNode treeNode = null ; StringBuffer code = new StringBuffer ( ) ; /* * append the tree node code to the HOSECode in their now determined * order, using commas to separate nodes from different branches */ IAtom branch = sphereNodes . get ( 0 ) . source . atom ; StringBuffer tempCode = null ; for ( int i = 0 ; i < sphereNodes . size ( ) ; i ++ ) { treeNode = sphereNodes . get ( i ) ; tempCode = new StringBuffer ( ) ; if ( ! treeNode . source . stopper && ! treeNode . source . atom . equals ( branch ) ) { branch = treeNode . source . atom ; code . append ( ' ' ) ; } if ( ! treeNode . source . stopper && treeNode . source . atom . equals ( branch ) ) { if ( treeNode . bondType <= 4 ) { tempCode . append ( bondSymbols [ ( int ) treeNode . bondType ] ) ; } else { throw new CDKException ( "Unknown bond type" ) ; } if ( treeNode . atom != null && ! treeNode . atom . getFlag ( CDKConstants . VISITED ) ) { tempCode . append ( getElementSymbol ( treeNode . symbol ) ) ; } else if ( treeNode . atom != null && treeNode . atom . getFlag ( CDKConstants . VISITED ) ) { tempCode . append ( ' ' ) ; treeNode . stopper = true ; } code . append ( tempCode + createChargeCode ( treeNode . atom ) ) ; treeNode . hSymbol = tempCode . toString ( ) ; } if ( treeNode . atom != null ) treeNode . atom . setFlag ( CDKConstants . VISITED , true ) ; if ( treeNode . source . stopper ) treeNode . stopper = true ; } code . append ( sphereDelimiters [ sphere - 1 ] ) ; return code . toString ( ) ; }
Generates the string code for a given sphere .