Skip to content

Commit 385542a

Browse files
Minor auto-refactor code cleanup on a massive scale (#964)
* Minor auto-refactor code cleanup on a massive scale * Avoid calling isEmpty() on JS arrays
1 parent 074fe0c commit 385542a

138 files changed

Lines changed: 445 additions & 605 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

EHR_App/test/src/org/labkey/test/tests/EHRAppTestSetupHelper.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import java.io.File;
1414
import java.io.IOException;
1515
import java.util.Arrays;
16-
import java.util.Collections;
1716
import java.util.List;
1817
import java.util.Map;
1918
import java.util.Objects;

EHR_App/test/src/org/labkey/test/tests/EHR_AppTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ protected File getStudyPolicyXML()
7474
@BeforeClass
7575
public static void setupProject() throws Exception
7676
{
77-
EHR_AppTest init = (EHR_AppTest) getCurrentTest();
77+
EHR_AppTest init = getCurrentTest();
7878
init.doSetup();
7979
}
8080

EHR_ComplianceDB/src/org/labkey/ehr_compliancedb/notification/EmployeeComplianceNotification.java

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,10 @@
1515
*/
1616
package org.labkey.ehr_compliancedb.notification;
1717

18-
import org.jetbrains.annotations.Nullable;
1918
import org.labkey.api.data.Container;
2019
import org.apache.commons.lang3.time.DateUtils;
21-
import org.labkey.api.module.ModuleLoader;
22-
import org.labkey.api.module.Module;
2320
import org.labkey.api.data.CompareType;
24-
import org.labkey.api.data.Results;
2521
import org.labkey.api.data.ColumnInfo;
26-
import org.labkey.api.data.ResultsImpl;
2722
import org.labkey.api.data.Selector;
2823
import org.labkey.api.data.SimpleFilter;
2924
import org.labkey.api.data.Sort;
@@ -36,20 +31,15 @@
3631
import org.labkey.api.query.UserSchema;
3732
import org.labkey.api.ldk.notification.AbstractNotification;
3833
import org.labkey.api.util.DateUtil;
39-
import org.labkey.ehr_compliancedb.EHR_ComplianceDBModule;
40-
import org.labkey.ehr_compliancedb.EHR_ComplianceDBUserSchema;
4134

4235

43-
import java.util.Date;
4436
import java.sql.ResultSet;
4537
import java.sql.SQLException;
4638
import java.util.Calendar;
4739
import java.util.Date;
48-
import java.util.HashMap;
4940
import java.util.HashSet;
5041
import java.util.Map;
5142
import java.util.Set;
52-
import java.util.TreeMap;
5343

5444
//Added 3-29-2016 Blasa
5545

@@ -153,12 +143,12 @@ private void EmployeeComplianceNotification(Container c, User u, final StringBui
153143
msg.append("<tr style='font-weight: bold;'><td>Employee ID</td><td>First Name</td><td>Last Name</td><td>Category</td><td>Unit</td><td>Supervisor</td><td>Location</td></tr>\n");
154144

155145

156-
ts.forEach(new Selector.ForEachBlock<ResultSet>()
146+
ts.forEach(new Selector.ForEachBlock<>()
157147
{
158148
@Override
159149
public void exec(ResultSet rs) throws SQLException
160150
{
161-
msg.append("<tr><td>" + (rs.getString("employeeid") == null ? "" : rs.getString("employeeid")) + "</td><td>" + rs.getString("firstName") + "</td><td>" + rs.getString("lastName") + "</td><td>" + rs.getString("category") + "</td><td>" + rs.getString("unit") + "</td><td>" + rs.getString("supervisor") + "</td><td>" + rs.getString("location")+ "</td></tr>\n");
151+
msg.append("<tr><td>" + (rs.getString("employeeid") == null ? "" : rs.getString("employeeid")) + "</td><td>" + rs.getString("firstName") + "</td><td>" + rs.getString("lastName") + "</td><td>" + rs.getString("category") + "</td><td>" + rs.getString("unit") + "</td><td>" + rs.getString("supervisor") + "</td><td>" + rs.getString("location") + "</td></tr>\n");
162152

163153
}
164154
});

EHR_Purchasing/src/org/labkey/ehr_purchasing/EHR_PurchasingController.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,15 @@ public EHR_PurchasingController()
3636
}
3737

3838
@RequiresPermission(ReadPermission.class)
39-
public class BeginAction extends SimpleViewAction
39+
public static class BeginAction extends SimpleViewAction<Object>
4040
{
41+
@Override
4142
public ModelAndView getView(Object o, BindException errors)
4243
{
43-
return new JspView("/org/labkey/ehr_purchasing/view/hello.jsp");
44+
return new JspView<>("/org/labkey/ehr_purchasing/view/hello.jsp");
4445
}
4546

47+
@Override
4648
public void addNavTrail(NavTree root) { }
4749
}
4850
}

EHR_SM/src/org/labkey/ehr_sm/EHR_SMController.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,17 @@ public EHR_SMController()
4848
}
4949

