From f2fedb42f84eb7ad8ac32f98174123cc0e54d733 Mon Sep 17 00:00:00 2001 From: langella <langella@b8ef2a07-7df7-436f-90b9-41648038564b> Date: Thu, 24 May 2012 16:01:12 +0000 Subject: [PATCH] performance problem fixed using hashmap git-svn-id: https://subversion.renater.fr/xtandempipeline/trunk@295 b8ef2a07-7df7-436f-90b9-41648038564b --- .../grouping/HashPeptideSet.java | 18 ++++++--------- .../grouping/HashProteinSet.java | 23 ++++++++----------- .../grouping/HashSampleScanSet.java | 17 ++++++-------- 3 files changed, 24 insertions(+), 34 deletions(-) diff --git a/xtandempipeline/src/fr/inra/pappso/xtandempipeline/grouping/HashPeptideSet.java b/xtandempipeline/src/fr/inra/pappso/xtandempipeline/grouping/HashPeptideSet.java index cea6378af..adede18de 100644 --- a/xtandempipeline/src/fr/inra/pappso/xtandempipeline/grouping/HashPeptideSet.java +++ b/xtandempipeline/src/fr/inra/pappso/xtandempipeline/grouping/HashPeptideSet.java @@ -15,6 +15,9 @@ public class HashPeptideSet extends HashKey4GroupsSet { */ private static final Logger logger = Logger.getLogger(HashPeptideSet.class); + private HashMap<HashPeptide, HashPeptide> mapHashPeptide = new HashMap<HashPeptide, HashPeptide>( + 0); + public HashPeptideSet() { // logger.debug("HashPeptideSet begin"); } @@ -32,20 +35,13 @@ public class HashPeptideSet extends HashKey4GroupsSet { HashPeptide temp = new HashPeptide(sampleScan, sequence); if (this.add(temp)) { - //this HashPeptide is new + // this HashPeptide is new + this.mapHashPeptide.put(temp, temp); return (temp); - } - else { + } else { // find the existing instance of the same peptide scan : - for (HashKey4Groups toCompare:this) { - HashPeptide hashPeptideToCompare = (HashPeptide) toCompare; - if (temp.equals(hashPeptideToCompare)) { - return hashPeptideToCompare; - } - } + return this.mapHashPeptide.get(temp); } - logger.error("ERROR this might not appear"); - return temp; } } diff --git a/xtandempipeline/src/fr/inra/pappso/xtandempipeline/grouping/HashProteinSet.java b/xtandempipeline/src/fr/inra/pappso/xtandempipeline/grouping/HashProteinSet.java index dabf87b07..182d2e77b 100644 --- a/xtandempipeline/src/fr/inra/pappso/xtandempipeline/grouping/HashProteinSet.java +++ b/xtandempipeline/src/fr/inra/pappso/xtandempipeline/grouping/HashProteinSet.java @@ -1,5 +1,7 @@ package fr.inra.pappso.xtandempipeline.grouping; +import java.util.HashMap; + import org.apache.log4j.Logger; public class HashProteinSet extends HashKey4GroupsSet { @@ -14,28 +16,23 @@ public class HashProteinSet extends HashKey4GroupsSet { */ private static final Logger logger = Logger.getLogger(HashProteinSet.class); + private HashMap<HashProtein, HashProtein> mapHashProtein = new HashMap<HashProtein, HashProtein>( + 0); + public HashProteinSet() { // logger.debug("HashPeptideSet begin"); } public HashProtein getInstance(String accession) { HashProtein temp = new HashProtein(accession); - if (this.add(temp)) { - //this HashProtein is new + // this HashProtein is new + this.mapHashProtein.put(temp, temp); return (temp); + } else { + // find the existing instance of the same protein : + return this.mapHashProtein.get(temp); } - else { - // find the existing instance of the same sample scan : - for (HashKey4Groups toCompare:this) { - HashProtein hashProtToCompare = (HashProtein) toCompare; - if (temp.equals(hashProtToCompare)) { - return hashProtToCompare; - } - } - } - logger.error("ERROR this might not appear"); - return temp; } @Override diff --git a/xtandempipeline/src/fr/inra/pappso/xtandempipeline/grouping/HashSampleScanSet.java b/xtandempipeline/src/fr/inra/pappso/xtandempipeline/grouping/HashSampleScanSet.java index a7abc9769..76bd0bb86 100644 --- a/xtandempipeline/src/fr/inra/pappso/xtandempipeline/grouping/HashSampleScanSet.java +++ b/xtandempipeline/src/fr/inra/pappso/xtandempipeline/grouping/HashSampleScanSet.java @@ -2,6 +2,7 @@ package fr.inra.pappso.xtandempipeline.grouping; import java.util.ArrayList; import java.util.Collections; +import java.util.HashMap; import java.util.HashSet; import org.apache.log4j.Logger; @@ -16,6 +17,8 @@ public class HashSampleScanSet extends HashSet<HashSampleScan> implements private static final long serialVersionUID = -9055338154900110371L; private static final Logger logger = Logger .getLogger(HashSampleScanSet.class); + private HashMap<HashSampleScan, HashSampleScan> mapHashSampleScan = new HashMap<HashSampleScan, HashSampleScan>( + 0); public HashSampleScanSet() { } @@ -31,19 +34,13 @@ public class HashSampleScanSet extends HashSet<HashSampleScan> implements HashSampleScan temp = new HashSampleScan(scan, msRun); if (this.add(temp)) { - //this hashSampleScan is new + // this HashSampleScan is new + this.mapHashSampleScan.put(temp, temp); return (temp); - } - else { + } else { // find the existing instance of the same sample scan : - for (HashSampleScan toCompare:this) { - if (temp.equals(toCompare)) { - return toCompare; - } - } + return this.mapHashSampleScan.get(temp); } - logger.error("ERROR this might not appear"); - return temp; } public void loggerDebug() { -- GitLab