Skip to content

Commit cbde02d

Browse files
committed
Clearing ChemComp cache whenever provider changes
This avoids requiring the user to manually clear the cache, so the cache no longer needs to be publically exposed.
1 parent 649a05b commit cbde02d

3 files changed

Lines changed: 7 additions & 17 deletions

File tree

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

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,8 @@ public static ChemComp getChemComp(String recordName){
5757
logger.debug("Chem comp "+recordName+" read from provider "+chemCompProvider.getClass().getCanonicalName());
5858
cc = chemCompProvider.getChemComp(recordName);
5959

60-
// If chemCompProvider fails don't try to cache null & one letter code may be null.
61-
if (null != cc && !cc.isEmpty()){
62-
cache.put(recordName, cc);
63-
}
60+
// Note that this also caches null or empty responses
61+
cache.put(recordName, cc);
6462
return cc;
6563
}
6664

@@ -79,6 +77,8 @@ public static ChemComp getChemComp(String recordName){
7977
public static void setChemCompProvider(ChemCompProvider provider) {
8078
logger.debug("Setting new chem comp provider to "+provider.getClass().getCanonicalName());
8179
chemCompProvider = provider;
80+
// clear cache
81+
cache.clear();
8282
}
8383

8484
public static ChemCompProvider getChemCompProvider(){
@@ -154,9 +154,4 @@ public static String getOneLetterCode(ChemComp cc){
154154
return oneLetter;
155155
}
156156

157-
public static SoftHashMap<String, ChemComp> getCache() {
158-
return cache;
159-
}
160-
161-
162157
}

biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/ChemComp.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ public static ChemComp getEmptyChemComp(){
594594
ChemComp comp = new ChemComp();
595595

596596
comp.setOne_letter_code("?");
597-
comp.setThree_letter_code("???");
597+
comp.setThree_letter_code("???"); // Main signal for isEmpty()
598598
comp.setPolymerType(PolymerType.unknown);
599599
comp.setResidueType(ResidueType.atomn);
600600
return comp;
@@ -606,7 +606,7 @@ public static ChemComp getEmptyChemComp(){
606606
*/
607607
public boolean isEmpty() {
608608
// Is this the best flag for it being empty?
609-
return id == null || getThree_letter_code().equals("???");
609+
return id == null || getThree_letter_code() == null || getThree_letter_code().equals("???");
610610
}
611611

612612
}

biojava-structure/src/test/java/org/biojava/nbio/structure/ChemCompTest.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,6 @@ public void testPRR(){
117117
@Test
118118
public void testChangingProviders(){
119119

120-
//reset the cache
121-
SoftHashMap<String, ChemComp> cache = ChemCompGroupFactory.getCache();
122-
cache.clear();
123-
124120
// test for issue #145
125121

126122
String chemID = "MEA";
@@ -134,7 +130,7 @@ public void testChangingProviders(){
134130

135131
assertTrue(" is not mea" , cc.getId().equals(chemID));
136132

137-
assertNull(cc.getThree_letter_code());
133+
assertTrue(cc.isEmpty());
138134

139135
// now we change to download chem comp provider
140136

@@ -151,7 +147,6 @@ public void testChangingProviders(){
151147

152148

153149
// now testing in opposite order
154-
cache.clear();
155150

156151
// first we test with download chem comp provider
157152

0 commit comments

Comments
 (0)