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 */
021package org.biojava.nbio.structure.symmetry.misc;
022
023import java.util.List;
024
025public class ChainSignature implements Comparable<ChainSignature> {
026        private int chainCount = 0;
027        private String representative = "";
028        private String compositionId = "";
029        private List<String> chainIds = null;
030
031        public ChainSignature(String representative, int chainCount, List<String> chainIds) {
032                this.representative = representative;
033                this.chainCount = chainCount;
034                this.chainIds = chainIds;
035        }
036
037        public String getRepresentative() {
038                return representative;
039        }
040
041        public List<String> getChainIds() {
042                return chainIds;
043        }
044
045        public String getCompositionId() {
046                return compositionId;
047        }
048
049        public void setCompositionId(String compositionId) {
050                this.compositionId = compositionId;
051        }
052
053        @Override
054        public boolean equals (Object obj) {
055                if (this == obj) {
056                        return true;
057                }
058                if((obj == null) || (obj.getClass() != this.getClass())) return false;
059
060                ChainSignature other = (ChainSignature) obj;
061                if (representative == null) {
062                        return false;
063                }
064                return chainCount == other.chainCount && representative.equals(other.representative);
065        }
066
067        @Override
068        public int compareTo(ChainSignature other) {
069                if (other.chainCount < this.chainCount) {
070                        return -1;
071                }
072                if (other.chainCount > this.chainCount) {
073                        return 1;
074                }
075                return this.representative.compareTo(other.representative);
076        }
077
078        @Override
079        public int hashCode() {
080                int hash = 7;
081                hash = 31 * hash + chainCount;
082                hash = 31 * hash + (representative == null ? 0 : representative.hashCode());
083                return hash;
084        }
085
086        @Override
087        public String toString() {
088                StringBuilder builder = new StringBuilder();
089                builder.append("(");
090                builder.append(representative);
091                builder.append(")");
092                if (chainCount> 1) {
093                        builder.append(chainCount);
094                }
095                return builder.toString();
096        }
097
098}