5454
5555import java .io .BufferedReader ;
5656import java .io .IOException ;
57+ import java .io .Reader ;
5758import java .util .ArrayList ;
5859import java .util .HashMap ;
5960import java .util .LinkedHashMap ;
@@ -143,19 +144,20 @@ private String parse(BufferedReader bufferedReader) {
143144 // Get an ordered list of key->value pairs in array-tuples
144145 do {
145146 section = this .readSection (bufferedReader );
146- sectionKey = section .get (0 )[0 ];
147+ String [] s0 = section .get (0 );
148+ sectionKey = s0 [0 ];
147149 if (sectionKey == null ) {
148150 //if we reach the end of the file, section contains empty strings
149- if (section . get ( 0 ) [1 ]==null || section . get ( 0 ) [1 ].equals ("" ) ||
150- section . get ( 0 ) [1 ].length ()==0 ) {
151+ if (s0 [1 ]==null || s0 [1 ].equals ("" ) ||
152+ s0 [1 ].length ()==0 ) {
151153 throw new ParserException (Messages .ENDOFFILE );
152154 }
153155 throw new ParserException (Messages .SECTIONKEYNULL );
154156 }
155157 // process section-by-section
156158 switch (sectionKey ) {
157159 case LOCUS_TAG : {
158- String loc = section . get ( 0 ) [1 ];
160+ String loc = s0 [1 ];
159161 header = loc ;
160162 Matcher m = lp .matcher (loc );
161163 if (m .matches ()) {
@@ -169,7 +171,7 @@ private String parse(BufferedReader bufferedReader) {
169171 compoundType = AminoAcidCompoundSet .aminoAcidCompoundSet ;
170172 } else if (lengthUnits .equalsIgnoreCase ("bp" )) {
171173 if (type != null ) {
172- if (type .contains ("RNA" )) {
174+ if (type .contains ("RNA" )) { //HACK
173175 compoundType = RNACompoundSet .getRNACompoundSet ();
174176 } else {
175177 compoundType = DNACompoundSet .getDNACompoundSet ();
@@ -179,25 +181,25 @@ private String parse(BufferedReader bufferedReader) {
179181 }
180182 }
181183
182- log .debug ("compound type: {}" , compoundType .getClass ().getSimpleName ());
184+ // log.debug("compound type: {}", compoundType.getClass().getSimpleName());
183185
184186 } else {
185187 throw new ParserException ("Bad locus line" );
186188 }
187189 break ;
188190 }
189191 case DEFINITION_TAG :
190- headerParser .setDescription (section . get ( 0 ) [1 ]);
192+ headerParser .setDescription (s0 [1 ]);
191193 break ;
192194 case ACCESSION_TAG :
193195 // if multiple accessions, store only first as accession,
194196 // and store rest in annotation
195- String [] accs = section . get ( 0 ) [1 ].split ("\\ s+" );
197+ String [] accs = s0 [1 ].split ("\\ s+" );
196198 accession = accs [0 ].trim ();
197199 headerParser .setAccession (accession );
198200 break ;
199201 case VERSION_TAG : {
200- String ver = section . get ( 0 ) [1 ];
202+ String ver = s0 [1 ];
201203 Matcher m = vp .matcher (ver );
202204 if (m .matches ()) {
203205 String verAcc = m .group (1 );
@@ -244,15 +246,16 @@ private String parse(BufferedReader bufferedReader) {
244246 break ;
245247 case COMMENT_TAG :
246248 // Set up some comments
247- headerParser .setComment (section . get ( 0 ) [1 ]);
249+ headerParser .setComment (s0 [1 ]);
248250 break ;
249251 case FEATURE_TAG :
250252 // starting from second line of input, start a new feature whenever we come across
251253 // a key that does not start with /
252254 AbstractFeature gbFeature = null ;
253255 for (int i = 1 ; i < section .size (); i ++) {
254- String key = section .get (i )[0 ];
255- String val = section .get (i )[1 ];
256+ String [] si = section .get (i );
257+ String key = si [0 ];
258+ String val = si [1 ];
256259 if (key .startsWith ("/" )) {
257260 if (gbFeature == null ) {
258261 throw new ParserException ("Malformed GenBank file: found a qualifier without feature." );
@@ -271,7 +274,7 @@ private String parse(BufferedReader bufferedReader) {
271274 DBReferenceInfo xref = new DBReferenceInfo (dbname , raccession );
272275 gbFeature .addQualifier (key , xref );
273276
274- ArrayList <DBReferenceInfo > listDBEntry = new ArrayList <>();
277+ ArrayList <DBReferenceInfo > listDBEntry = new ArrayList <>(1 );
275278 listDBEntry .add (xref );
276279 mapDB .put (key , listDBEntry );
277280 } else {
@@ -284,24 +287,17 @@ private String parse(BufferedReader bufferedReader) {
284287 if (key .equalsIgnoreCase ("translation" )) {
285288 // strip spaces from sequence
286289 val = val .replaceAll ("\\ s+" , "" );
287- Qualifier q = new Qualifier (key , val );
288- gbFeature .addQualifier (key , q );
290+ gbFeature .addQualifier (key , new Qualifier (key , val ));
289291 } else {
290- Qualifier q = new Qualifier (key , val );
291- gbFeature .addQualifier (key , q );
292+ gbFeature .addQualifier (key , new Qualifier (key , val ));
292293 }
293294 }
294295 } else {
295296 // new feature!
296297 gbFeature = new TextFeature (key , val , key , key );
297- Location l =
298- locationParser .parse (val );
299- gbFeature .setLocation ((AbstractLocation ) l );
298+ gbFeature .setLocation ((AbstractLocation ) locationParser .parse (val ));
300299
301- if (!featureCollection .containsKey (key )) {
302- featureCollection .put (key , new ArrayList ());
303- }
304- featureCollection .get (key ).add (gbFeature );
300+ featureCollection .computeIfAbsent (key , (x )->new ArrayList <>(1 )).add (gbFeature );
305301 }
306302 }
307303 break ;
@@ -363,8 +359,7 @@ private List<String[]> readSection(BufferedReader bufferedReader) {
363359 // having only white space characters
364360 continue ;
365361 }
366- if (line == null
367- || (!line .startsWith (" " ) && linecount ++ > 0 && (!firstSecKey
362+ if (line == null || (!line .startsWith (" " ) && linecount ++ > 0 && (!firstSecKey
368363 .equals (START_SEQUENCE_TAG ) || line
369364 .startsWith (END_SEQUENCE_TAG )))) {
370365 // dump out last part of section
@@ -417,7 +412,7 @@ public String getSequence(BufferedReader bufferedReader, int sequenceLength) {
417412 try {
418413 parse (bufferedReader );
419414 } catch (ParserException e ) {
420- if (e .getMessage ().equalsIgnoreCase (Messages .ENDOFFILE )) return null ;
415+ if (e .getMessage ().equalsIgnoreCase (Messages .ENDOFFILE )) return null ;
421416 else throw new ParserException (e .getMessage ());
422417 }
423418
0 commit comments