/*
 * Copyright 2009 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.tuples;

import compid.sequences.AminoSequence;
import java.util.HashMap;

/**
 *
 * @author Lari Natri
 */
public final class Peptide extends Tuple {
    
    public static final String TABLELABEL = "PEPTIDE";

    private final AminoSequence sequence;
    
    public Peptide(String sequence) {
        // TODO: check if sequence consists of amino acid symbols only
        if (sequence==null)
            throw new IllegalArgumentException("Sequence is not set.");
        String modifiedSequence = sequence.trim().toUpperCase();
        try {
            this.sequence = new AminoSequence(modifiedSequence);
        } catch (Exception ex) {
            throw new IllegalArgumentException("Peptide sequence is not an" +
                    "amino acid sequence. ("+sequence+")");
        }
        this.setTupleHasNoForeignKeys();
    }

    public Peptide(AminoSequence sequence) {
        this.sequence = sequence;
    }

    public AminoSequence getSequence() {
        return this.sequence;
    }

    @Override
    public boolean equals(Object obj) {
        // NOTE: if mass is later added, do not include it in equals(),
        // hashCode() nor getKeysAndValuesForExistenceCheck()
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Peptide other = (Peptide) obj;
        if (this.sequence != other.sequence && (this.sequence == null || !this.sequence.equals(other.sequence))) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        // NOTE: if mass is later added, do not include it in equals(),
        // hashCode() nor getKeysAndValuesForExistenceCheck()
        int hash = 7;
        hash = 83 * hash + (this.sequence != null ? this.sequence.hashCode() : 0);
        return hash;
    }

    @Override
    public String getTableLabel() {
        return TABLELABEL;
    }

    @Override
    public HashMap<String,Object> getColsAndValues() {
        HashMap<String,Object> map = new HashMap<String,Object>(1,1);
        map.put("PEPSEQUENCE", this.sequence.toString());
        return map;
    }

//    @Override
//    public HashMap<String, Object> getKeysAndValuesForExistenceCheck() {
//        // NOTE: if mass is later added, do not include it in equals(),
//        // hashCode() nor getKeysAndValuesForExistenceCheck()
//        HashMap<String,Object> map = new HashMap<String,Object>(1,1);
//        map.put("PEPSEQUENCE", this.sequence.toString());
//        return map;
//    }




}
