JAL-1645 Version-Rel Version 2.9 Year-Rel 2015 Licensing glob
[jalview.git] / src / jalview / datamodel / DBRefEntry.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.9)
3  * Copyright (C) 2015 The Jalview Authors
4  * 
5  * This file is part of Jalview.
6  * 
7  * Jalview is free software: you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License 
9  * as published by the Free Software Foundation, either version 3
10  * of the License, or (at your option) any later version.
11  *  
12  * Jalview is distributed in the hope that it will be useful, but 
13  * WITHOUT ANY WARRANTY; without even the implied warranty 
14  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
15  * PURPOSE.  See the GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License
18  * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
19  * The Jalview Authors are detailed in the 'AUTHORS' file.
20  */
21 package jalview.datamodel;
22
23 public class DBRefEntry
24 {
25   String source = "", version = "", accessionId = "";
26
27   /**
28    * maps from associated sequence to the database sequence's coordinate system
29    */
30   Mapping map = null;
31
32   public DBRefEntry()
33   {
34
35   }
36
37   public DBRefEntry(String source, String version, String accessionId)
38   {
39     this(source, version, accessionId, null);
40   }
41
42   /**
43    * 
44    * @param source
45    *          canonical source (uppercase only)
46    * @param version
47    *          (source dependent version string)
48    * @param accessionId
49    *          (source dependent accession number string)
50    * @param map
51    *          (mapping from local sequence numbering to source accession
52    *          numbering)
53    */
54   public DBRefEntry(String source, String version, String accessionId,
55           Mapping map)
56   {
57     this.source = source.toUpperCase();
58     this.version = version;
59     this.accessionId = accessionId;
60     this.map = map;
61   }
62
63   public DBRefEntry(DBRefEntry entry)
64   {
65     this(
66             (entry.source == null ? "" : new String(entry.source)),
67             (entry.version == null ? "" : new String(entry.version)),
68             (entry.accessionId == null ? "" : new String(entry.accessionId)),
69             (entry.map == null ? null : new Mapping(entry.map)));
70   }
71
72   @Override
73   public boolean equals(Object o)
74   {
75     // TODO should also override hashCode to ensure equal objects have equal
76     // hashcodes
77     if (o == null || !(o instanceof DBRefEntry))
78     {
79       return false;
80     }
81     DBRefEntry entry = (DBRefEntry) o;
82     if (entry == this)
83     {
84       return true;
85     }
86     if (equalRef(entry)
87             && ((map == null && entry.map == null) || (map != null
88                     && entry.map != null && map.equals(entry.map))))
89     {
90       return true;
91     }
92     return false;
93   }
94
95   /**
96    * test for similar DBRef attributes, except for the map object.
97    * 
98    * @param entry
99    * @return true if source, accession and version are equal with those of entry
100    */
101   public boolean equalRef(DBRefEntry entry)
102   {
103     if (entry == null)
104     {
105       return false;
106     }
107     if (entry == this)
108     {
109       return true;
110     }
111     if ((source != null && entry.source != null && source
112             .equalsIgnoreCase(entry.source))
113             && (accessionId != null && entry.accessionId != null && accessionId
114                     .equalsIgnoreCase(entry.accessionId))
115             && (version != null && entry.version != null && version
116                     .equalsIgnoreCase(entry.version)))
117     {
118       return true;
119     }
120     return false;
121   }
122
123   public String getSource()
124   {
125     return source;
126   }
127
128   public String getVersion()
129   {
130     return version;
131   }
132
133   public String getAccessionId()
134   {
135     return accessionId;
136   }
137
138   /**
139    * @param accessionId
140    *          the accessionId to set
141    */
142   public void setAccessionId(String accessionId)
143   {
144     this.accessionId = accessionId;
145   }
146
147   /**
148    * @param source
149    *          the source to set
150    */
151   public void setSource(String source)
152   {
153     this.source = source;
154   }
155
156   /**
157    * @param version
158    *          the version to set
159    */
160   public void setVersion(String version)
161   {
162     this.version = version;
163   }
164
165   /**
166    * @return the map
167    */
168   public Mapping getMap()
169   {
170     return map;
171   }
172
173   /**
174    * @param map
175    *          the map to set
176    */
177   public void setMap(Mapping map)
178   {
179     this.map = map;
180   }
181
182   public boolean hasMap()
183   {
184     return map != null;
185   }
186
187   /**
188    * 
189    * @return source+":"+accessionId
190    */
191   public String getSrcAccString()
192   {
193     return ((source != null) ? source : "") + ":"
194             + ((accessionId != null) ? accessionId : "");
195   }
196
197   public String toString()
198   {
199     return getSrcAccString();
200   }
201 }