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 */
023package org.biojava.nbio.core.sequence;
024
025import org.biojava.nbio.core.util.Equals;
026import org.biojava.nbio.core.util.Hashcoder;
027
028/**
029 * Used in Sequences as the unique indentifier. If possible, set the {@link DataSource} to know the
030 * source of the id. This allows a SequenceProxy to gather features or related sequences
031 * Protein->Gene as an example. When parsing a Blast file it is also possible
032 * to identify the type of ID
033 *
034 * @author Scooter Willis
035 * @author Jacek Grzebyta
036 */
037public class AccessionID {
038
039        private String id = null;
040        private DataSource source = DataSource.LOCAL;
041        private Integer version;
042        private String identifier = null;
043
044        /**
045         *
046         */
047
048        public AccessionID(){
049                id = "";
050
051        }
052
053        /**
054         *
055         * @param id
056         */
057        public AccessionID(String id) {
058                this.id = id.trim();
059                this.source = DataSource.LOCAL;
060        }
061
062
063        /**
064         *
065         * @param id
066         * @param source
067         */
068        public AccessionID(String id, DataSource source) {
069                this.id = id.trim();
070                this.source = source;
071        }
072
073        public AccessionID(String id, DataSource source, Integer version, String identifier) {
074                this.id = id;
075                this.source = source;
076                this.version = version;
077                this.identifier = identifier;
078        }
079
080        /**
081         * @return the id
082         */
083        public String getID() {
084                return id;
085        }
086
087        /**
088         * @return the source
089         */
090        public DataSource getDataSource() {
091                return source;
092        }
093
094        @Override
095        public boolean equals(Object o) {
096                boolean equals = false;
097                if (Equals.classEqual(this, o)) {
098                        AccessionID l = (AccessionID) o;
099                        equals = (Equals.equal(getID(), l.getID())
100                                        && Equals.equal(getDataSource(), l.getDataSource())
101                                        && Equals.equal(getIdentifier(), l.getIdentifier())
102                                        && Equals.equal(getVersion(), l.getVersion()));
103        }
104                return equals;
105        }
106
107        @Override
108        public int hashCode() {
109                int r = Hashcoder.SEED;
110                r = Hashcoder.hash(r, getID());
111                r = Hashcoder.hash(r, getDataSource());
112                r = Hashcoder.hash(r, getIdentifier());
113                r = Hashcoder.hash(r, getVersion());
114                return r;
115        }
116
117//   public void setDataSource(DataSource dataSource){
118//       source = dataSource;
119//   }
120
121
122        /**
123         * In case if the {@link #getID() } is not unique keeps the id version.
124         * @return the version
125         */
126        public Integer getVersion() {
127                return version;
128        }
129
130        public void setVersion(Integer version) {
131                this.version = version;
132        }
133
134        /**
135         * In case if {@link #getID() } in not unique keeps the alternative id, eg. NCBI GI number.
136         * 
137         * This may null.
138         *
139         * @return
140         */
141        public String getIdentifier() {
142                return identifier;
143        }
144
145        public void setIdentifier(String identifier) {
146                this.identifier = identifier;
147        }
148
149
150        @Override
151        public String toString() {
152                return id;
153        }
154}