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 Aug 2, 2010
021 * Author: Jianjiong Gao
022 *
023 */
024
025package org.biojava.nbio.protmod.structure;
026
027public class StructureAtomLinkage {
028
029        private final StructureAtom atom1;
030        private final StructureAtom atom2;
031        private final double distance;
032
033        public StructureAtomLinkage(final StructureAtom atom1,
034                        final StructureAtom atom2, final double distance) {
035                if (atom1 == null || atom2 == null)
036                        throw new IllegalArgumentException("Null atom(s)");
037                this.atom1 = atom1;
038                this.atom2 = atom2;
039                this.distance = distance;
040        }
041
042        public StructureAtom getAtom1() {
043                return atom1;
044        }
045
046        public StructureAtom getAtom2() {
047                return atom2;
048        }
049
050        public double getDistance() {
051                return distance;
052        }
053
054        @Override
055        public boolean equals(Object obj) {
056                if (obj == this)
057                        return true;
058
059                if (!(obj instanceof StructureAtomLinkage))
060                        return false;
061
062                StructureAtomLinkage aLink = (StructureAtomLinkage) obj;
063                if (aLink.atom1.equals(atom1) && aLink.atom2.equals(atom2))
064                        return true;
065
066                if (aLink.atom1.equals(atom2) && aLink.atom2.equals(atom1))
067                        return true;
068
069                return false;
070        }
071
072        @Override
073        public int hashCode() {
074                int result = 17;
075                result = result * 31 + atom1.hashCode() + atom2.hashCode();
076                return result;
077        }
078
079        @Override
080        public String toString() {
081                String dat =  atom1.toString() + "-" + atom2.toString() + " distance: " + String.format("%.2f",distance);
082                dat = dat.replaceAll("\t"," ");
083                return dat;
084        }
085}