update author list in license for (JAL-826)
[jalview.git] / src / jalview / datamodel / DBRefEntry.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
3  * Copyright (C) 2011 J Procter, AM Waterhouse, J Engelhardt, LM Lui, G Barton, M Clamp, S Searle
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  */
18 package jalview.datamodel;
19
20 public class DBRefEntry
21 {
22   String source = "", version = "", accessionId = "";
23
24   /**
25    * maps from associated sequence to the database sequence's coordinate system
26    */
27   Mapping map = null;
28
29   public DBRefEntry()
30   {
31
32   }
33
34   public DBRefEntry(String source, String version, String accessionId)
35   {
36     this(source, version, accessionId, null);
37   }
38
39   /**
40    * 
41    * @param source
42    *          canonical source (uppercase only)
43    * @param version
44    *          (source dependent version string)
45    * @param accessionId
46    *          (source dependent accession number string)
47    * @param map
48    *          (mapping from local sequence numbering to source accession
49    *          numbering)
50    */
51   public DBRefEntry(String source, String version, String accessionId,
52           Mapping map)
53   {
54     this.source = source.toUpperCase();
55     this.version = version;
56     this.accessionId = accessionId;
57     this.map = map;
58   }
59
60   public DBRefEntry(DBRefEntry entry)
61   {
62     this(
63             (entry.source == null ? "" : new String(entry.source)),
64             (entry.version == null ? "" : new String(entry.version)),
65             (entry.accessionId == null ? "" : new String(entry.accessionId)),
66             (entry.map == null ? null : new Mapping(entry.map)));
67   }
68
69   public boolean equals(DBRefEntry entry)
70   {
71     if (entry == this)
72       return true;
73     if (entry == null)
74       return false;
75     if (equalRef(entry)
76             && ((map == null && entry.map == null) || (map != null
77                     && entry.map != null && map.equals(entry.map))))
78     {
79       return true;
80     }
81     return false;
82   }
83
84   /**
85    * test for similar DBRef attributes, except for the map object.
86    * 
87    * @param entry
88    * @return true if source, accession and version are equal with those of entry
89    */
90   public boolean equalRef(DBRefEntry entry)
91   {
92     if (entry == null)
93     {
94       return false;
95     }
96     if (entry == this)
97       return true;
98     if ((source != null && entry.source != null && source
99             .equalsIgnoreCase(entry.source))
100             && (accessionId != null && entry.accessionId != null && accessionId
101                     .equalsIgnoreCase(entry.accessionId))
102             && (version != null && entry.version != null && version
103                     .equalsIgnoreCase(entry.version)))
104     {
105       return true;
106     }
107     return false;
108   }
109
110   public String getSource()
111   {
112     return source;
113   }
114
115   public String getVersion()
116   {
117     return version;
118   }
119
120   public String getAccessionId()
121   {
122     return accessionId;
123   }
124
125   /**
126    * @param accessionId
127    *          the accessionId to set
128    */
129   public void setAccessionId(String accessionId)
130   {
131     this.accessionId = accessionId;
132   }
133
134   /**
135    * @param source
136    *          the source to set
137    */
138   public void setSource(String source)
139   {
140     this.source = source;
141   }
142
143   /**
144    * @param version
145    *          the version to set
146    */
147   public void setVersion(String version)
148   {
149     this.version = version;
150   }
151
152   /**
153    * @return the map
154    */
155   public Mapping getMap()
156   {
157     return map;
158   }
159
160   /**
161    * @param map
162    *          the map to set
163    */
164   public void setMap(Mapping map)
165   {
166     this.map = map;
167   }
168
169   public boolean hasMap()
170   {
171     return map != null;
172   }
173
174   /**
175    * 
176    * @return source+":"+accessionId
177    */
178   public String getSrcAccString()
179   {
180     return ((source != null) ? source : "") + ":"
181             + ((accessionId != null) ? accessionId : "");
182   }
183 }