JAL-1803 first pass at updatePDBEntry
[jalview.git] / src / jalview / datamodel / PDBEntry.java
index 673c12a..1c1d192 100755 (executable)
@@ -245,4 +245,54 @@ public class PDBEntry
   {
     return id;
   }
+
+  /**
+   * update entry with details from another entry concerning the same PDB
+   * ID/file spec.
+   * 
+   * @param newEntry
+   * @return true if modifications were made
+   */
+  public boolean updateFrom(PDBEntry newEntry)
+  {
+    boolean modified = false;
+
+    if (getFile() == null)
+    {
+      // update file and type of file
+      modified |= newEntry.getFile() != null;
+      setFile(newEntry.getFile());
+    }
+    if (newEntry.getType() != null && newEntry.getFile() != null
+            && newEntry.getFile().equals(getFile()))
+    {
+      setType(newEntry.getType());
+    }
+    if (getChainCode() == null
+            || (getChainCode() != null && getChainCode().length() == 0 && newEntry
+                    .getChainCode() != null))
+    {
+      modified |= getChainCode() == null
+              || !newEntry.getChainCode().equals(getChainCode());
+      setChainCode(newEntry.getChainCode());
+    }
+    if (newEntry.getProperty() != null)
+    {
+      if (properties == null)
+      {
+        properties = new Hashtable();
+      }
+      // TODO: getProperty -> Map<String,String>
+      for (Object p : newEntry.getProperty().keySet())
+      {
+        if (properties.get(p) == null
+                || !properties.get(p).equals(newEntry.getProperty().get(p)))
+        {
+          modified = true;
+        }
+        properties.put(p, newEntry.getProperty().get(p));
+      }
+    }
+    return modified;
+  }
 }