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