2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
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.
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.
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.
21 package jalview.datamodel;
23 import jalview.api.DBRefEntryI;
25 public class DBRefEntry implements DBRefEntryI
27 String source = "", version = "", accessionId = "";
29 * maps from associated sequence to the database sequence's coordinate system
39 public DBRefEntry(String source, String version, String accessionId)
41 this(source, version, accessionId, null);
47 * canonical source (uppercase only)
49 * (source dependent version string)
51 * (source dependent accession number string)
53 * (mapping from local sequence numbering to source accession
56 public DBRefEntry(String source, String version, String accessionId,
59 this.source = source.toUpperCase();
60 this.version = version;
61 this.accessionId = accessionId;
65 public DBRefEntry(DBRefEntryI entry)
67 this((entry.getSource() == null ? "" : new String(entry.getSource())),
68 (entry.getVersion() == null ? "" : new String(
70 (entry.getAccessionId() == null ? "" : new String(
71 entry.getAccessionId())),
72 (entry.getMap() == null ? null : new Mapping(entry.getMap())));
76 public boolean equals(Object o)
78 // TODO should also override hashCode to ensure equal objects have equal
80 if (o == null || !(o instanceof DBRefEntry))
84 DBRefEntry entry = (DBRefEntry) o;
90 && ((map == null && entry.map == null) || (map != null
91 && entry.map != null && map.equals(entry.map))))
99 * Answers true if this object is either equivalent to, or can be 'improved'
100 * by, the given entry. Specifically, answers true if
102 * <li>source and accession are identical (ignoring case)</li>
103 * <li>version is identical (ignoring case), or this version is of the format
104 * "someSource:0", in which case the version for the other entry replaces it</li>
105 * <li>mappings are not compared but if this entry has no mapping, replace
106 * with that for the other entry</li>
113 public boolean updateFrom(DBRefEntryI other)
125 * source must either match or be both null
127 String otherSource = other.getSource();
128 if ((source == null && otherSource != null)
129 || (source != null && otherSource == null)
130 || (source != null && !source.equalsIgnoreCase(otherSource)))
136 * accession id must either match or be both null
138 String otherAccession = other.getAccessionId();
139 if ((accessionId == null && otherAccession != null)
140 || (accessionId != null && otherAccession == null)
141 || (accessionId != null && !accessionId.equalsIgnoreCase(otherAccession)))
147 * if my version is null, "0" or "source:0" then replace with other version,
148 * otherwise the versions have to match
150 String otherVersion = other.getVersion();
152 if ((version == null || version.equals("0") || version.endsWith(":0"))
153 && otherVersion != null)
155 setVersion(otherVersion);
160 && (otherVersion == null || !version
161 .equalsIgnoreCase(otherVersion)))
168 * if I have no mapping, take that of the other dbref
172 setMap(other.getMap());
178 * test for similar DBRef attributes, except for the map object.
181 * @return true if source, accession and version are equal with those of entry
184 public boolean equalRef(DBRefEntryI entry)
186 // TODO is this method and equals() not needed?
196 && (source != null && entry.getSource() != null && source
197 .equalsIgnoreCase(entry.getSource()))
198 && (accessionId != null && entry.getAccessionId() != null && accessionId
199 .equalsIgnoreCase(entry.getAccessionId()))
200 && (version != null && entry.getVersion() != null && version
201 .equalsIgnoreCase(entry.getVersion())))
209 public String getSource()
215 public String getVersion()
221 public String getAccessionId()
228 public void setAccessionId(String accessionId)
230 this.accessionId = accessionId;
235 public void setSource(String source)
237 this.source = source;
242 public void setVersion(String version)
244 this.version = version;
249 public Mapping getMap()
258 public void setMap(Mapping map)
263 public boolean hasMap()
270 * @return source+":"+accessionId
272 public String getSrcAccString()
274 return ((source != null) ? source : "") + ":"
275 + ((accessionId != null) ? accessionId : "");
279 public String toString()
281 return getSrcAccString();