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 java.util.Hashtable;
37 * case insensitive matching for Type enum
42 public static Type getType(String value)
44 for (Type t : Type.values())
46 if (t.toString().equalsIgnoreCase(value))
55 * case insensitive equivalence for strings resolving to PDBEntry type
60 public boolean matches(String t)
62 return (this.toString().equalsIgnoreCase(t));
66 public final class ChainId
70 public ChainId(String chainId)
72 this.chainId = chainId;
76 public String toString()
82 public boolean equals(Object o){
87 return chainId.equalsIgnoreCase(o.toString());
92 * constant for storing chain code in properties table
94 private static final String CHAIN_ID = "chain_code";
101 * @see java.lang.Object#equals(java.lang.Object)
104 public boolean equals(Object obj)
106 if (obj == null || !(obj instanceof PDBEntry))
114 PDBEntry o = (PDBEntry) obj;
115 return (type == o.type || (type != null && o.type != null && o.type
117 && (id == o.id || (id != null && o.id != null && o.id
118 .equalsIgnoreCase(id)))
119 && (properties == o.properties || (properties != null
120 && o.properties != null && properties
121 .equals(o.properties)));
126 * Default constructor
133 * Constructor given file path and PDB id.
137 // public PDBEntry(String filePath, String pdbId)
139 // this.file = filePath;
143 public PDBEntry(String pdbId, String chain, PDBEntry.Type type,
147 this.type = type == null ? null : type.toString();
148 this.file = filePath;
157 public PDBEntry(PDBEntry entry)
162 if (entry.properties != null)
164 properties = (Hashtable) entry.properties.clone();
168 public void setFile(String file)
173 public String getFile()
178 public void setType(String t)
183 public void setType(PDBEntry.Type type)
185 this.type = type == null ? null : type.toString();
188 public String getType()
193 public void setId(String id)
198 public String getId()
203 public void setProperty(Hashtable property)
205 this.properties = property;
208 public Hashtable getProperty()
215 * @return null or a string for associated chain IDs
217 public String getChainCode()
219 return (properties == null || properties.get(CHAIN_ID) == null) ? null
220 : properties.get(CHAIN_ID).toString();
223 public void setChainCode(String chainCode)
225 if (properties == null)
227 if (chainCode == null)
232 properties = new Hashtable();
234 if (chainCode == null)
236 properties.remove(CHAIN_ID);
239 // update property for non-null chainCode
240 properties.put(CHAIN_ID, new ChainId(chainCode));
244 public String toString()
250 * update entry with details from another entry concerning the same PDB
254 * @return true if modifications were made
256 public boolean updateFrom(PDBEntry newEntry)
258 boolean modified = false;
260 if (getFile() == null)
262 // update file and type of file
263 modified |= newEntry.getFile() != null;
264 setFile(newEntry.getFile());
266 if (newEntry.getType() != null && newEntry.getFile() != null
267 && newEntry.getFile().equals(getFile()))
269 setType(newEntry.getType());
271 if (getChainCode() == null
272 || (getChainCode() != null && getChainCode().length() == 0 && newEntry
273 .getChainCode() != null))
275 modified |= getChainCode() == null
276 || !newEntry.getChainCode().equals(getChainCode());
277 setChainCode(newEntry.getChainCode());
279 if (newEntry.getProperty() != null)
281 if (properties == null)
283 properties = new Hashtable();
285 // TODO: getProperty -> Map<String,String>
286 for (Object p : newEntry.getProperty().keySet())
288 if (properties.get(p) == null
289 || !properties.get(p).equals(newEntry.getProperty().get(p)))
293 properties.put(p, newEntry.getProperty().get(p));