import jalview.util.CaseInsensitiveString;
+import java.util.Collections;
+import java.util.Enumeration;
import java.util.Hashtable;
public class PDBEntry
{
+
+ /**
+ * constant for storing chain code in properties table
+ */
+ private static final String CHAIN_ID = "chain_code";
+
+ private Hashtable<String, Object> properties;
+
private static final int PDB_ID_LENGTH = 4;
private String file;
}
}
- /**
- * constant for storing chain code in properties table
- */
- private static final String CHAIN_ID = "chain_code";
-
- Hashtable properties;
/**
* Answers true if obj is a PDBEntry with the same id and chain code (both
/**
* @param pdbId
* @param chain
- * @param type
+ * @param entryType
* @param filePath
*/
- void init(String pdbId, String chain, PDBEntry.Type type, String filePath)
+ void init(String pdbId, String chain, PDBEntry.Type entryType, String filePath)
{
this.id = pdbId;
- this.type = type == null ? null : type.toString();
+ this.type = entryType == null ? null : entryType.toString();
this.file = filePath;
setChainCode(chain);
}
id = entry.id;
if (entry.properties != null)
{
- properties = (Hashtable) entry.properties.clone();
+ properties = (Hashtable<String, Object>) entry.properties.clone();
}
}
init(pdbId, chainCode, null, null);
}
- public void setFile(String file)
+ public void setFile(String f)
{
- this.file = file;
+ this.file = f;
}
public String getFile()
return id;
}
- public void setProperty(Hashtable property)
+ public void setProperty(String key, Object value)
{
- this.properties = property;
+ if (this.properties == null)
+ {
+ this.properties = new Hashtable<String, Object>();
+ }
+ properties.put(key, value);
}
- public Hashtable getProperty()
+ public Object getProperty(String key)
{
- return properties;
+ return properties == null ? null : properties.get(key);
+ }
+
+ /**
+ * Returns an enumeration of the keys of this object's properties (or an empty
+ * enumeration if it has no properties)
+ *
+ * @return
+ */
+ public Enumeration<String> getProperties()
+ {
+ if (properties == null)
+ {
+ return Collections.emptyEnumeration();
+ }
+ return properties.keys();
}
/**
: properties.get(CHAIN_ID).toString();
}
+ /**
+ * Sets a non-case-sensitive property for the given chain code. Two PDBEntry
+ * objects which differ only in the case of their chain code are considered
+ * equal. This avoids duplication of objects in lists of PDB ids.
+ *
+ * @param chainCode
+ */
public void setChainCode(String chainCode)
{
- if (properties == null)
+ if (chainCode == null)
{
- if (chainCode == null)
- {
- // nothing to do.
- return;
- }
- properties = new Hashtable();
+ deleteProperty(CHAIN_ID);
}
- if (chainCode == null)
+ else
+ {
+ setProperty(CHAIN_ID, new CaseInsensitiveString(chainCode));
+ }
+ }
+
+ /**
+ * Deletes the property with the given key, and returns the deleted value (or
+ * null)
+ */
+ Object deleteProperty(String key)
+ {
+ Object result = null;
+ if (properties != null)
{
- properties.remove(CHAIN_ID);
- return;
+ result = properties.remove(key);
}
- // update property for non-null chainCode
- properties.put(CHAIN_ID, new CaseInsensitiveString(chainCode));
+ return result;
}
@Override
}
/**
+ * Getter provided for Castor binding only. Application code should call
+ * getProperty() or getProperties() instead.
+ *
+ * @deprecated
+ * @see #getProperty(String)
+ * @see #getProperties()
+ * @see jalview.ws.dbsources.Uniprot#getUniprotEntries
+ * @return
+ */
+ @Deprecated
+ public Hashtable<String, Object> getProps()
+ {
+ return properties;
+ }
+
+ /**
+ * Setter provided for Castor binding only. Application code should call
+ * setProperty() instead.
+ *
+ * @deprecated
+ * @return
+ */
+ @Deprecated
+ public void setProps(Hashtable<String, Object> props)
+ {
+ properties = props;
+ }
+
+ /**
* Answers true if this object is either equivalent to, or can be 'improved'
* by, the given entry.
* <p>
* @param newEntry
* @return true if modifications were made
*/
- protected boolean updateFrom(PDBEntry newEntry)
+ public boolean updateFrom(PDBEntry newEntry)
{
if (this.equals(newEntry))
{
}
/*
- * id (less any chain code) has to match (ignoring case)
+ * id has to match (ignoring case)
*/
if (!getId().equalsIgnoreCase(newId))
{
}
/*
- * copy any new properties; notice this may include chain_code,
- * but we excluded differing chain codes earlier
+ * copy any new or modified properties
*/
- if (newEntry.getProperty() != null)
+ Enumeration<String> newProps = newEntry.getProperties();
+ while (newProps.hasMoreElements())
{
- if (properties == null)
+ /*
+ * copy properties unless value matches; this defends against changing
+ * the case of chain_code which is wrapped in a CaseInsensitiveString
+ */
+ String key = newProps.nextElement();
+ Object value = newEntry.getProperty(key);
+ if (!value.equals(getProperty(key)))
{
- 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));
- }
+ setProperty(key, value);
}
}
return true;