16bd2526e63529278c7a7b1989f6058dd99671c6
[jalview.git] / src / jalview / datamodel / DBRefEntry.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3  * Copyright (C) $$Year-Rel$$ 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   public boolean equals(DBRefEntry entry)
73   {
74     if (entry == this)
75     {
76       return true;
77     }
78     if (entry == null)
79     {
80       return false;
81     }
82     if (equalRef(entry)
83             && ((map == null && entry.map == null) || (map != null
84                     && entry.map != null && map.equals(entry.map))))
85     {
86       return true;
87     }
88     return false;
89   }
90
91   /**
92    * test for similar DBRef attributes, except for the map object.
93    * 
94    * @param entry
95    * @return true if source, accession and version are equal with those of entry
96    */
97   public boolean equalRef(DBRefEntry entry)
98   {
99     if (entry == null)
100     {
101       return false;
102     }
103     if (entry == this)
104     {
105       return true;
106     }
107     if ((source != null && entry.source != null && source
108             .equalsIgnoreCase(entry.source))
109             && (accessionId != null && entry.accessionId != null && accessionId
110                     .equalsIgnoreCase(entry.accessionId))
111             && (version != null && entry.version != null && version
112                     .equalsIgnoreCase(entry.version)))
113     {
114       return true;
115     }
116     return false;
117   }
118
119   public String getSource()
120   {
121     return source;
122   }
123
124   public String getVersion()
125   {
126     return version;
127   }
128
129   public String getAccessionId()
130   {
131     return accessionId;
132   }
133
134   /**
135    * @param accessionId
136    *          the accessionId to set
137    */
138   public void setAccessionId(String accessionId)
139   {
140     this.accessionId = accessionId;
141   }
142
143   /**
144    * @param source
145    *          the source to set
146    */
147   public void setSource(String source)
148   {
149     this.source = source;
150   }
151
152   /**
153    * @param version
154    *          the version to set
155    */
156   public void setVersion(String version)
157   {
158     this.version = version;
159   }
160
161   /**
162    * @return the map
163    */
164   public Mapping getMap()
165   {
166     return map;
167   }
168
169   /**
170    * @param map
171    *          the map to set
172    */
173   public void setMap(Mapping map)
174   {
175     this.map = map;
176   }
177
178   public boolean hasMap()
179   {
180     return map != null;
181   }
182
183   /**
184    * 
185    * @return source+":"+accessionId
186    */
187   public String getSrcAccString()
188   {
189     return ((source != null) ? source : "") + ":"
190             + ((accessionId != null) ? accessionId : "");
191   }
192
193   public String toString()
194   {
195     return getSrcAccString();
196   }
197 }