From: Jim Procter Date: Sun, 4 Sep 2016 12:13:46 +0000 (+0100) Subject: JAL-1803 chainCode moved onto property hashtable as chain_code X-Git-Tag: Release_2_10_0~47^2~4^2~19 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=24e0210e437c1dcfd36dd0080613327284c76b8e;p=jalview.git JAL-1803 chainCode moved onto property hashtable as chain_code --- diff --git a/src/jalview/datamodel/PDBEntry.java b/src/jalview/datamodel/PDBEntry.java index 1c7df49..673c12a 100755 --- a/src/jalview/datamodel/PDBEntry.java +++ b/src/jalview/datamodel/PDBEntry.java @@ -30,13 +30,69 @@ public class PDBEntry private String id; - private String chainCode; - public enum Type { - PDB, MMCIF, FILE + PDB, MMCIF, FILE; + /** + * case insensitive matching for Type enum + * + * @param value + * @return + */ + public static Type getType(String value) + { + for (Type t : Type.values()) + { + if (t.toString().equalsIgnoreCase(value)) + { + return t; + } + } + return null; + } + + /** + * case insensitive equivalence for strings resolving to PDBEntry type + * + * @param t + * @return + */ + public boolean matches(String t) + { + return (this.toString().equalsIgnoreCase(t)); + } } + 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; /* @@ -60,9 +116,6 @@ public class PDBEntry .equals(type))) && (id == o.id || (id != null && o.id != null && o.id .equalsIgnoreCase(id))) - && (chainCode == o.chainCode || (chainCode != null - && o.chainCode != null && o.chainCode - .equalsIgnoreCase(chainCode))) && (properties == o.properties || (properties != null && o.properties != null && properties .equals(o.properties))); @@ -91,9 +144,9 @@ public class PDBEntry String filePath) { this.id = pdbId; - this.chainCode = chain; this.type = type == null ? null : type.toString(); this.file = filePath; + setChainCode(chain); } /** @@ -106,7 +159,6 @@ public class PDBEntry file = entry.file; type = entry.type; id = entry.id; - chainCode = entry.chainCode; if (entry.properties != null) { properties = (Hashtable) entry.properties.clone(); @@ -158,14 +210,34 @@ public class PDBEntry return properties; } + /** + * + * @return null or a string for associated chain IDs + */ public String getChainCode() { - return chainCode; + return (properties == null || properties.get(CHAIN_ID) == null) ? null + : properties.get(CHAIN_ID).toString(); } public void setChainCode(String chainCode) { - this.chainCode = 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 ChainId(chainCode)); } @Override