*/
package jalview.datamodel;
+import jalview.util.CaseInsensitiveString;
+
+import java.util.Collections;
+import java.util.Enumeration;
import java.util.Hashtable;
+import java.util.Map.Entry;
public class PDBEntry
{
+
+ /**
+ * constant for storing chain code in properties table
+ */
+ private static final String CHAIN_ID = "chain_code";
+
+ Hashtable<String, Object> properties;
+
private String file;
private String type;
}
}
- public final class ChainId
- {
- String chainId;
-
- public ChainId(String chainId)
- {
- this.chainId = chainId;
- }
-
- @Override
- public String toString()
- {
- return chainId;
- }
-
- @Override
- public boolean equals(Object o){
- if (o==null)
- {
- return false;
- }
- return chainId.equalsIgnoreCase(o.toString());
- }
- }
-
- /**
- * constant for storing chain code in properties table
- */
- private static final String CHAIN_ID = "chain_code";
-
- Hashtable properties;
/*
* (non-Javadoc)
id = entry.id;
if (entry.properties != null)
{
- properties = (Hashtable) entry.properties.clone();
+ properties = (Hashtable<String, Object>) entry.properties.clone();
}
}
- 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 ChainId(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;
+ }
+
+ /**
* update entry with details from another entry concerning the same PDB
* ID/file spec.
*
if (getFile() == null)
{
// update file and type of file
- modified |= newEntry.getFile() != null;
+ modified = newEntry.getFile() != null;
setFile(newEntry.getFile());
}
if (newEntry.getType() != null && newEntry.getFile() != null
|| (getChainCode() != null && getChainCode().length() == 0 && newEntry
.getChainCode() != null))
{
- modified |= getChainCode() == null
- || !newEntry.getChainCode().equals(getChainCode());
+ modified |= (getChainCode() == null || !newEntry.getChainCode()
+ .equals(getChainCode()));
setChainCode(newEntry.getChainCode());
}
- if (newEntry.getProperty() != null)
+ if (newEntry.properties != null)
{
- if (properties == null)
- {
- properties = new Hashtable();
- }
- // TODO: getProperty -> Map<String,String>
- for (Object p : newEntry.getProperty().keySet())
+ for (Entry<String, Object> entry : newEntry.properties.entrySet())
{
- if (properties.get(p) == null
- || !properties.get(p).equals(newEntry.getProperty().get(p)))
+ if (!entry.getValue().equals(getProperty(entry.getKey())))
{
modified = true;
}
- properties.put(p, newEntry.getProperty().get(p));
+ setProperty(entry.getKey(), entry.getValue());
}
}
return modified;