Skip to content

Commit 3f2c4ac

Browse files
committed
now without (or few) loops
1 parent ad751de commit 3f2c4ac

File tree

1 file changed

+32
-0
lines changed
  • biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/chem

1 file changed

+32
-0
lines changed

biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/chem/ResidueType.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
package org.biojava.nbio.structure.io.mmcif.chem;
2323

2424
import java.io.Serializable;
25+
import java.util.HashMap;
26+
import java.util.Map;
2527

2628

2729
/**
@@ -72,10 +74,21 @@ public enum ResidueType implements Serializable {
7274
nonPolymer(null, "non-polymer"),
7375
otherChemComp(null, "other");
7476

77+
78+
static Map<String,ResidueType> lookupTable = new HashMap<>();
79+
80+
static {
81+
82+
for (ResidueType rt : ResidueType.values() ) {
83+
lookupTable.put(rt.chem_comp_type,rt);
84+
lookupTable.put(rt.chem_comp_type.toLowerCase(),rt);
85+
}
86+
}
7587
ResidueType(PolymerType pt, String chem_comp_type)
7688
{
7789
this.polymerType = pt;
7890
this.chem_comp_type = chem_comp_type;
91+
7992
}
8093

8194
/**
@@ -94,9 +107,28 @@ public enum ResidueType implements Serializable {
94107
*/
95108
public final String chem_comp_type;
96109

110+
/** Get ResidueType by chem_comp_type
111+
*
112+
* @param chem_comp_type e.g. L-peptide linking
113+
* @return
114+
*/
97115
public static ResidueType getResidueTypeFromString(String chem_comp_type)
98116
{
99117

118+
ResidueType rtype = lookupTable.get(chem_comp_type);
119+
if ( rtype != null)
120+
return rtype;
121+
122+
/** Unfortunately it can be guaranteed that chem_comp_type case sensitivity is preserved.
123+
* E.g. mmtf has it all upper-case. As such we need to do a second check
124+
*
125+
*/
126+
rtype = lookupTable.get(chem_comp_type.toLowerCase());
127+
if ( rtype != null)
128+
return rtype;
129+
130+
131+
100132
for(ResidueType rt : ResidueType.values())
101133
{
102134
if(rt.chem_comp_type.equalsIgnoreCase(chem_comp_type))

0 commit comments

Comments
 (0)