001/*
002 *                    BioJava development code
003 *
004 * This code may be freely distributed and modified under the
005 * terms of the GNU Lesser General Public Licence.  This should
006 * be distributed with the code.  If you do not have a copy,
007 * see:
008 *
009 *      http://www.gnu.org/copyleft/lesser.html
010 *
011 * Copyright for this code is held jointly by the individual
012 * authors.  These should be listed in @author doc comments.
013 *
014 * For more information on the BioJava project and its aims,
015 * or to join the biojava-l mailing list, visit the home page
016 * at:
017 *
018 *      http://www.biojava.org/
019 *
020 * Created on DATE
021 *
022 */
023
024package org.biojava.nbio.core.sequence.compound;
025
026import java.io.Serializable;
027
028import org.biojava.nbio.core.sequence.template.AbstractCompound;
029import org.biojava.nbio.core.sequence.template.Compound;
030import org.biojava.nbio.core.sequence.template.CompoundSet;
031
032/**
033 * Used to describe an Amino Acid.
034 * @author Richard Holland
035 * @author Scooter Willis
036 * @author Andy Yates
037 */
038public class AminoAcidCompound extends AbstractCompound implements Serializable {
039
040        /**
041         *
042         */
043private static final long serialVersionUID = -1955116496725902319L;
044private final AminoAcidCompoundSet compoundSet;
045
046
047        public AminoAcidCompound(AminoAcidCompoundSet compoundSet, String shortName,
048                        String longName, String description, Float molecularWeight) {
049                super(shortName);
050                setShortName(shortName);
051                setLongName(longName);
052                setDescription(description);
053                setMolecularWeight(molecularWeight);
054                this.compoundSet = compoundSet;
055        }
056
057        // TODO need to allow for modified name; that's not equality though is it?
058        @Override
059public boolean equals(Object obj) {
060                if (obj == null) {
061                        return false;
062                }
063                if (!(obj instanceof AminoAcidCompound)) {
064                        return false;
065                }
066                AminoAcidCompound them = (AminoAcidCompound) obj;
067                if (toString().equals(them.toString())) {
068                        return true;
069                }
070                return getLongName().equals(them.getLongName());
071
072        }
073
074        @Override
075public int hashCode() {
076                return toString().hashCode();
077        }
078
079        @Override
080public boolean equalsIgnoreCase(Compound compound) {
081                if (compound == null) {
082                        return false;
083                }
084                if (!(compound instanceof AminoAcidCompound)) {
085                        return false;
086                }
087                AminoAcidCompound them = (AminoAcidCompound) compound;
088                if (toString().equalsIgnoreCase(them.toString())) {
089                        return true;
090                }
091                return getLongName().equalsIgnoreCase(them.getLongName());
092        }
093
094        public CompoundSet<AminoAcidCompound> getCompoundSet() {
095                return compoundSet;
096        }
097}