5050
@RequiresPermission(ReadPermission.class)
51-
public class BeginAction extends SimpleViewAction
51+
public static class BeginAction extends SimpleViewAction<Object>
5252
{
53+
@Override
5354
public ModelAndView getView(Object o, BindException errors)
5455
{
5556
JspView<Void> view = new JspView<>("/org/labkey/ehr_sm/view/hello.jsp");
5657
view.setTitle("EHR Sample Manager");
5758
return view;
5859
}
5960

61+
@Override
6062
public void addNavTrail(NavTree root) { }
6163
}
6264

@@ -100,6 +102,7 @@ public void setSelectedAnimalSampleTypes(String[] selectedAnimalSampleTypes)
100102
@RequiresPermission(AdminPermission.class)
101103
public class AdminAction extends FormViewAction<AdminForm>
102104
{
105+
@Override
103106
public void addNavTrail(NavTree root) { }
104107

105108
@Override

EHR_SM/test/src/org/labkey/test/tests/ehr_sm/EHR_SMTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ protected void doCleanup(boolean afterTest) throws TestTimeoutException
4242
@BeforeClass
4343
public static void setupProject()
4444
{
45-
EHR_SMTest init = (EHR_SMTest)getCurrentTest();
45+
EHR_SMTest init = getCurrentTest();
4646

4747
init.doSetup();
4848
}

Viral_Load_Assay/src/org/labkey/viral_load_assay/assay/ABI7500ImportMethod.java

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ public JSONObject getMetadata(ViewContext ctx, ExpProtocol protocol)
162162
return meta;
163163
}
164164

