X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fdatamodel%2FPDBEntry.java;h=14035957fe08c181c99d2580e042f0ac756bcf8e;hb=ee0f6c877392ffc2018ae1a832042fbd364730ab;hp=16f88642f3b71e6d37e109e4a3fbc7b26c2736b0;hpb=7bc226b58110fa26d9dbd3f0c78095d06909ffc3;p=jalview.git
diff --git a/src/jalview/datamodel/PDBEntry.java b/src/jalview/datamodel/PDBEntry.java
index 16f8864..1403595 100755
--- a/src/jalview/datamodel/PDBEntry.java
+++ b/src/jalview/datamodel/PDBEntry.java
@@ -1,73 +1,383 @@
-/*
- * Jalview - A Sequence Alignment Editor and Viewer
- * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
- */
-package jalview.datamodel;
-
-import java.util.*;
-
-public class PDBEntry
-{
- String file;
- String type;
- String id;
- Hashtable properties;
-
- public PDBEntry()
- {}
-
- public void setFile(String file)
- {
- this.file = file;
- }
-
- public String getFile()
- {
- return file;
- }
-
- public void setType(String type)
- {
- this.type = type;
- }
-
- public String getType()
- {
- return type;
- }
-
- public void setId(String id)
- {
- this.id = id;
- }
-
- public String getId()
- {
- return id;
- }
-
- public void setProperty(Hashtable property)
- {
- this.properties = property;
- }
-
- public Hashtable getProperty()
- {
- return properties;
- }
-
-}
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
+ *
+ * This file is part of Jalview.
+ *
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * Jalview is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview. If not, see
+ * If newEntry has the same id (ignoring case), and doesn't have a conflicting + * file spec or chain code, then update this entry from its file and/or chain + * code. + * + * @param newEntry + * @return true if modifications were made + */ + protected boolean updateFrom(PDBEntry newEntry) + { + if (this.equals(newEntry)) + { + return true; + } + + String newId = newEntry.getId(); + if (newId == null || getId() == null) + { + return false; // shouldn't happen + } + + /* + * id (less any chain code) has to match (ignoring case) + */ + if (!getId().equalsIgnoreCase(newId)) + { + return false; + } + + /* + * Don't update if associated with different structure files + */ + String newFile = newEntry.getFile(); + if (newFile != null && getFile() != null && !newFile.equals(getFile())) + { + return false; + } + + /* + * Don't update if associated with different chains (ignoring case) + */ + String newChain = newEntry.getChainCode(); + if (newChain != null && newChain.length() > 0 && getChainCode() != null + && getChainCode().length() > 0 + && !getChainCode().equalsIgnoreCase(newChain)) + { + return false; + } + + /* + * set file path if not already set + */ + String newType = newEntry.getType(); + if (getFile() == null && newFile != null) + { + setFile(newFile); + setType(newType); + } + + /* + * set file type if new entry has it and we don't + * (for the case where file was not updated) + */ + if (getType() == null && newType != null) + { + setType(newType); + } + + /* + * set chain if not already set (we excluded differing + * chains earlier) (ignoring case change only) + */ + if (newChain != null && newChain.length() > 0 + && !newChain.equalsIgnoreCase(getChainCode())) + { + setChainCode(newChain); + } + + /* + * copy any new properties; notice this may include chain_code, + * but we excluded differing chain codes earlier + */ + if (newEntry.getProperty() != null) + { + if (properties == null) + { + properties = new Hashtable(); + } + for (Object p : newEntry.getProperty().keySet()) + { + /* + * copy properties unless value matches; this defends against changing + * the case of chain_code which is wrapped in a CaseInsensitiveString + */ + Object value = newEntry.getProperty().get(p); + if (!value.equals(properties.get(p))) + { + properties.put(p, newEntry.getProperty().get(p)); + } + } + } + return true; + } +}