public final static MonomerNotationGroup replaceMonomerNotationGroup ( MonomerNotationGroup monomerNotation , String existingMonomerID , String newMonomerID ) throws NotationException { MonomerNotationGroup newObject = null ; boolean hasChanged = false ; StringBuilder sb = new StringBuilder ( ) ; String id = "" ; for ( MonomerNotationGroupElement object : monomerNotation . getListOfElements ( ) ) { if ( object . getMonomerNotation ( ) . getUnit ( ) . equals ( existingMonomerID ) ) { hasChanged = true ; id = generateGroupElement ( newMonomerID , object . getValue ( ) ) ; } else { id = generateGroupElement ( object . getMonomerNotation ( ) . getUnit ( ) , object . getValue ( ) ) ; } if ( monomerNotation instanceof MonomerNotationGroupOr ) { sb . append ( id + "," ) ; } else { sb . append ( id + "+" ) ; } } if ( hasChanged ) { sb . setLength ( sb . length ( ) - 1 ) ; if ( monomerNotation instanceof MonomerNotationGroupOr ) { newObject = new MonomerNotationGroupOr ( sb . toString ( ) , monomerNotation . getType ( ) ) ; } else { newObject = new MonomerNotationGroupMixture ( sb . toString ( ) , monomerNotation . getType ( ) ) ; } } return newObject ; }
method to replace the MonomerNotationGroup having the MonomerID with the new MonomerID