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.Hashtable;
39 * case insensitive matching for Type enum
44 public static Type getType(String value)
46 for (Type t : Type.values())
48 if (t.toString().equalsIgnoreCase(value))
57 * case insensitive equivalence for strings resolving to PDBEntry type
62 public boolean matches(String t)
64 return (this.toString().equalsIgnoreCase(t));
69 * constant for storing chain code in properties table
71 private static final String CHAIN_ID = "chain_code";
78 * @see java.lang.Object#equals(java.lang.Object)
81 public boolean equals(Object obj)
83 if (obj == null || !(obj instanceof PDBEntry))
91 PDBEntry o = (PDBEntry) obj;
92 return (type == o.type || (type != null && o.type != null && o.type
94 && (id == o.id || (id != null && o.id != null && o.id
95 .equalsIgnoreCase(id)))
96 && (properties == o.properties || (properties != null
97 && o.properties != null && properties
98 .equals(o.properties)));
103 * Default constructor
110 * Constructor given file path and PDB id.
114 // public PDBEntry(String filePath, String pdbId)
116 // this.file = filePath;
120 public PDBEntry(String pdbId, String chain, PDBEntry.Type type,
124 this.type = type == null ? null : type.toString();
125 this.file = filePath;
134 public PDBEntry(PDBEntry entry)
139 if (entry.properties != null)
141 properties = (Hashtable) entry.properties.clone();
145 public void setFile(String file)
150 public String getFile()
155 public void setType(String t)
160 public void setType(PDBEntry.Type type)
162 this.type = type == null ? null : type.toString();
165 public String getType()
170 public void setId(String id)
175 public String getId()
180 public void setProperty(Hashtable property)
182 this.properties = property;
185 public Hashtable getProperty()
192 * @return null or a string for associated chain IDs
194 public String getChainCode()
196 return (properties == null || properties.get(CHAIN_ID) == null) ? null
197 : properties.get(CHAIN_ID).toString();
200 public void setChainCode(String chainCode)
202 if (properties == null)
204 if (chainCode == null)
209 properties = new Hashtable();
211 if (chainCode == null)
213 properties.remove(CHAIN_ID);
216 // update property for non-null chainCode
217 properties.put(CHAIN_ID, new CaseInsensitiveString(chainCode));
221 public String toString()
227 * update entry with details from another entry concerning the same PDB
231 * @return true if modifications were made
233 public boolean updateFrom(PDBEntry newEntry)
235 boolean modified = false;
237 if (getFile() == null)
239 // update file and type of file
240 modified |= newEntry.getFile() != null;
241 setFile(newEntry.getFile());
243 if (newEntry.getType() != null && newEntry.getFile() != null
244 && newEntry.getFile().equals(getFile()))
246 setType(newEntry.getType());
248 if (getChainCode() == null
249 || (getChainCode() != null && getChainCode().length() == 0 && newEntry
250 .getChainCode() != null))
252 modified |= getChainCode() == null
253 || !newEntry.getChainCode().equals(getChainCode());
254 setChainCode(newEntry.getChainCode());
256 if (newEntry.getProperty() != null)
258 if (properties == null)
260 properties = new Hashtable();
262 // TODO: getProperty -> Map<String,String>
263 for (Object p : newEntry.getProperty().keySet())
265 if (properties.get(p) == null
266 || !properties.get(p).equals(newEntry.getProperty().get(p)))
270 properties.put(p, newEntry.getProperty().get(p));