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.util.CaseInsensitiveString;
25 import java.util.Collections;
26 import java.util.Enumeration;
27 import java.util.Hashtable;
28 import java.util.Map.Entry;
34 * constant for storing chain code in properties table
36 private static final String CHAIN_ID = "chain_code";
38 Hashtable<String, Object> properties;
50 * case insensitive matching for Type enum
55 public static Type getType(String value)
57 for (Type t : Type.values())
59 if (t.toString().equalsIgnoreCase(value))
68 * case insensitive equivalence for strings resolving to PDBEntry type
73 public boolean matches(String t)
75 return (this.toString().equalsIgnoreCase(t));
83 * @see java.lang.Object#equals(java.lang.Object)
86 public boolean equals(Object obj)
88 if (obj == null || !(obj instanceof PDBEntry))
96 PDBEntry o = (PDBEntry) obj;
97 return (type == o.type || (type != null && o.type != null && o.type
99 && (id == o.id || (id != null && o.id != null && o.id
100 .equalsIgnoreCase(id)))
101 && (properties == o.properties || (properties != null
102 && o.properties != null && properties
103 .equals(o.properties)));
108 * Default constructor
115 * Constructor given file path and PDB id.
119 // public PDBEntry(String filePath, String pdbId)
121 // this.file = filePath;
125 public PDBEntry(String pdbId, String chain, PDBEntry.Type type,
129 this.type = type == null ? null : type.toString();
130 this.file = filePath;
139 public PDBEntry(PDBEntry entry)
144 if (entry.properties != null)
146 properties = (Hashtable<String, Object>) entry.properties.clone();
150 public void setFile(String f)
155 public String getFile()
160 public void setType(String t)
165 public void setType(PDBEntry.Type type)
167 this.type = type == null ? null : type.toString();
170 public String getType()
175 public void setId(String id)
180 public String getId()
185 public void setProperty(String key, Object value)
187 if (this.properties == null)
189 this.properties = new Hashtable<String, Object>();
191 properties.put(key, value);
194 public Object getProperty(String key)
196 return properties == null ? null : properties.get(key);
200 * Returns an enumeration of the keys of this object's properties (or an empty
201 * enumeration if it has no properties)
205 public Enumeration<String> getProperties()
207 if (properties == null)
209 return Collections.emptyEnumeration();
211 return properties.keys();
216 * @return null or a string for associated chain IDs
218 public String getChainCode()
220 return (properties == null || properties.get(CHAIN_ID) == null) ? null
221 : properties.get(CHAIN_ID).toString();
225 * Sets a non-case-sensitive property for the given chain code. Two PDBEntry
226 * objects which differ only in the case of their chain code are considered
227 * equal. This avoids duplication of objects in lists of PDB ids.
231 public void setChainCode(String chainCode)
233 if (chainCode == null)
235 deleteProperty(CHAIN_ID);
239 setProperty(CHAIN_ID, new CaseInsensitiveString(chainCode));
244 * Deletes the property with the given key, and returns the deleted value (or
247 Object deleteProperty(String key)
249 Object result = null;
250 if (properties != null)
252 result = properties.remove(key);
258 public String toString()
264 * Getter provided for Castor binding only. Application code should call
265 * getProperty() or getProperties() instead.
268 * @see #getProperty(String)
269 * @see #getProperties()
270 * @see jalview.ws.dbsources.Uniprot#getUniprotEntries
274 public Hashtable<String, Object> getProps()
280 * Setter provided for Castor binding only. Application code should call
281 * setProperty() instead.
287 public void setProps(Hashtable<String, Object> props)
293 * update entry with details from another entry concerning the same PDB
297 * @return true if modifications were made
299 public boolean updateFrom(PDBEntry newEntry)
301 boolean modified = false;
303 if (getFile() == null)
305 // update file and type of file
306 modified = newEntry.getFile() != null;
307 setFile(newEntry.getFile());
309 if (newEntry.getType() != null && newEntry.getFile() != null
310 && newEntry.getFile().equals(getFile()))
312 setType(newEntry.getType());
314 if (getChainCode() == null
315 || (getChainCode() != null && getChainCode().length() == 0 && newEntry
316 .getChainCode() != null))
318 modified |= (getChainCode() == null || !newEntry.getChainCode()
319 .equals(getChainCode()));
320 setChainCode(newEntry.getChainCode());
322 if (newEntry.properties != null)
324 for (Entry<String, Object> entry : newEntry.properties.entrySet())
326 if (!entry.getValue().equals(getProperty(entry.getKey())))
330 setProperty(entry.getKey(), entry.getValue());