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