/*
 * Copyright 2009, 2010 Lari Natri <lari.natri@gmail.com>
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 * 
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 * 
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package compid.data;


import compid.data.tuples.*;
import net.aavalla.utils.general.RetrievalHashSet;

/**
 *
 * @author Lari Natri
 */
public class FullDataset {
    
    private RetrievalHashSet<Protein> proteins = null;
    private RetrievalHashSet<ProteinHit> proteinHits = null;
    private RetrievalHashSet<Peptide> peptides = null;
    private RetrievalHashSet<PeptideHit> peptideHits = null;
    private RetrievalHashSet<ProtHitPeptHitJoin> protHitPeptHitJoins = null;
    private RetrievalHashSet<Query> queries = null;
    private RetrievalHashSet<DatasetInfo> dataSetInfos = null;
    private RetrievalHashSet<ProtSeq> protSequences = null;
    private RetrievalHashSet<ProtDbInfo> protDbs = null;
    
    public FullDataset() {
        this.proteins = new RetrievalHashSet<Protein>(128);
        this.proteinHits = new RetrievalHashSet<ProteinHit>(128);
        this.peptides = new RetrievalHashSet<Peptide>(256);
        this.peptideHits = new RetrievalHashSet<PeptideHit>(512);
        this.protHitPeptHitJoins = new RetrievalHashSet<ProtHitPeptHitJoin>(512);
        this.queries = new RetrievalHashSet<Query>(512);
        this.dataSetInfos = new RetrievalHashSet<DatasetInfo>(1,1);
        this.protSequences = new RetrievalHashSet<ProtSeq>();
        this.protDbs = new RetrievalHashSet<ProtDbInfo>(2);
        
    }

    
    public RetrievalHashSet<Protein> getProteins() { return this.proteins; }
    
    public RetrievalHashSet<ProteinHit> getProteinHits() { return this.proteinHits; }
    
    public RetrievalHashSet<Peptide> getPeptides() { return this.peptides; }
    
    public RetrievalHashSet<PeptideHit> getPeptideHits() { return this.peptideHits; }
    
    public RetrievalHashSet<ProtHitPeptHitJoin> getProtHitPeptHitJoins() {
        return this.protHitPeptHitJoins;
    }

    public RetrievalHashSet<DatasetInfo> getDataSetInfos() {
        return this.dataSetInfos;
    }
    
    public RetrievalHashSet<ProtSeq> getProtSequences() {
        return this.protSequences;
    }
    
    public RetrievalHashSet<ProtDbInfo> getProtDatabases() {
        return this.protDbs;
    }
    
    public RetrievalHashSet<Query> getQueries() { return this.queries; }
    
    public boolean addDataSetInfo(DatasetInfo dsInfo) {
        return dataSetInfos.add(dsInfo);
    }
    
    public boolean addProtein(Protein prot) {
        ProtSeq seq = prot.getProtSeq();
        if (!this.addProteinSequence(seq)) {
            prot.setProtSeq((ProtSeq)this.protSequences.getKey(seq));
        }
        ProtDbInfo pdb = prot.getProtDbInfo();
        if (!this.addProteinDB(pdb)) {
            prot.setProtDb((ProtDbInfo)this.protDbs.getKey(pdb));
        }        
        return proteins.add(prot);
    }
    
    public boolean addProteinHit(ProteinHit protHit) {
        Protein prot = protHit.getProtein();
        if (!this.addProtein(prot)) {
            protHit.setProtein((Protein)proteins.getKey(prot));
        }
        DatasetInfo dataset = protHit.getDataset();
        if (!this.addDataSetInfo(dataset)) {
            protHit.setDataset((DatasetInfo)dataSetInfos.getKey(dataset));
        }
        return proteinHits.add(protHit);
    }
    
    public boolean addPeptide(Peptide pep) {
        return peptides.add(pep);
    }
    
    public boolean addPeptideHit(PeptideHit pepHit) {
        Query query = pepHit.getQuery();
        if (!this.addQuery(query)) {
            pepHit.setQuery((Query)queries.getKey(query));
        }
        Peptide pep = pepHit.getPeptide();
        if (!this.addPeptide(pep)) {
            pepHit.setPeptide((Peptide)peptides.getKey(pep));
        }            
        return peptideHits.add(pepHit);
    }
    
    public boolean addProteinHitPeptideHitJoin(ProtHitPeptHitJoin pph) {
        ProteinHit protHit = pph.getProteinHit();
        if (!this.addProteinHit(protHit)) {
            pph.setProteinHit((ProteinHit)proteinHits.getKey(protHit));
        }
        PeptideHit pepHit = pph.getPeptideHit();
        if (!this.addPeptideHit(pepHit)) {
            pph.setPeptideHit((PeptideHit)peptideHits.getKey(pepHit));
        }
        return protHitPeptHitJoins.add(pph);
    }
    
    public boolean addQuery(Query q) {
        DatasetInfo dsi = q.getDataSetInfo();
        if (!this.addDataSetInfo(dsi)) {
            q.setDataSetInfo((DatasetInfo)dataSetInfos.getKey(dsi));
        }
        return queries.add(q);
    }
    
    public boolean addProteinDB(ProtDbInfo protDb) {
        return this.protDbs.add(protDb);
    }

    public boolean addProteinSequence(ProtSeq protSeq) {
        return this.protSequences.add(protSeq);
    }    
    
}
