Skip to content

Commit 23dbaa4

Browse files
Minor auto-refactor code cleanup on a massive scale (#166)
1 parent d55a9a1 commit 23dbaa4

30 files changed

+103
-105
lines changed

OConnorExperiments/src/org/labkey/oconnorexperiments/OConnorExperimentsController.java

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package org.labkey.oconnorexperiments;
1818

1919
import org.apache.commons.io.FileUtils;
20-
import org.apache.logging.log4j.Logger;
2120
import org.apache.logging.log4j.LogManager;
2221
import org.labkey.api.action.ApiResponse;
2322
import org.labkey.api.action.ApiSimpleResponse;
@@ -93,7 +92,7 @@ public OConnorExperimentsController()
9392
}
9493

9594
@RequiresPermission(ReadPermission.class)
96-
public class BeginAction extends SimpleViewAction
95+
public static class BeginAction extends SimpleViewAction<Object>
9796
{
9897
@Override
9998
public ModelAndView getView(Object o, BindException errors)
@@ -108,7 +107,7 @@ public void addNavTrail(NavTree root)
108107
}
109108

110109
@RequiresPermission(AdminPermission.class)
111-
public class MigrateDataAction extends FormViewAction<UserForm>
110+
public static class MigrateDataAction extends FormViewAction<UserForm>
112111
{
113112
@Override
114113
public void validateCommand(UserForm target, Errors errors)
@@ -234,7 +233,7 @@ public boolean handlePost(UserForm form, BindException errors) throws Exception
234233
// Move files
235234
File sourceFile = new File(fileContentService.getFileRoot(sourceContainer).getPath() + File.separator + "@files", databaseMap.get("expnumber").toString());
236235
File targetDir = new File(fileContentService.getFileRoot(targetContainer).getPath() + File.separator + databaseMap.get("expnumber").toString() + File.separator + "@files");
237-
LogManager.getLogger(OConnorExperimentsController.class).info("Copy from file '" + sourceFile.toString() + "' to directory '" + targetDir.toString() +"'" );
236+
LogManager.getLogger(OConnorExperimentsController.class).info("Copy from file '" + sourceFile + "' to directory '" + targetDir +"'" );
238237
if (sourceFile.exists())
239238
{
240239
FileUtils.copyDirectory(sourceFile, targetDir);
@@ -258,7 +257,7 @@ public boolean handlePost(UserForm form, BindException errors) throws Exception
258257
Map<String, Object> map = new CaseInsensitiveHashMap<>();
259258
map.put("container", databaseMap.get("ContainerStr"));
260259

261-
String[] parents = new String[0];
260+
String[] parents;
262261
ArrayList<String> parentsEntityId = new ArrayList<>();
263262
if (databaseMap.get("expParent") != null)
264263
{
@@ -280,9 +279,9 @@ public boolean handlePost(UserForm form, BindException errors) throws Exception
280279
}
281280
}
282281
}
283-
if (parentsEntityId.size() > 0)
282+
if (!parentsEntityId.isEmpty())
284283
{
285-
map.put("ParentExperiments", parentsEntityId.toArray(new String[parentsEntityId.size()]));
284+
map.put("ParentExperiments", parentsEntityId.toArray(new String[0]));
286285

287286
// workaround, pass user, container - databaseMap.get("Container"), singleton list
288287
LogManager.getLogger(OConnorExperimentsController.class).info("Update rows on experiment " + databaseMap.get("expnumber"));
@@ -423,7 +422,7 @@ public void setFinalMigration(boolean finalMigration)
423422
*/
424423
@RequiresLogin
425424
@RequiresPermission(InsertPermission.class)
426-
public class InsertExperimentAction extends FormHandlerAction
425+
public static class InsertExperimentAction extends FormHandlerAction<Object>
427426
{
428427
private Container newExperiment;
429428

@@ -465,7 +464,7 @@ public boolean handlePost(Object o, BindException errors) throws Exception
465464

466465
@RequiresLogin
467466
@RequiresPermission(ReadPermission.class)
468-
public class GetExperimentAction extends ReadOnlyApiAction
467+
public static class GetExperimentAction extends ReadOnlyApiAction<Object>
469468
{
470469
@Override
471470
public ApiResponse execute(Object o, BindException errors) throws Exception
@@ -474,7 +473,7 @@ public ApiResponse execute(Object o, BindException errors) throws Exception
474473
TableInfo table = schema.getTable(OConnorExperimentsUserSchema.Table.Experiments.name());
475474
QueryUpdateService qus = table.getUpdateService();
476475

477-
List<Map<String, Object>> pks = Collections.singletonList(Collections.singletonMap("Container", (Object)getContainer().getId()));
476+
List<Map<String, Object>> pks = Collections.singletonList(Collections.singletonMap("Container", getContainer().getId()));
478477
List<Map<String, Object>> result = qus.getRows(getUser(), getContainer(), pks);
479478

480479
ApiSimpleResponse resp = new ApiSimpleResponse();
@@ -495,14 +494,14 @@ public ApiResponse execute(Object o, BindException errors) throws Exception
495494
}
496495

497496
@RequiresPermission(UpdatePermission.class)
498-
public class HistoryAction extends SimpleViewAction
497+
public static class HistoryAction extends SimpleViewAction<Object>
499498
{
500499
@Override
501500
public ModelAndView getView(Object o, BindException errors)
502501
{
503502
getPageConfig().setNoIndex();
504503
getPageConfig().setNoFollow();
505-
return new JspView("/org/labkey/oconnorexperiments/view/history.jsp", null, errors);
504+
return new JspView<>("/org/labkey/oconnorexperiments/view/history.jsp", null, errors);
506505
}
507506

508507
@Override
@@ -528,7 +527,7 @@ public void setId(String id)
528527
}
529528

530529
@RequiresPermission(ReadPermission.class)
531-
public class LookupWorkbookAction extends SimpleViewAction<LookupWorkbookForm>
530+
public static class LookupWorkbookAction extends SimpleViewAction<LookupWorkbookForm>
532531
{
533532
@Override
534533
public ModelAndView getView(LookupWorkbookForm form, BindException errors)

OConnorExperiments/src/org/labkey/oconnorexperiments/OConnorExperimentsModule.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public Set<String> getSchemaNames()
128128
}
129129

130130
// Listener that just updates the experiment changed date when a wiki is modified.
131-
private class OConnorWikiChangeListener implements WikiChangeListener
131+
private static class OConnorWikiChangeListener implements WikiChangeListener
132132
{
133133
@Override
134134
public void wikiCreated(User user, Container c, String name)
@@ -150,7 +150,7 @@ public void wikiDeleted(User user, Container c, String name)
150150
}
151151

152152
// Listener that just updates the experiment changed date when a file is uploaded/renamed.
153-
private class OConnorFileChangeListener implements FileListener
153+
private static class OConnorFileChangeListener implements FileListener
154154
{
155155
@Override
156156
public void fileCreated(@NotNull File created, @Nullable User user, @Nullable Container container)

OConnorExperiments/src/org/labkey/oconnorexperiments/query/ExperimentsTable.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ public boolean next() throws BatchValidationException
505505
}
506506

507507
Collection<String> parentExperiments = (Collection<String>)o;
508-
if (parentExperiments.size() == 0)
508+
if (parentExperiments.isEmpty())
509509
return true;
510510

511511
// Validate each ParentExperiment is a workbook and create list of maps for insertion

OConnorExperiments/test/src/org/labkey/test/tests/OConnorExperimentTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public class OConnorExperimentTest extends BaseWebDriverTest implements Postgres
6464
private static final String TABLE_NAME = "Experiments";
6565
private static final String EXPERIMENT_TYPE_TABLE_NAME = "ExperimentType";
6666
private static final String EXPERIMENT_SAVE_SIGNAL = "experimentDataSave"; // See experimentField.html
67-
private ArrayList<String> pkeys = new ArrayList<>();
67+
private final ArrayList<String> pkeys = new ArrayList<>();
6868

6969
@Nullable
7070
@Override
@@ -327,7 +327,7 @@ protected void deleteViaJavaApi()
327327
DeleteRowsCommand cmd = new DeleteRowsCommand(SCHEMA_NAME, TABLE_NAME);
328328
Connection cn = WebTestHelper.getRemoteApiConnection();
329329
for (String pk : pkeys)
330-
cmd.addRow(Collections.singletonMap("container", (Object) pk));
330+
cmd.addRow(Collections.singletonMap("container", pk));
331331

332332
SaveRowsResponse resp = cmd.execute(cn, getProjectName());
333333
assertEquals("Expected to delete " + pkeys.size() + " rows", pkeys.size(), resp.getRowsAffected().intValue());

OConnorExperiments/test/src/org/labkey/test/tests/OConnorListTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public List<String> getAssociatedModules()
7070
@LogMethod
7171
public static void setup()
7272
{
73-
OConnorListTest initTest = (OConnorListTest)getCurrentTest();
73+
OConnorListTest initTest = getCurrentTest();
7474
initTest.setupOConnorProject();
7575
}
7676

genotyping/src/org/labkey/genotyping/GenotypingController.java

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ public GenotypingController()
154154
}
155155

156156
@RequiresPermission(ReadPermission.class)
157-
public class BeginAction extends SimpleRedirectAction
157+
public static class BeginAction extends SimpleRedirectAction<Object>
158158
{
159159
@Override
160160
public ActionURL getRedirectURL(Object o)
@@ -222,7 +222,7 @@ public void setError(String error)
222222

223223

224224
@RequiresPermission(ReadPermission.class)
225-
public class AnalysisAction extends QueryViewAction<AnalysisForm, QueryView>
225+
public static class AnalysisAction extends QueryViewAction<AnalysisForm, QueryView>
226226
{
227227
private GenotypingAnalysis _analysis = null;
228228

@@ -316,7 +316,7 @@ private ActionURL getDeleteMatchesURL(int analysisId)
316316

317317
// TODO: Delete this action? No longer used?
318318
@RequiresPermission(DeletePermission.class)
319-
public class DeleteMatchesAction extends FormHandlerAction<MatchesForm>
319+
public static class DeleteMatchesAction extends FormHandlerAction<MatchesForm>
320320
{
321321
private int _count = 0;
322322
private String _error = null;
@@ -363,7 +363,7 @@ public boolean handlePost(MatchesForm form, BindException errors)
363363

364364

365365
@RequiresPermission(AdminPermission.class)
366-
public class LoadSequencesAction extends FormHandlerAction<ReturnUrlForm>
366+
public static class LoadSequencesAction extends FormHandlerAction<ReturnUrlForm>
367367
{
368368
@Override
369369
public void validateCommand(ReturnUrlForm target, Errors errors)
@@ -581,7 +581,7 @@ public void addNavTrail(NavTree root)
581581

582582
@RequiresPermission(ReadPermission.class)
583583
@IgnoresTermsOfUse
584-
public class MergeFastqFilesAction extends ExportAction<MergeFastqFilesForm>
584+
public static class MergeFastqFilesAction extends ExportAction<MergeFastqFilesForm>
585585
{
586586
@Override
587587
public void export(MergeFastqFilesForm form, HttpServletResponse response, BindException errors) throws Exception
@@ -698,7 +698,7 @@ public static ActionURL getMySettingsURL(Container c, ActionURL returnUrl)
698698

699699

700700
@RequiresPermission(ReadPermission.class)
701-
public class MySettingsAction extends FormViewAction<MySettingsForm>
701+
public static class MySettingsAction extends FormViewAction<MySettingsForm>
702702
{
703703
@Override
704704
public void validateCommand(MySettingsForm form, Errors errors)
@@ -890,10 +890,10 @@ public void setPrefix(String prefix)
890890

891891
public static class ImportReadsBean
892892
{
893-
private List<Integer> _runs;
894-
private SEQUENCE_PLATFORMS _platform;
895-
private String _readsPath;
896-
private String _path;
893+
private final List<Integer> _runs;
894+
private final SEQUENCE_PLATFORMS _platform;
895+
private final String _readsPath;
896+
private final String _path;
897897
private String _prefix;
898898

899899
private ImportReadsBean(List<Integer> runs, String readsPath, String path, @Nullable String platform, @Nullable String prefix)
@@ -1124,7 +1124,7 @@ private ActionURL getAnalyzeURL(int runId, ActionURL cancelURL)
11241124

11251125

11261126
@RequiresPermission(InsertPermission.class)
1127-
public class AnalyzeAction extends FormViewAction<AnalyzeForm>
1127+
public static class AnalyzeAction extends FormViewAction<AnalyzeForm>
11281128
{
11291129
@Override
11301130
public void validateCommand(AnalyzeForm target, Errors errors)
@@ -1501,7 +1501,7 @@ public static ActionURL getSequencesURL(Container c, @Nullable Integer dictionar
15011501

15021502

15031503
@RequiresPermission(ReadPermission.class)
1504-
public class SequencesAction extends QueryViewAction<SequencesForm, QueryView>
1504+
public static class SequencesAction extends QueryViewAction<SequencesForm, QueryView>
15051505
{
15061506
public SequencesAction()
15071507
{
@@ -1563,7 +1563,7 @@ public void setAnalysis(Integer analysis)
15631563

15641564
@SuppressWarnings({"UnusedDeclaration"}) // URL defined on sequences.rowId column in genotyping.xml
15651565
@RequiresPermission(ReadPermission.class)
1566-
public class SequenceAction extends SimpleViewAction<SequenceForm>
1566+
public static class SequenceAction extends SimpleViewAction<SequenceForm>
15671567
{
15681568
@Override
15691569
public ModelAndView getView(SequenceForm form, BindException errors)
@@ -1607,7 +1607,7 @@ public static ActionURL getRunsURL(Container c)
16071607

16081608

16091609
@RequiresPermission(ReadPermission.class)
1610-
public class RunsAction extends QueryViewAction<QueryExportForm, QueryView>
1610+
public static class RunsAction extends QueryViewAction<QueryExportForm, QueryView>
16111611
{
16121612
public RunsAction()
16131613
{
@@ -1636,7 +1636,7 @@ public static ActionURL getAnalysesURL(Container c)
16361636

16371637

16381638
@RequiresPermission(ReadPermission.class)
1639-
public class AnalysesAction extends QueryViewAction<QueryExportForm, QueryView>
1639+
public static class AnalysesAction extends QueryViewAction<QueryExportForm, QueryView>
16401640
{
16411641
public AnalysesAction()
16421642
{
@@ -1727,7 +1727,7 @@ public static ActionURL getRunURL(Container c, GenotypingRun run)
17271727
public static final String FASTQ_FILE_FORMAT = "FASTQ_FILE";
17281728
public static final String FASTQ_FORMAT = "FASTQ";
17291729

1730-
private abstract class ReadsAction<FORM extends RunForm> extends QueryViewAction<FORM, QueryView>
1730+
private abstract static class ReadsAction<FORM extends RunForm> extends QueryViewAction<FORM, QueryView>
17311731
{
17321732
private static final String DATA_REGION_NAME = "Reads";
17331733

@@ -1905,7 +1905,7 @@ protected void handleSettings(QuerySettings settings)
19051905

19061906

19071907
@RequiresPermission(AdminPermission.class)
1908-
public class DeleteRunsAction extends FormHandlerAction
1908+
public static class DeleteRunsAction extends FormHandlerAction<Object>
19091909
{
19101910
@Override
19111911
public void validateCommand(Object target, Errors errors)
@@ -1936,7 +1936,7 @@ public ActionURL getSuccessURL(Object o)
19361936

19371937

19381938
@RequiresPermission(DeletePermission.class)
1939-
public class DeleteAnalysesAction extends FormHandlerAction
1939+
public static class DeleteAnalysesAction extends FormHandlerAction<Object>
19401940
{
19411941
@Override
19421942
public void validateCommand(Object target, Errors errors)
@@ -2036,7 +2036,7 @@ protected void handleSettings(QuerySettings settings)
20362036
}
20372037
}
20382038

2039-
public class AssignmentReportBean
2039+
public static class AssignmentReportBean
20402040
{
20412041
private final Collection<Integer> _ids;
20422042
private final String _assayName;
@@ -2101,7 +2101,7 @@ public void addNavTrail(NavTree root)
21012101
}
21022102

21032103
@RequiresPermission(ReadPermission.class)
2104-
public class DuplicateAssignmentReportAction extends BaseAssayAction<ProtocolIdForm>
2104+
public static class DuplicateAssignmentReportAction extends BaseAssayAction<ProtocolIdForm>
21052105
{
21062106
private ExpProtocol _protocol;
21072107

@@ -2128,7 +2128,7 @@ public void addNavTrail(NavTree root)
21282128
}
21292129

21302130
@RequiresPermission(ReadPermission.class)
2131-
public class STRDiscrepanciesAssignmentReportAction extends SimpleViewAction<STRDiscrepancies>
2131+
public static class STRDiscrepanciesAssignmentReportAction extends SimpleViewAction<STRDiscrepancies>
21322132
{
21332133
private ExpProtocol _protocol;
21342134
private static final String DELIM = "[;,/]";
@@ -2355,7 +2355,7 @@ public void addNavTrail(NavTree root)
23552355
}
23562356

23572357
@RequiresPermission(UpdatePermission.class)
2358-
public class EditHaplotypeAssignmentAction extends SimpleViewAction<AssignmentForm>
2358+
public static class EditHaplotypeAssignmentAction extends SimpleViewAction<AssignmentForm>
23592359
{
23602360
@Override
23612361
public ModelAndView getView(AssignmentForm form, BindException errors)

genotyping/src/org/labkey/genotyping/GenotypingManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ public int deleteMatches(Container c, User user, int analysisId, List<Integer> m
443443
GenotypingAnalysis analysis = GenotypingManager.get().getAnalysis(c, analysisId);
444444

445445
// Verify that matches were posted
446-
if (matchIds.size() < 1)
446+
if (matchIds.isEmpty())
447447
throw new IllegalStateException("No matches were selected");
448448

449449
// Count the corresponding matches in the database, making sure they belong to this analysis

0 commit comments

Comments
 (0)