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 Jul 29, 2010
021 * Author: Jianjiong Gao
022 *
023 */
024
025package org.biojava.nbio.protmod.structure;
026
027/**
028 * Everything that is needed to uniquely describe a atom.
029 * @author Jianjiong Gao
030 * @since 3.0
031 */
032public class StructureAtom {
033
034        private final StructureGroup group;
035        private final String atomName;
036
037        public StructureAtom(final StructureGroup group, final String atomName) {
038                if (group==null || atomName==null) {
039                        throw new IllegalArgumentException("Null argument(s).");
040                }
041                this.group = group;
042                this.atomName = atomName;
043        }
044
045        public StructureGroup getGroup() {
046                return group;
047        }
048
049        public String getAtomName() {
050                return atomName;
051        }
052
053        @Override
054        public boolean equals(Object obj) {
055                if (obj == this)
056                        return true;
057
058                if (!(obj instanceof StructureAtom))
059                        return false;
060
061                StructureAtom anAtom = (StructureAtom)obj;
062
063                if (!anAtom.getGroup().equals(group))
064                        return false;
065
066                if (!anAtom.getAtomName().equals(atomName))
067                        return false;
068
069                return true;
070        }
071
072        @Override
073        public int hashCode() {
074                int result = 17;
075                result = result * 32 + group.hashCode();
076                result = result * 32 + atomName.hashCode();
077                return result;
078        }
079
080        @Override
081        public String toString() {
082                return group.toString() + '\t' + atomName;
083        }
084}