From 664deb65bce339df26d66f7cdd17e552bc168b18 Mon Sep 17 00:00:00 2001 From: Greg DiCristofaro Date: Mon, 24 Aug 2020 11:53:34 -0400 Subject: [PATCH] addressing codacy remarks --- .../DataSourceTopDomainsSummary.java | 4 ++- .../datamodel/SleuthkitCaseProvider.java | 2 +- .../guiutils/internal/DataFetchWorker.java | 16 ++-------- .../guiutils/internal/DataLoadingResult.java | 2 +- .../guiutils/internal/DataProcessor.java | 29 ------------------- .../internal/DataProcessorException.java | 3 +- .../guiutils/internal/DataResultJTable.java | 27 ++++++++--------- .../DefaultPojoListTableDataModel.java | 9 ++++-- 8 files changed, 30 insertions(+), 62 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/datasourcesummary/datamodel/DataSourceTopDomainsSummary.java b/Core/src/org/sleuthkit/autopsy/datasourcesummary/datamodel/DataSourceTopDomainsSummary.java index d61a21e307..16cdf98db4 100644 --- a/Core/src/org/sleuthkit/autopsy/datasourcesummary/datamodel/DataSourceTopDomainsSummary.java +++ b/Core/src/org/sleuthkit/autopsy/datasourcesummary/datamodel/DataSourceTopDomainsSummary.java @@ -18,7 +18,6 @@ */ package org.sleuthkit.autopsy.datasourcesummary.datamodel; -import java.util.Collections; import java.util.Date; import java.util.List; import java.util.stream.Collectors; @@ -41,6 +40,9 @@ public class DataSourceTopDomainsSummary { // this.provider = provider; // } + /* + * a function to calculate a result from 2 paramaters + */ interface Function2 { O apply(A1 a1, A2 a2); } diff --git a/Core/src/org/sleuthkit/autopsy/datasourcesummary/datamodel/SleuthkitCaseProvider.java b/Core/src/org/sleuthkit/autopsy/datasourcesummary/datamodel/SleuthkitCaseProvider.java index 9855fde185..7c369bed63 100644 --- a/Core/src/org/sleuthkit/autopsy/datasourcesummary/datamodel/SleuthkitCaseProvider.java +++ b/Core/src/org/sleuthkit/autopsy/datasourcesummary/datamodel/SleuthkitCaseProvider.java @@ -27,7 +27,7 @@ import org.sleuthkit.datamodel.SleuthkitCase; * uses Case.getCurrentCaseThrows().getSleuthkkitCase(). */ public interface SleuthkitCaseProvider { - public static final SleuthkitCaseProvider DEFAULT = () -> Case.getCurrentCaseThrows().getSleuthkitCase(); + SleuthkitCaseProvider DEFAULT = () -> Case.getCurrentCaseThrows().getSleuthkitCase(); SleuthkitCase get() throws NoCurrentCaseException; } diff --git a/Core/src/org/sleuthkit/autopsy/guiutils/internal/DataFetchWorker.java b/Core/src/org/sleuthkit/autopsy/guiutils/internal/DataFetchWorker.java index a673e8d265..a3b123ad02 100644 --- a/Core/src/org/sleuthkit/autopsy/guiutils/internal/DataFetchWorker.java +++ b/Core/src/org/sleuthkit/autopsy/guiutils/internal/DataFetchWorker.java @@ -106,17 +106,7 @@ public class DataFetchWorker extends SwingWorker { @Override protected R doInBackground() throws Exception { - if (Thread.interrupted() || isCancelled()) { - throw new InterruptedException(); - } - - R result = processor.process(args); - - if (Thread.interrupted() || isCancelled()) { - throw new InterruptedException(); - } - - return result; + return processor.process(args); } @Override @@ -135,14 +125,14 @@ public class DataFetchWorker extends SwingWorker { } catch (ExecutionException ex) { Throwable inner = ex.getCause(); // if cancelled during operation, simply return - if (inner != null && inner instanceof InterruptedException) { + if (inner instanceof InterruptedException) { return; } // otherwise, there is an error to log logger.log(Level.WARNING, "There was an error while fetching results.", ex); - if (inner != null && inner instanceof DataProcessorException) { + if (inner instanceof DataProcessorException) { resultHandler.accept(DataLoadingResult.getLoadError((DataProcessorException) inner)); } return; diff --git a/Core/src/org/sleuthkit/autopsy/guiutils/internal/DataLoadingResult.java b/Core/src/org/sleuthkit/autopsy/guiutils/internal/DataLoadingResult.java index d2b1aba199..2dd85b398b 100644 --- a/Core/src/org/sleuthkit/autopsy/guiutils/internal/DataLoadingResult.java +++ b/Core/src/org/sleuthkit/autopsy/guiutils/internal/DataLoadingResult.java @@ -21,7 +21,7 @@ package org.sleuthkit.autopsy.guiutils.internal; /** * The intermediate or end result of a loading process. */ -public class DataLoadingResult { +public final class DataLoadingResult { // The state of loading in the result. public enum ProcessorState { diff --git a/Core/src/org/sleuthkit/autopsy/guiutils/internal/DataProcessor.java b/Core/src/org/sleuthkit/autopsy/guiutils/internal/DataProcessor.java index f99f33c39a..96aa967dc5 100644 --- a/Core/src/org/sleuthkit/autopsy/guiutils/internal/DataProcessor.java +++ b/Core/src/org/sleuthkit/autopsy/guiutils/internal/DataProcessor.java @@ -26,35 +26,6 @@ package org.sleuthkit.autopsy.guiutils.internal; */ @FunctionalInterface public interface DataProcessor { - - /** - * Wraps a DataProcessor in statements looking to see if the thread has been - * interrupted and throws an InterruptedException in that event. - * - * @param toBeWrapped The data processor to be wrapped. - * - * @return The wrapped data processor that will throw an interrupted - * exception before or after the toBeWrapped data processor has been - * run. - */ - public static DataProcessor wrap(DataProcessor toBeWrapped) { - return new DataProcessor() { - @Override - public O1 process(I1 input) throws InterruptedException, DataProcessorException { - if (Thread.interrupted()) { - throw new InterruptedException(); - } - - O1 output = toBeWrapped.process(input); - if (Thread.interrupted()) { - throw new InterruptedException(); - } - - return output; - } - }; - } - /** * A function that accepts an input argument and outputs a result. Since it * is meant to be used with the DataFetchWorker, it throws an interrupted diff --git a/Core/src/org/sleuthkit/autopsy/guiutils/internal/DataProcessorException.java b/Core/src/org/sleuthkit/autopsy/guiutils/internal/DataProcessorException.java index cc14647a06..3dc67968c3 100644 --- a/Core/src/org/sleuthkit/autopsy/guiutils/internal/DataProcessorException.java +++ b/Core/src/org/sleuthkit/autopsy/guiutils/internal/DataProcessorException.java @@ -23,7 +23,8 @@ package org.sleuthkit.autopsy.guiutils.internal; * DataProcessor. */ public class DataProcessorException extends Exception { - + private static final long serialVersionUID = 1L; + /** * Main constructor. * @param string The error message. diff --git a/Core/src/org/sleuthkit/autopsy/guiutils/internal/DataResultJTable.java b/Core/src/org/sleuthkit/autopsy/guiutils/internal/DataResultJTable.java index cf747b5259..43d59b4588 100644 --- a/Core/src/org/sleuthkit/autopsy/guiutils/internal/DataResultJTable.java +++ b/Core/src/org/sleuthkit/autopsy/guiutils/internal/DataResultJTable.java @@ -42,6 +42,7 @@ import org.sleuthkit.autopsy.coreutils.Logger; "DataResultJTable_errorMessage_defaultText=There was an error loading results." }) public class DataResultJTable extends JPanel { + private static final long serialVersionUID = 1L; /** * JTables don't allow display messages. So this LayerUI is used to display @@ -50,7 +51,8 @@ public class DataResultJTable extends JPanel { * https://docs.oracle.com/javase/tutorial/uiswing/misc/jlayer.html. */ private static class Overlay extends LayerUI { - + private static final long serialVersionUID = 1L; + private final JLabel child; private boolean visible; @@ -96,9 +98,6 @@ public class DataResultJTable extends JPanel { @Override public void paint(Graphics g, JComponent c) { - int w = c.getWidth(); - int h = c.getHeight(); - // Paint the underlying view. super.paint(g, c); @@ -106,6 +105,9 @@ public class DataResultJTable extends JPanel { return; } + int w = c.getWidth(); + int h = c.getHeight(); + // paint the jlabel if visible. child.setBounds(0, 0, w, h); child.paint(g); @@ -119,17 +121,16 @@ public class DataResultJTable extends JPanel { private static final String DEFAULT_NO_RESULTS_MESSAGE = ""; private static final String DEFAULT_NOT_LOADED_MESSAGE = ""; - private final JTable table; private final JScrollPane tableScrollPane; - private final JLayer dualLayer; private final Overlay overlayLayer; + private final PojoListTableDataModel tableModel; private String loadingMessage = DEFAULT_LOADING_MESSAGE; private String errorMessage = DEFAULT_ERROR_MESSAGE; private String noResultsMessage = DEFAULT_NO_RESULTS_MESSAGE; private String notLoadedMessage = DEFAULT_NOT_LOADED_MESSAGE; - private PojoListTableDataModel tableModel = null; + /** * Main constructor. @@ -137,12 +138,12 @@ public class DataResultJTable extends JPanel { */ public DataResultJTable(PojoListTableDataModel tableModel) { this.tableModel = tableModel; - this.table = new JTable(tableModel, tableModel.getTableColumnModel()); - this.table.getTableHeader().setReorderingAllowed(false); + JTable table = new JTable(tableModel, tableModel.getTableColumnModel()); + table.getTableHeader().setReorderingAllowed(false); this.overlayLayer = new Overlay(); this.tableScrollPane = new JScrollPane(table); - this.dualLayer = new JLayer(tableScrollPane, overlayLayer); + JLayer dualLayer = new JLayer(tableScrollPane, overlayLayer); setLayout(new BorderLayout()); add(dualLayer, BorderLayout.CENTER); } @@ -157,21 +158,21 @@ public class DataResultJTable extends JPanel { /** * @return The message shown when there is an exception. */ - String getErrorMessage() { + public String getErrorMessage() { return errorMessage; } /** * @return The message shown when there are no results. */ - String getNoResultsMessage() { + public String getNoResultsMessage() { return noResultsMessage; } /** * @return The message shown when the table has not been loaded. */ - String getNotLoadedMessage() { + public String getNotLoadedMessage() { return notLoadedMessage; } diff --git a/Core/src/org/sleuthkit/autopsy/guiutils/internal/DefaultPojoListTableDataModel.java b/Core/src/org/sleuthkit/autopsy/guiutils/internal/DefaultPojoListTableDataModel.java index b33fef986d..9387194eb4 100644 --- a/Core/src/org/sleuthkit/autopsy/guiutils/internal/DefaultPojoListTableDataModel.java +++ b/Core/src/org/sleuthkit/autopsy/guiutils/internal/DefaultPojoListTableDataModel.java @@ -36,7 +36,8 @@ import org.apache.commons.lang3.StringUtils; * class provides a TableModel and TableColumnModel to be used with that class. */ public class DefaultPojoListTableDataModel extends AbstractTableModel implements PojoListTableDataModel { - + private static final long serialVersionUID = 1L; + /** * Describes the horizontal alignment. */ @@ -63,8 +64,7 @@ public class DefaultPojoListTableDataModel extends AbstractTableModel impleme /** * The default cell model. */ - public static class DefaultCellModel implements CellModel { - + public static class DefaultCellModel implements CellModel { private final String text; private String tooltip; @@ -300,6 +300,9 @@ public class DefaultPojoListTableDataModel extends AbstractTableModel impleme case RIGHT: defaultCell.setHorizontalAlignment(JLabel.RIGHT); break; + default: + throw new IllegalArgumentException("Unknown horizontal alignment choice: " + + columnModel.getCellHorizontalAlignment()); } } else { defaultCell.setHorizontalAlignment(JLabel.LEFT);