private static List < Integer > getOccurencesOfMonomerNotation ( String sourceUnit , HELMEntity e , HELM2Notation helm2notation ) throws org . helm . notation2 . parser . exceptionparser . NotationException , AttachmentException { List < Integer > occurences = new ArrayList < Integer > ( ) ; /* The monomer's position in the polymer is specified */ try { occurences . add ( Integer . parseInt ( sourceUnit ) ) ; return occurences ; } catch ( NumberFormatException ex ) { MonomerNotation mon = ValidationMethod . decideWhichMonomerNotation ( sourceUnit , e . getType ( ) ) ; /* it is only one monomer e.g. C */ if ( mon instanceof MonomerNotationUnit ) { PolymerNotation polymerNotation = helm2notation . getPolymerNotation ( e . getId ( ) ) ; /* monomer can also be unknown */ if ( sourceUnit . equals ( "?" ) ) { return occurences ; } occurences . addAll ( findElementInPolymer ( sourceUnit , polymerNotation ) ) ; /* the specified monomer does not exist in the polymer */ if ( occurences . isEmpty ( ) ) { throw new AttachmentException ( "Monomer is not there" ) ; } } /* second: group (mixture or or) or list */ else if ( mon instanceof MonomerNotationGroup || mon instanceof MonomerNotationList ) { PolymerNotation polymerNotation = helm2notation . getPolymerNotation ( e . getId ( ) ) ; Map < String , String > elements = new HashMap < String , String > ( ) ; for ( MonomerNotationGroupElement groupElement : ( ( MonomerNotationGroup ) mon ) . getListOfElements ( ) ) { elements . put ( groupElement . getMonomerNotation ( ) . getUnit ( ) , "" ) ; } for ( String e1 : elements . keySet ( ) ) { try { int i = Integer . parseInt ( e1 ) ; elements . put ( e1 , "1" ) ; occurences . add ( i ) ; } catch ( NumberFormatException ex1 ) { // have to be found in polymer List < Integer > foundMonomers = findElementInPolymer ( e1 , polymerNotation ) ; if ( foundMonomers . size ( ) > 0 ) { elements . put ( e1 , "1" ) ; occurences . addAll ( foundMonomers ) ; } } } if ( occurences . size ( ) < elements . size ( ) || elements . containsValue ( "" ) ) { throw new AttachmentException ( "Not all Monomers are there" ) ; } } return occurences ; } }
method to get all occurences of the MonomerNotation