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    package org.biojava3.core.sequence;
024    
025    import org.biojava3.core.util.Equals;
026    import org.biojava3.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     */
036    public class AccessionID {
037    
038        private String id = null;
039        private DataSource source = DataSource.LOCAL;
040    
041        /**
042         *
043         */
044    
045        public AccessionID(){
046            id = "";
047            
048        }
049    
050        /**
051         *
052         * @param id
053         */
054        public AccessionID(String id) {
055            this.id = id.trim();
056            this.source = DataSource.LOCAL;
057        }
058    
059        /**
060         *
061         * @param id
062         * @param source
063         */
064        public AccessionID(String id, DataSource source) {
065            this.id = id.trim();
066            this.source = source;
067        }
068    
069        /**
070         * @return the id
071         */
072        public String getID() {
073            return id;
074        }
075    
076        /**
077         * @return the source
078         */
079        public DataSource getDataSource() {
080            return source;
081        }
082    
083        @Override
084        public boolean equals(Object o) {
085            boolean equals = false;
086            if (Equals.classEqual(this, o)) {
087                AccessionID l = (AccessionID) o;
088                equals = (Equals.equal(getID(), l.getID())
089                        && Equals.equal(getDataSource(), l.getDataSource()));
090            }
091            return equals;
092        }
093    
094        @Override
095        public int hashCode() {
096            int r = Hashcoder.SEED;
097            r = Hashcoder.hash(r, getID());
098            r = Hashcoder.hash(r, getDataSource());
099            return r;
100        }
101    
102     //   public void setDataSource(DataSource dataSource){
103     //       source = dataSource;
104     //   }
105    
106        @Override
107        public String toString() {
108            return id;
109        }
110    }