165-
private class Parser extends DefaultAssayParser
165+
private static class Parser extends DefaultAssayParser
166166
{
167167
private final Double CYCLE_LIMIT = 45.0;
168168
private static final String TASK_FIELD = "Task";
@@ -178,7 +178,7 @@ public Parser(AssayImportMethod method, Container c, User u, int assayId)
178178
@Override
179179
public Pair<ExpExperiment, ExpRun> saveBatch(JSONObject json, File file, String fileName, ViewContext ctx) throws BatchValidationException
180180
{
181-
Integer templateId = json.getInt("TemplateId");
181+
int templateId = json.getInt("TemplateId");
182182

183183
Pair<ExpExperiment, ExpRun> result = super.saveBatch(json, file, fileName, ctx);
184184

@@ -217,7 +217,7 @@ protected String readRawFile(ImportContext context) throws BatchValidationExcept
217217

218218
if (!inResults)
219219
{
220-
if (row.size() == 0)
220+
if (row.isEmpty())
221221
continue;
222222

223223
if (row.get(0).equals("Detector Name"))
@@ -229,7 +229,7 @@ protected String readRawFile(ImportContext context) throws BatchValidationExcept
229229
if (inDetectors)
230230
{
231231
String detector = row.get(0);
232-
Map<String, Double> map = new HashMap<String, Double>();
232+
Map<String, Double> map = new HashMap<>();
233233
map.put("slope", Double.parseDouble(row.get(1)));
234234
map.put("intercept", Double.parseDouble(row.get(2)));
235235
map.put("rSquared", Double.parseDouble(row.get(3)));
@@ -262,7 +262,7 @@ else if (row.get(0).startsWith("Document Name:"))
262262
}
263263
else
264264
{
265-
out.writeNext(row.toArray(new String[row.size()]));
265+
out.writeNext(row.toArray(new String[0]));
266266
}
267267
}
268268

@@ -284,7 +284,7 @@ else if (row.get(0).startsWith("Document Name:"))
284284
@Override
285285
protected List<Map<String, Object>> processRowsFromFile(List<Map<String, Object>> rows, ImportContext context) throws BatchValidationException
286286
{
287-
List<Map<String, Object>> newRows = new ArrayList<Map<String, Object>>();
287+
List<Map<String, Object>> newRows = new ArrayList<>();
288288
ParserErrors errors = context.getErrors();
289289

290290
//add slope to run info
@@ -308,7 +308,7 @@ protected List<Map<String, Object>> processRowsFromFile(List<Map<String, Object>
308308
{
309309
rowIdx++;
310310
Map<String, Object> row = rowsIter.next();
311-
Map<String, Object> map = new CaseInsensitiveHashMap<Object>(row);
311+
Map<String, Object> map = new CaseInsensitiveHashMap<>(row);
312312

313313
if (row.size() != 9)
314314
{
@@ -444,7 +444,7 @@ private void calculateViralLoad(Map<String, Object> map, Double limitOfDetection
444444
{
445445
Map<String, Double> detectorInfo = _detectorMap.get(map.get(DETECTOR_FIELD));
446446
Double ct = map.get("cp") == null ? null : Double.parseDouble(map.get("cp").toString());
447-
Double sampleVol = Double.parseDouble(String.valueOf(map.get("sampleVol")));
447+
double sampleVol = Double.parseDouble(String.valueOf(map.get("sampleVol")));
448448
Double intercept = detectorInfo.get("intercept");
449449
Double slope = detectorInfo.get("slope");
450450
Double volPerRxn = Double.parseDouble(String.valueOf(map.get("volPerRxn")));
@@ -463,14 +463,14 @@ private void calculateViralLoad(Map<String, Object> map, Double limitOfDetection
463463

464464
private void calculateViralLoads(List<Map<String, Object>> rows)
465465
{
466-
Map<String, List<Map<String, Object>>> rowMap = new HashMap<String, List<Map<String, Object>>>();
466+
Map<String, List<Map<String, Object>>> rowMap = new HashMap<>();
467467
Double lowestStd = 0.0;
468468
for (Map<String, Object> row : rows)
469469
{
470470
String key = (String)row.get(NAME_FIELD);
471471
List<Map<String, Object>> list = rowMap.get(key);
472472
if (list == null)
473-
list = new ArrayList<Map<String, Object>>();
473+
list = new ArrayList<>();
474474

475475
if (TYPE.Standard.getTemplateText().equals(row.get(CATEGORY_FIELD)))
476476
{
@@ -505,7 +505,7 @@ private void calculateViralLoads(List<Map<String, Object>> rows)
505505

506506
avgCopies = avgCopies / list.size();
507507
Double stdDev = new StandardDeviation().evaluate(values);
508-
Double cv = stdDev / avgCopies;
508+
double cv = stdDev / avgCopies;
509509

510510
//NOTE: at some point I should make this configurable
511511
//flag any record with %CV > 66, but only if at least 1 replicate has copies/rxn above limitOfDetection
@@ -573,14 +573,14 @@ public void doGenerateTemplate(JSONObject json, HttpServletRequest request, Http
573573
response.setHeader("Pragma", "private");
574574
response.setHeader("Cache-Control", "private");
575575

576-
Map<Integer, String[]> rowMap = new HashMap<Integer, String[]>();
576+
Map<Integer, String[]> rowMap = new HashMap<>();
577577

578578
int rowIdx = 0;
579579
for (JSONObject row : results)
580580
{
581581
rowIdx++;
582582

583-
List<String> fields = new ArrayList<String>();
583+
List<String> fields = new ArrayList<>();
584584

585585
//build the row
586586
Integer wellNum = (Integer)wellMap.get(row.getString("well"));
@@ -594,13 +594,13 @@ public void doGenerateTemplate(JSONObject json, HttpServletRequest request, Http
594594
fields.add(type.getTemplateText());
595595
fields.add(TYPE.getQuantity(type, row.getString(SUBJECT_FIELD)));
596596

597-
rowMap.put(wellNum, fields.toArray(new String[fields.size()]));
597+
rowMap.put(wellNum, fields.toArray(new String[0]));
598598
}
599599

600600
if (errors.hasErrors())
601601
throw errors;
602602

603-
List<String[]> rows = new ArrayList<String[]>();
603+
List<String[]> rows = new ArrayList<>();
604604
rows.add(new String[]{"*** SDS Setup File Version", "3"});
605605
rows.add(new String[]{"*** Output Plate Size", "96"});
606606
rows.add(new String[]{"*** Output Plate ID", json.getString("templateName") + ".sds"});
@@ -642,21 +642,21 @@ public void doGenerateTemplate(JSONObject json, HttpServletRequest request, Http
642642

643643
private Map<String, Map<String, String>> getDetectorsForResults(List<JSONObject> results)
644644
{
645-
final Map<String, Map<String, String>> ret = new HashMap<String, Map<String, String>>();
646-
Set<String> distinctAssays = new HashSet<String>();
645+
final Map<String, Map<String, String>> ret = new HashMap<>();
646+
Set<String> distinctAssays = new HashSet<>();
647647
for (JSONObject row : results)
648648
{
649649
distinctAssays.add(row.getString(ASSAYNAME_FIELD));
650650
}
651651

652652
TableInfo table = Viral_Load_AssaySchema.getInstance().getSchema().getTable(Viral_Load_AssaySchema.TABLE_ABI7500_DETECTORS);
653653
TableSelector ts = new TableSelector(table, new SimpleFilter(FieldKey.fromString("assayName"), distinctAssays, CompareType.IN), null);
654-
ts.forEach(new Selector.ForEachBlock<ResultSet>()
654+
ts.forEach(new Selector.ForEachBlock<>()
655655
{
656656
@Override
657657
public void exec(ResultSet object) throws SQLException
658658
{
659-
Map<String, String> row = new HashMap<String, String>();
659+
Map<String, String> row = new HashMap<>();
660660
row.put("detector", object.getString("detector"));
661661
row.put("reporter", object.getString("reporter"));
662662
row.put("quencher", object.getString("quencher"));
@@ -673,8 +673,8 @@ public void validateTemplate(User u, Container c, ExpProtocol protocol, @Nullabl
673673
//ensure each subject/date has at least 2 neg controls
674674
JSONObject resultDefaults = json.optJSONObject("Results");
675675
JSONArray rawResults = json.getJSONArray("ResultRows");
676-
List<JSONObject> results = new ArrayList<JSONObject>();
677-
Set<String> distinctWells = new HashSet<String>();
676+
List<JSONObject> results = new ArrayList<>();
677+
Set<String> distinctWells = new HashSet<>();
678678
Map<Object, Object> wellMap = getWellMap96("well_96", "addressbyrow_96");
679679

680680
String[] requiredFields = new String[]{"well", SUBJECT_FIELD, CATEGORY_FIELD, ASSAYNAME_FIELD};
@@ -710,7 +710,7 @@ public void validateTemplate(User u, Container c, ExpProtocol protocol, @Nullabl
710710
if (missingRequired)
711711
continue;
712712

713-
TYPE type = null;
713+
TYPE type;
714714
try
715715
{
716716
type = TYPE.getByDatabaseCategoryValue(row.getString(CATEGORY_FIELD));
@@ -782,7 +782,7 @@ public void validateTemplate(User u, Container c, ExpProtocol protocol, @Nullabl
782782
}
783783

784784
Map<String, Map<String, String>> detectorRows = getDetectorsForResults(results);
785-
if (detectorRows.size() == 0)
785+
if (detectorRows.isEmpty())
786786
{
787787
errors.addRowError(new ValidationException("No detectors were found for these samples."));
788788
throw errors;

Viral_Load_Assay/src/org/labkey/viral_load_assay/assay/AbstractWNPRCImportMethod.java

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -401,10 +401,10 @@ protected void calculateViralLoadForRoche(Map<String, Object> map)
401401
map.put("sampleVol", 1.0);
402402

403403
//This is the size (ml or mg) of the source material (plasma/serum/urine/etc.)
404-
Double sampleVol = Double.parseDouble(map.get("sampleVol").toString());
404+
double sampleVol = Double.parseDouble(map.get("sampleVol").toString());
405405

406-
Double viralLoad = 0.0;
407-
Double dilutionFactor = 0.0;
406+
double viralLoad = 0.0;
407+
double dilutionFactor = 0.0;
408408
if (copiesPerRxn != null && sampleVol > 0)
409409
{
410410
dilutionFactor = (1.0 / sampleVol) * (eluateVol / volPerRxn);
@@ -417,8 +417,8 @@ protected void calculateViralLoadForRoche(Map<String, Object> map)
417417
}
418418

419419
protected class Parser extends DefaultAssayParser {
420-
private String HAS_RESULT = "__hasResult__";
421-
private int _assayId;
420+
private final String HAS_RESULT = "__hasResult__";
421+
private final int _assayId;
422422
final String[] lookup = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ,.".split("");
423423
//The expected number of columns in the import data
424424
private int _expectedColumnCount = Integer.MAX_VALUE;
@@ -444,6 +444,7 @@ public Pair<ExpExperiment, ExpRun> saveBatch(JSONObject json, File file, String
444444
}
445445

446446
//Needs to be overridden within the Parser class of each ImportMethod that extends AbstractWNPRCImportMethod
447+
@Override
447448
protected TabLoader getTabLoader(String contents) throws IOException {
448449
return null;
449450
}
@@ -531,6 +532,7 @@ protected List<Map<String, Object>> processRowsFromFile(List<Map<String, Object>
531532
return newRows;
532533
}
533534

535+
@Override
534536
protected void ensureTemplateRowsHaveResults(Map<String, Map<String, Object>> templateRows, ImportContext context) throws BatchValidationException {
535537
for (String key : templateRows.keySet()) {
536538
Map<String, Object> row = templateRows.get(key);
@@ -563,7 +565,7 @@ private String uncompressUUID(String compressObjectId) {
563565
else if (hexString.length() == 2) {
564566
hexString = "0" + hexString;
565567
}
566-
else if (hexString.length() == 0) {
568+
else if (hexString.isEmpty()) {
567569
hexString = "000" + hexString;
568570
}
569571

@@ -577,19 +579,17 @@ else if (hexString.length() == 0) {
577579
}
578580
char[] objectId = base16Duples.toString().toCharArray();
579581

580-
StringBuilder returnObjectId = new StringBuilder();
581-
582-
returnObjectId.append(objectId, 0, 8);
583-
returnObjectId.append("-");
584-
returnObjectId.append(objectId, 8, 4);
585-
returnObjectId.append("-");
586-
returnObjectId.append(objectId, 12, 4);
587-
returnObjectId.append("-");
588-
returnObjectId.append(objectId, 16, 4);
589-
returnObjectId.append("-");
590-
returnObjectId.append(objectId, 20, 12);
591-
592-
return returnObjectId.toString();
582+
String returnObjectId = String.valueOf(objectId, 0, 8) +
583+
"-" +
584+
String.valueOf(objectId, 8, 4) +
585+
"-" +
586+
String.valueOf(objectId, 12, 4) +
587+
"-" +
588+
String.valueOf(objectId, 16, 4) +
589+
"-" +
590+
String.valueOf(objectId, 20, 12);
591+
592+
return returnObjectId;
593593
}
594594
}
595595

Viral_Load_Assay/src/org/labkey/viral_load_assay/assay/DefaultVLImportMethod.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ protected void calculateViralLoadForRoche(Map<String, Object> map)
157157
if (!map.containsKey("sampleVol"))
158158
map.put("sampleVol", 1.0);
159159

160-
Double sampleVol = Double.parseDouble(map.get("sampleVol").toString());
160+
double sampleVol = Double.parseDouble(map.get("sampleVol").toString());
161161

162162
double viralLoad;
163163
if (copiesPerRxn != null)

0 commit comments

Comments
 (0)