Skip to content

Commit a39bd7d

Browse files
committed
refactored code to use java 8 streams
1 parent afd98d4 commit a39bd7d

File tree

3 files changed

+11
-12
lines changed

3 files changed

+11
-12
lines changed

biojava-aa-prop/src/main/java/org/biojava/nbio/aaproperties/CommandPrompt.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -327,9 +327,7 @@ private static void compute(PrintStream output, String header, String sequence,
327327
}
328328
}
329329
output.print(header.replace(delimiter, "_"));
330-
for(int i = 0; i < dList.size(); i++){
331-
output.print(delimiter + Utils.roundToDecimals(dList.get(i), decimalPlace));
332-
}
330+
dList.forEach(item -> System.out.print(delimiter + Utils.roundToDecimals(dList.get(item), decimalPlace)));
333331
output.println();
334332
output.flush();
335333
}

biojava-aa-prop/src/main/java/org/biojava/nbio/aaproperties/PeptideProperties.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,12 @@
3131
import javax.xml.bind.JAXBException;
3232
import java.io.File;
3333
import java.io.FileNotFoundException;
34+
import java.util.Arrays;
3435
import java.util.HashMap;
3536
import java.util.HashSet;
3637
import java.util.Map;
3738
import java.util.Set;
39+
import java.util.stream.Collectors;
3840

3941
/**
4042
* This is an adaptor class which enable the ease of generating protein properties.
@@ -64,8 +66,9 @@ public enum SingleLetterAACode { W, C, M, H, Y, F, Q, N, I, R, D, P, T, K, E, V,
6466
* To initialize the standardAASet
6567
*/
6668
static{
67-
standardAASet = new HashSet<Character>();
68-
for(SingleLetterAACode c:SingleLetterAACode.values()) standardAASet.add(c.toString().charAt(0));
69+
standardAASet = Arrays.stream(SingleLetterAACode.values())
70+
.map(singleLetterAACode -> singleLetterAACode.toString().charAt(0))
71+
. .collect(Collectors.toCollection(HashSet::new));
6972
}
7073

7174
/**

biojava-core/src/main/java/org/biojava/nbio/core/sequence/template/AbstractNucleotideCompoundSet.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.biojava.nbio.core.sequence.compound.NucleotideCompound;
2424

2525
import java.util.*;
26+
import java.util.stream.Collectors;
2627

2728
/**
2829
*
@@ -66,13 +67,10 @@ protected void addNucleotideCompound(String base, String complement, String... e
6667
protected void calculateIndirectAmbiguities() {
6768
Map<NucleotideCompound, List<NucleotideCompound>> equivalentsMap = new HashMap<NucleotideCompound, List<NucleotideCompound>>();
6869

69-
List<NucleotideCompound> ambiguousCompounds = new ArrayList<NucleotideCompound>();
70-
for(NucleotideCompound compound: getAllCompounds()) {
71-
if (!compound.isAmbiguous()) {
72-
continue;
73-
}
74-
ambiguousCompounds.add(compound);
75-
}
70+
List<NucleotideCompound> ambiguousCompounds = getAllCompounds().stream()
71+
.filter(compound -> compound.isAmbiguous())
72+
.collect(Collectors.toCollection(ArrayList::new));
73+
7674

7775
for(NucleotideCompound sourceCompound: ambiguousCompounds) {
7876
Set<NucleotideCompound> compoundConstituents = sourceCompound.getConstituents();

0 commit comments

Comments
 (0)