+ /**
+ *
+ * @return null or a string for associated chain IDs
+ */
+ public String getChainCode()
+ {
+ return (properties == null || properties.get(CHAIN_ID) == null) ? null
+ : properties.get(CHAIN_ID).toString();
+ }
+
+ public void setChainCode(String chainCode)
+ {
+ if (properties == null)
+ {
+ if (chainCode == null)
+ {
+ // nothing to do.
+ return;
+ }
+ properties = new Hashtable();
+ }
+ if (chainCode == null)
+ {
+ properties.remove(CHAIN_ID);
+ return;
+ }
+ // update property for non-null chainCode
+ properties.put(CHAIN_ID, new CaseInsensitiveString(chainCode));
+ }
+
+ @Override
+ public String toString()
+ {
+ return id;
+ }
+
+ /**
+ * Answers true if this object is either equivalent to, or can be 'improved'
+ * by, the given entry.
+ * <p>
+ * 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;
+ }