Skip to content

Commit ff5dcc1

Browse files
committed
Use memoization to speed up generation of scientific names on long taxon list
1 parent 0b5ef81 commit ff5dcc1

10 files changed

Lines changed: 32 additions & 284 deletions

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,6 @@ PreCapture.jar
88
target/
99
precapturedebug.log
1010
VESPIDAE_EUMENIDAE_MASARIDAE_authority_file.csv
11-
precapture.log
11+
precapture.log
12+
PRECAPTURE2.trace.db
13+
PRECAPTURE2.mv.db

PRECAPTURE2.h2.db

-922 KB
Binary file not shown.

PRECAPTURE2.trace.db

Lines changed: 0 additions & 203 deletions
This file was deleted.
-300 KB
Binary file not shown.

PRECAPTURE2?characterEncoding=UTF-8.trace.db

Lines changed: 0 additions & 3 deletions
This file was deleted.

PreCaptureApp (1).iml

Lines changed: 0 additions & 62 deletions
This file was deleted.

src/edu/harvard/mcz/precapture/data/UnitTrayLabel.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ public void setTribe(String tribe) {
316316
* @return the scientificName
317317
*/
318318
public String getScientificName() {
319-
if (this.scientificName != null && !this.scientificName.equals("")) {
319+
if (this.scientificName != null && !this.scientificName.trim().equals("")) {
320320
return scientificName;
321321
}
322322
this.scientificName = UnitTrayLabelLifeCycle.getScientificName(this);

src/edu/harvard/mcz/precapture/encoder/LabelEncoder.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -417,17 +417,22 @@ private QrCode getQRCodeMatrix() throws WriterException {
417417
break;
418418
}
419419
String data = label.toJSON();
420-
byte[] compressedStrBytes = data.getBytes(StandardCharsets.UTF_8);
421-
// compress message
420+
boolean compress = false;
421+
if (compress) {
422+
byte[] compressedStrBytes = data.getBytes(StandardCharsets.UTF_8);
423+
// compress message
422424
// try {
423425
// compressedStrBytes = GZipCompressor.compress(data);
424426
// } catch (IOException e) {
425427
// // fallback to uncompressed
426428
// log.error("Failed to compress: " + e.getMessage());
427429
// log.error(e);
428430
// }
429-
// add the bytes to the QR Code
430-
qr_writer.addBytes(compressedStrBytes);
431+
// add the bytes to the QR Code
432+
qr_writer.addBytes(compressedStrBytes);
433+
} else {
434+
qr_writer.addAutomatic(data);
435+
}
431436
return qr_writer.fixate();
432437
}
433438

src/edu/harvard/mcz/precapture/ui/FilteringJComboBox.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,15 @@ public class FilteringJComboBox extends JComboBox implements FocusListener {
4242

4343
private String familyLimit;
4444
private String genusLimit;
45+
private UnitTrayLabelComboBoxModel initialModel;
4546

4647
/**
4748
* Default no argument constructor, constructs a new FilteringJComboBox instance.
4849
*/
4950
public FilteringJComboBox() {
50-
super.setModel(new UnitTrayLabelComboBoxModel());
51+
UnitTrayLabelLifeCycle uls = new UnitTrayLabelLifeCycle();
52+
initialModel = new UnitTrayLabelComboBoxModel(uls.findAll());
53+
super.setModel(initialModel);
5154
init();
5255
}
5356

@@ -90,18 +93,17 @@ public void resetFilter(boolean changePopupState) {
9093
protected void filter(String enteredText, boolean changePopupState) {
9194
if (enteredText == null || enteredText.length() == 0) {
9295
// If entry is blank, show full list.
93-
// TODO: Filter by family/genus.
9496
UnitTrayLabelLifeCycle uls = new UnitTrayLabelLifeCycle();
95-
if (familyLimit == null && genusLimit == null) {
96-
super.setModel(new UnitTrayLabelComboBoxModel(uls.findAll()));
97+
if ((familyLimit == null || familyLimit.length() == 0) && (genusLimit == null || genusLimit.length() == 0)) {
98+
super.setModel(this.initialModel);
9799
} else {
100+
// Filter by family/genus.
98101
UnitTrayLabel pattern = new UnitTrayLabel();
99102
if (familyLimit != null && familyLimit.length() > 0) {
100103
pattern.setFamily(familyLimit);
101-
} else {
102-
if (genusLimit != null && genusLimit.length() > 0) {
103-
pattern.setGenus(genusLimit);
104-
}
104+
}
105+
if (genusLimit != null && genusLimit.length() > 0) {
106+
pattern.setGenus(genusLimit);
105107
}
106108
super.setModel(new UnitTrayLabelComboBoxModel(uls.findByExample(pattern)));
107109
}

src/edu/harvard/mcz/precapture/ui/UnitTrayLabelComboBoxModel.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,11 @@ public int getSize() {
109109
}
110110

111111
public Object getElementAt(int index) {
112-
return UnitTrayLabelLifeCycle.getScientificName(model.get(index));
112+
if (model.get(index) != null) {
113+
return model.get(index).getScientificName();
114+
} else {
115+
return null;
116+
}
113117
}
114118

115119
/**
@@ -131,7 +135,10 @@ public void removeListDataListener(ListDataListener l) {
131135
}
132136

133137
public Object getSelectedItem() {
134-
return UnitTrayLabelLifeCycle.getScientificName(selectedItem);
138+
if (selectedItem != null) {
139+
return selectedItem.getScientificName();
140+
}
141+
return null;
135142
}
136143

137144
public void setSelectedItem(Object anItem) {

0 commit comments

Comments
 (0)