<class name="jalview.datamodel.PDBEntry">
<field name="type"><bind-xml node="attribute"/></field>
<field name="id"><bind-xml node="attribute"/></field>
- <field name="property" collection="hashtable">
+ <field name="props" collection="hashtable">
<bind-xml name="property">
<class name="org.exolab.castor.mapping.MapItem">
<field name="key">
worker.start();
}
- if (pdbentry.getProperty() != null)
+ String method = (String) pdbentry.getProperty("method");
+ if (method != null)
{
- if (pdbentry.getProperty().get("method") != null)
- {
- title.append(" Method: ");
- title.append(pdbentry.getProperty().get("method"));
- }
- if (pdbentry.getProperty().get("chains") != null)
- {
- title.append(" Chain:");
- title.append(pdbentry.getProperty().get("chains"));
- }
+ title.append(" Method: ");
+ title.append(method);
+ }
+ String ch = (String) pdbentry.getProperty("chains");
+ if (ch != null)
+ {
+ title.append(" Chain:");
+ title.append(ch);
}
Desktop.addInternalFrame(this, title.toString(), 400, 400);
}
import java.util.Arrays;
import java.util.Deque;
import java.util.HashMap;
-import java.util.Hashtable;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;
}
if (needtoadd)
{
- // make a note of the access mode and add
- if (pdbentry.getProperty() == null)
- {
- pdbentry.setProperty(new Hashtable());
- }
- pdbentry.getProperty().put("protocol", protocol);
+ pdbentry.setProperty("protocol", protocol);
toaddpdb.addPDBId(pdbentry);
alignPanel.getStructureSelectionManager()
.registerPDBEntry(pdbentry);
if (protocol == null || protocol.trim().length() == 0
|| protocol.equals("null"))
{
- protocol = (String) pdb.getProperty().get("protocol");
+ protocol = (String) pdb.getProperty("protocol");
if (protocol == null)
{
System.err.println("Couldn't work out protocol to open structure: "
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.ArrayList;
-import java.util.Hashtable;
import java.util.List;
import java.util.Vector;
closeViewer();
}
});
- if (pdbentry.getProperty() == null)
- {
- pdbentry.setProperty(new Hashtable());
- pdbentry.getProperty().put("protocol", protocol);
- }
+ pdbentry.setProperty("protocol", protocol);
+
if (pdbentry.getFile() != null)
{
// import structure data from pdbentry.getFile based on given protocol
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;
}
}
- if (entry.getProperty() != null && !entry.getProperty().isEmpty())
+ Enumeration<String> props = entry.getProperties();
+ if (props.hasMoreElements())
{
PdbentryItem item = new PdbentryItem();
- Hashtable properties = entry.getProperty();
- Enumeration en2 = properties.keys();
- while (en2.hasMoreElements())
+ while (props.hasMoreElements())
{
Property prop = new Property();
- String key = en2.nextElement().toString();
+ String key = props.nextElement();
prop.setName(key);
- prop.setValue(properties.get(key).toString());
+ prop.setValue(entry.getProperty(key).toString());
item.addProperty(prop);
}
pdb.addPdbentryItem(item);
}
if (ids[p].getPdbentryItem() != null)
{
- entry.setProperty(new Hashtable());
for (PdbentryItem item : ids[p].getPdbentryItem())
{
for (Property pr : item.getProperty())
{
- entry.getProperty().put(pr.getName(), pr.getValue());
+ entry.setProperty(pr.getName(), pr.getValue());
}
}
}
import java.awt.Color;
import java.io.IOException;
import java.lang.reflect.Constructor;
-import java.util.Hashtable;
import java.util.List;
import java.util.Vector;
{
}
- @SuppressWarnings("rawtypes")
protected SequenceI postProcessChain(PDBChain chain)
{
SequenceI pdbSequence = chain.sequence;
PDBEntry entry = new PDBEntry();
entry.setId(getId());
entry.setType(getStructureFileType());
- entry.setProperty(new Hashtable());
if (chain.id != null)
{
- entry.setChainCode(String.valueOf(chain.id));
+ entry.setChainCode(chain.id);
}
if (inFile != null)
{
// TODO: give a more informative title when multiple structures are
// displayed.
StringBuilder title = new StringBuilder(64);
- final PDBEntry pdbEntry = getPdbEntry(0);
+ final PDBEntry pdbe = getPdbEntry(0);
title.append(viewerName + " view for " + getSequence()[0][0].getName()
- + ":" + pdbEntry.getId());
+ + ":" + pdbe.getId());
if (verbose)
{
- if (pdbEntry.getProperty() != null)
+ String method = (String) pdbe.getProperty("method");
+ if (method != null)
{
- if (pdbEntry.getProperty().get("method") != null)
- {
- title.append(" Method: ");
- title.append(pdbEntry.getProperty().get("method"));
- }
- if (pdbEntry.getProperty().get("chains") != null)
- {
- title.append(" Chain:");
- title.append(pdbEntry.getProperty().get("chains"));
- }
+ title.append(" Method: ").append(method);
+ }
+ String chain = (String) pdbe.getProperty("chains");
+ if (chain != null)
+ {
+ title.append(" Chain:").append(chain);
}
}
return title.toString();
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
-import java.util.Hashtable;
import java.util.List;
import java.util.Map;
import java.util.Set;
PDBEntry pdbr = new PDBEntry();
pdbr.setId(pdbid);
pdbr.setType(PDBEntry.Type.PDB);
- pdbr.setProperty(new Hashtable());
pdbr.setChainCode(chaincode);
- // pdbr.getProperty().put("CHAIN", chaincode);
seq.addPDBId(pdbr);
}
else
if ("EMBL".equals(pdb.getType()))
{
// look for a CDS reference and add it, too.
- String cdsId = (String) pdb.getProperty()
- .get("protein sequence ID");
+ String cdsId = (String) pdb.getProperty("protein sequence ID");
if (cdsId != null && cdsId.trim().length() > 0)
{
// remove version
* <property type="gene ID" value="ENSG00000158828"/>
* </dbReference>
*/
- String cdsId = (String) pdb.getProperty()
- .get("protein sequence ID");
+ String cdsId = (String) pdb.getProperty("protein sequence ID");
if (cdsId != null && cdsId.trim().length() > 0)
{
dbr = new DBRefEntry(DBRefSource.ENSEMBL, DBRefSource.UNIPROT
import jalview.datamodel.PDBEntry.Type;
-import java.util.Hashtable;
-
//import org.testng.Assert;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
assertNotEquals(case9, case10);
// add properties
- case7.getProperty().put("hello", "world");
+ case7.setProperty("hello", "world");
assertNotEquals(case7, case9);
- case9.getProperty().put("hello", "world");
+ case9.setProperty("hello", "world");
assertEquals(case7, case9);
- case9.getProperty().put("hello", "WORLD");
+ case9.setProperty("hello", "WORLD");
assertNotEquals(case7, case9);
/*
* change string wrapper property to string...
*/
- case1.getProperty().put("chain_code", "a");
+ case1.setProperty("chain_code", "a");
assertFalse(pdbEntry.equals(case1));
assertFalse(case1.equals(pdbEntry));
}
*/
pdb1 = new PDBEntry("3A6S", null, null, null);
pdb2 = new PDBEntry("3A6S", null, null, null);
- // ughh properties not null if chain code has been set...
- // JAL-2196 addresses this
- pdb1.properties = new Hashtable();
- pdb2.properties = new Hashtable();
- pdb1.properties.put("destination", "mars");
- pdb1.properties.put("hello", "world");
- pdb2.properties.put("hello", "moon");
- pdb2.properties.put("goodbye", "world");
+ pdb1.setProperty("destination", "mars");
+ pdb1.setProperty("hello", "world");
+ pdb2.setProperty("hello", "moon");
+ pdb2.setProperty("goodbye", "world");
assertTrue(pdb1.updateFrom(pdb2));
- assertEquals(pdb1.properties.get("destination"), "mars");
- assertEquals(pdb1.properties.get("hello"), "moon");
- assertEquals(pdb1.properties.get("goodbye"), "world");
+ assertEquals(pdb1.getProperty("destination"), "mars");
+ assertEquals(pdb1.getProperty("hello"), "moon");
+ assertEquals(pdb1.getProperty("goodbye"), "world");
/*
* add properties only
*/
pdb1 = new PDBEntry("3A6S", null, null, null);
pdb2 = new PDBEntry("3A6S", null, null, null);
- pdb2.properties = new Hashtable();
- pdb2.properties.put("hello", "moon");
+ pdb2.setProperty("hello", "moon");
assertTrue(pdb1.updateFrom(pdb2));
- assertEquals(pdb1.properties.get("hello"), "moon");
+ assertEquals(pdb1.getProperty("hello"), "moon");
}
@Test(groups = { "Functional" })
package jalview.ws.dbsources;
import static org.testng.AssertJUnit.assertEquals;
+import static org.testng.AssertJUnit.assertFalse;
import static org.testng.AssertJUnit.assertNotNull;
import static org.testng.AssertJUnit.assertNull;
PDBEntry xref = xrefs.get(0);
assertEquals("2FSQ", xref.getId());
assertEquals("PDB", xref.getType());
- assertEquals(2, xref.getProperty().size());
- assertEquals("X-ray", xref.getProperty().get("method"));
- assertEquals("1.40", xref.getProperty().get("resolution"));
+ assertEquals("X-ray", xref.getProperty("method"));
+ assertEquals("1.40", xref.getProperty("resolution"));
xref = xrefs.get(1);
assertEquals("2FSR", xref.getId());
assertEquals("PDBsum", xref.getType());
- assertNull(xref.getProperty());
+ assertFalse(xref.getProperties().hasMoreElements());
xref = xrefs.get(2);
assertEquals("AE007869", xref.getId());
assertEquals("EMBL", xref.getType());
- assertNotNull(xref.getProperty());
assertEquals("AAK85932.1",
- (String) xref.getProperty().get("protein sequence ID"));
+ xref.getProperty("protein sequence ID"));
assertEquals("Genomic_DNA",
- (String) xref.getProperty().get("molecule type"));
- assertEquals(2, xref.getProperty().size());
-
+ xref.getProperty("molecule type"));
}
@Test(groups = { "Functional" })