From 53d49e834976c6dafdfa916a5c3cc501ec7a67da Mon Sep 17 00:00:00 2001 From: Nathanael Jourdane Date: Mon, 14 Mar 2016 16:03:37 +0100 Subject: [PATCH] Fix all Eclipse warnings. --- src/main/java/eu/omp/irap/vespa/epntapclient/EpnTapMainApp.java | 2 +- src/main/java/eu/omp/irap/vespa/epntapclient/controller/EpnTapController.java | 24 +++++++++++++----------- src/main/java/eu/omp/irap/vespa/epntapclient/utils/Queries.java | 11 ++++++----- src/main/java/eu/omp/irap/vespa/epntapclient/view/EpnTapMainView.java | 1 + src/main/java/eu/omp/irap/vespa/epntapclient/view/ParamField.java | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++-------------------------- src/main/java/eu/omp/irap/vespa/epntapclient/view/panels/BottomBarPanel.java | 11 ++++++++++- src/main/java/eu/omp/irap/vespa/epntapclient/view/panels/RequestPanel.java | 3 ++- src/main/java/eu/omp/irap/vespa/epntapclient/view/panels/ResultsPanel.java | 11 +++++++++-- src/main/java/eu/omp/irap/vespa/epntapclient/view/panels/ServicesPanel.java | 11 +++++++++-- src/main/java/eu/omp/irap/vespa/epntapclient/votable/Utils.java | 2 +- src/main/java/eu/omp/irap/vespa/epntapclient/votable/VOTableApp.java | 3 ++- 11 files changed, 105 insertions(+), 51 deletions(-) diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/EpnTapMainApp.java b/src/main/java/eu/omp/irap/vespa/epntapclient/EpnTapMainApp.java index c9584eb..dd9707f 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/EpnTapMainApp.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/EpnTapMainApp.java @@ -30,7 +30,7 @@ import eu.omp.irap.vespa.epntapclient.controller.EpnTapController; */ public class EpnTapMainApp { /** The logger for the class EpnTapMainApp. */ - private static final Logger logger = Logger.getLogger(EpnTapMainApp.class.getName()); + static final Logger logger = Logger.getLogger(EpnTapMainApp.class.getName()); /** Constructor to hide the implicit public one. */ private EpnTapMainApp() { diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/controller/EpnTapController.java b/src/main/java/eu/omp/irap/vespa/epntapclient/controller/EpnTapController.java index 3b7484e..2445ad6 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/controller/EpnTapController.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/controller/EpnTapController.java @@ -34,22 +34,22 @@ import eu.omp.irap.vespa.epntapclient.votable.controller.VOTableException; */ public class EpnTapController implements MainViewListener { /** The logger for the class EpnTapController. */ - Logger logger = Logger.getLogger(EpnTapController.class.getName()); + private Logger logger = Logger.getLogger(EpnTapController.class.getName()); /** The view of EPN-TAP application. */ - EpnTapMainView mainView; + private EpnTapMainView mainView; /** The controller of the VOTable displaying the list of services. */ - VOTableController servicesController; + private VOTableController servicesController; /** The controller of the VOTable displaying the query results. */ - VOTableController resultsController; + private VOTableController resultsController; /** The name of the table selected by the user on the table list panel. */ - String selectedTableName; + private String selectedTableName; /** The URL of the service corresponding to the selected table. */ - String selectedTableServiceURL; + private String selectedTableServiceURL; /** * The parameters fields for the request. @@ -135,22 +135,24 @@ public class EpnTapController implements MainViewListener { * @param event * @param args */ - public void event(Event event, Object[] args) { + @Override + public void event(Event event, Object... args) { logger.info("new event: " + event.toString()); try { + Object object = args[0]; switch (event) { case serviceSelected: - updateSelected((int) args[0]); + updateSelected(((Integer) args[0]).intValue()); break; case btnSearchClicked: - sendQuery((String) args[0]); + sendQuery((String) object); break; case paramChanged: - updateParameter((String) args[0], args[1]); + updateParameter((String) object, args[1]); break; case paramRemoved: - removeParameter((String) args[0]); + removeParameter((String) object); break; default: logger.warning("Event " + event.toString() + " detected but is not implemented."); diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/utils/Queries.java b/src/main/java/eu/omp/irap/vespa/epntapclient/utils/Queries.java index 24f534b..ae894e4 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/utils/Queries.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/utils/Queries.java @@ -28,7 +28,8 @@ import eu.omp.irap.vespa.epntapclient.votable.Utils.StringJoiner; */ public final class Queries { /** The logger for the class Queries. */ - Logger logger = Logger.getLogger(Queries.class.getName()); + @SuppressWarnings("unused") + private Logger logger = Logger.getLogger(Queries.class.getName()); // AMDA access_url: http://cdpp-epntap.cesr.fr/__system__/tap/run/tap // AMDA table name: amdadb.epn_core @@ -56,14 +57,14 @@ public final class Queries { public static String getQuery(String tableName, Map params, int nbRow) { StringJoiner addJoin = new StringJoiner(" AND "); for (Map.Entry param : params.entrySet()) { - Class paramClass = param.getValue().getClass(); - if (paramClass == ArrayList.class) { + if (param.getValue() instanceof ArrayList) { StringJoiner orJoin = new StringJoiner(" OR "); - List possibleValues = ((List) param.getValue()); + @SuppressWarnings("unchecked") + List possibleValues = (List) param.getValue(); for (String possibleValue : possibleValues) orJoin.add(param.getKey() + " LIKE '" + possibleValue + "'"); addJoin.add("(" + orJoin + ")"); - } else if (paramClass == String.class) { + } else if (param.getValue() instanceof String) { addJoin.add(param.getKey() + " LIKE '" + param.getValue() + "'"); } else { addJoin.add(param.getKey() + " = " + param.getValue().toString()); diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/view/EpnTapMainView.java b/src/main/java/eu/omp/irap/vespa/epntapclient/view/EpnTapMainView.java index 8772110..3ca48be 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/view/EpnTapMainView.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/view/EpnTapMainView.java @@ -34,6 +34,7 @@ import eu.omp.irap.vespa.epntapclient.votable.view.VOTableView; */ public class EpnTapMainView extends JPanel { /** The logger for the class EpnTapMainView. */ + @SuppressWarnings("unused") private static final Logger logger = Logger.getLogger(EpnTapMainView.class.getName()); /** The serial version UID (affected with a random number). */ diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/view/ParamField.java b/src/main/java/eu/omp/irap/vespa/epntapclient/view/ParamField.java index 238d62f..05fce02 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/view/ParamField.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/view/ParamField.java @@ -47,8 +47,11 @@ import eu.omp.irap.vespa.epntapclient.votable.controller.VOTableConnection; import eu.omp.irap.vespa.epntapclient.votable.controller.VOTableException.SendQueryException; public abstract class ParamField extends JPanel { + /** */ + private static final long serialVersionUID = 6025994164004985362L; + /** The logger for the class ParamField. */ - private static final Logger logger = Logger.getLogger(ParamField.class.getName()); + static final Logger logger = Logger.getLogger(ParamField.class.getName()); private static final int MIN_FIELD_WIDTH = 30; private static final int FIELD_HEIGHT = 20; @@ -61,7 +64,7 @@ public abstract class ParamField extends JPanel { private static final String MIN_SUFFIX = "min"; private static final String MAX_SUFFIX = "max"; - protected static EpnTapMainView mainView; + protected EpnTapMainView mainView; protected String paramName; public ParamField(EpnTapMainView mainView, String paramName) { @@ -80,6 +83,8 @@ public abstract class ParamField extends JPanel { } public static class StringField extends ParamField implements TextFieldListener { + /** */ + private static final long serialVersionUID = 24219488975302068L; JTextField field; public StringField(EpnTapMainView mainView, String paramName) { @@ -89,16 +94,19 @@ public abstract class ParamField extends JPanel { this.add(field); } - public void update(JTextField field) { - if ("".equals(field.getText())) { + @Override + public void update(JTextField textField) { + if ("".equals(textField.getText())) { mainView.event(Event.paramChanged, paramName, null); } else { - mainView.event(Event.paramChanged, paramName, field.getText()); + mainView.event(Event.paramChanged, paramName, textField.getText()); } } } public static class FloatField extends ParamField implements TextFieldListener { + /** */ + private static final long serialVersionUID = -1880193152285564590L; JTextField field; public FloatField(EpnTapMainView mainView, String paramName) { @@ -108,23 +116,26 @@ public abstract class ParamField extends JPanel { this.add(field); } - public void update(JTextField field) { - if ("".equals(field.getText())) { - field.setBackground(Color.WHITE); + @Override + public void update(JTextField textField) { + if ("".equals(textField.getText())) { + textField.setBackground(Color.WHITE); mainView.event(Event.paramRemoved, paramName); } else { try { - mainView.event(Event.paramChanged, paramName, - Float.parseFloat(field.getText())); - field.setBackground(Color.WHITE); - } catch (NumberFormatException e) { - field.setBackground(Color.PINK); + float value = Float.parseFloat(textField.getText()); + mainView.event(Event.paramChanged, paramName, value); + textField.setBackground(Color.WHITE); + } catch (@SuppressWarnings("unused") NumberFormatException e) { + textField.setBackground(Color.PINK); } } } } public static class DateRangeField extends ParamField implements TextFieldListener { + /** */ + private static final long serialVersionUID = -7781309003911514777L; JTextField fieldMin; JTextField fieldMax; @@ -145,6 +156,7 @@ public abstract class ParamField extends JPanel { this.add(fieldMax); } + @Override public void update(JTextField field) { DateFormat df = new SimpleDateFormat(DATE_FORMAT, Locale.ENGLISH); if ("".equals(field.getText())) { @@ -156,7 +168,7 @@ public abstract class ParamField extends JPanel { date = Math.round((date / 86400000.0) + 2440587.5); // to JD mainView.event(Event.paramChanged, paramName + field.getName(), date); field.setBackground(Color.WHITE); - } catch (ParseException e) { + } catch (@SuppressWarnings("unused") ParseException e) { field.setBackground(Color.PINK); } // TODO: check if date min < date max @@ -167,6 +179,8 @@ public abstract class ParamField extends JPanel { } public static class FloatRangeField extends ParamField implements TextFieldListener { + /** */ + private static final long serialVersionUID = 7923358142882329015L; JTextField fieldMin; JTextField fieldMax; @@ -183,6 +197,7 @@ public abstract class ParamField extends JPanel { this.add(fieldMax); } + @Override public void update(JTextField field) { if ("".equals(field.getText())) { field.setBackground(Color.WHITE); @@ -192,7 +207,7 @@ public abstract class ParamField extends JPanel { mainView.event(Event.paramChanged, paramName + field.getName(), Float.parseFloat(field.getText())); field.setBackground(Color.WHITE); - } catch (NumberFormatException e) { + } catch (@SuppressWarnings("unused") NumberFormatException e) { field.setBackground(Color.PINK); } } @@ -200,13 +215,15 @@ public abstract class ParamField extends JPanel { } public static class TargetNameField extends ParamField implements TextFieldListener { + /** */ + private static final long serialVersionUID = 5136431108894677113L; JComboBox comboBox; JTextField field; String lastContent; public TargetNameField(EpnTapMainView mainView, String paramName) { super(mainView, paramName); - comboBox = new JComboBox(); + comboBox = new JComboBox<>(); comboBox.setPreferredSize(new Dimension(MIN_FIELD_WIDTH, FIELD_HEIGHT)); comboBox.setEditable(true); @@ -215,7 +232,7 @@ public abstract class ParamField extends JPanel { this.add(comboBox); } - private String[] getItems(String begining) throws SendQueryException { + static String[] getItems(String begining) throws SendQueryException { StringBuilder resolverResult = null; resolverResult = VOTableConnection.sendGet(RESOLVER_URL, "q=\"" + begining + "\""); JsonObject root = new JsonParser().parse(resolverResult.toString()).getAsJsonObject(); @@ -256,17 +273,20 @@ public abstract class ParamField extends JPanel { } }; - public void update(JTextField field) { + @Override + public void update(JTextField textField) { SwingUtilities.invokeLater(updateComboBox); } } public static class DataProductTypeField extends ParamField { + /** */ + private static final long serialVersionUID = -6362359909898369750L; JComboBox comboBox; public DataProductTypeField(EpnTapMainView mainView, String paramName) { super(mainView, paramName); - comboBox = new JComboBox(getItems().keySet().toArray()); + comboBox = new JComboBox<>((String[]) getItems().keySet().toArray()); comboBox.setSelectedItem("All"); comboBox.setPreferredSize(new Dimension(MIN_FIELD_WIDTH, FIELD_HEIGHT)); comboBox.addActionListener(new ActionListener() { @@ -278,8 +298,8 @@ public abstract class ParamField extends JPanel { this.add(comboBox); } - private HashMap getItems() { - HashMap items = new HashMap(); + private static HashMap getItems() { + HashMap items = new HashMap<>(); items.put("All", "all"); items.put("Image", "im"); items.put("Spectrum", "sp"); @@ -295,9 +315,9 @@ public abstract class ParamField extends JPanel { return items; } - private void onUpdate() { + void onUpdate() { String key = comboBox.getSelectedItem().toString(); - List item = new ArrayList(); + List item = new ArrayList<>(); item.add(key.replace(" ", "-").toLowerCase()); item.add(getItems().get(key)); if ("All".equals(key)) { @@ -309,11 +329,13 @@ public abstract class ParamField extends JPanel { } public static class TargetClassField extends ParamField { + /** */ + private static final long serialVersionUID = 6439475087727685080L; JComboBox comboBox; public TargetClassField(EpnTapMainView mainView, String paramName) { super(mainView, paramName); - comboBox = new JComboBox(getItems()); + comboBox = new JComboBox<>(getItems()); comboBox.setPreferredSize(new Dimension(MIN_FIELD_WIDTH, FIELD_HEIGHT)); comboBox.addActionListener(new ActionListener() { @Override @@ -324,12 +346,12 @@ public abstract class ParamField extends JPanel { this.add(comboBox); } - private String[] getItems() { + private static String[] getItems() { return new String[] { "All", "Comet", "Exoplanet", "Interplanetary medium", "Ring", "Sample", "Sky", "Spacecraft", "Spacejunk", "Star" }; } - private void onUpdate() { + void onUpdate() { String value = comboBox.getSelectedItem().toString().replace(" ", "_").toLowerCase(); if ("All".equals(value)) { mainView.event(Event.paramRemoved, paramName); @@ -345,14 +367,17 @@ public abstract class ParamField extends JPanel { static void addChangeListener(final TextFieldListener changeListener, final JTextField field) { field.getDocument().addDocumentListener(new DocumentListener() { + @Override public void removeUpdate(DocumentEvent de) { changeListener.update(field); } + @Override public void insertUpdate(DocumentEvent de) { changeListener.update(field); } + @Override public void changedUpdate(DocumentEvent de) { changeListener.update(field); } diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/view/panels/BottomBarPanel.java b/src/main/java/eu/omp/irap/vespa/epntapclient/view/panels/BottomBarPanel.java index 3a92368..3a37057 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/view/panels/BottomBarPanel.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/view/panels/BottomBarPanel.java @@ -29,11 +29,20 @@ import eu.omp.irap.vespa.epntapclient.view.EpnTapMainView; * @author N. Jourdane */ public class BottomBarPanel extends JPanel { + /** */ + private static final long serialVersionUID = 8083897308526492902L; + /** The logger for the class BottomBar. */ + @SuppressWarnings("unused") private static final Logger logger = Logger.getLogger(BottomBarPanel.class.getName()); - JLabel infoLabel; + + @SuppressWarnings("unused") + private EpnTapMainView mainView; + + private JLabel infoLabel; public BottomBarPanel(EpnTapMainView mainView) { + this.mainView = mainView; setLayout(new BorderLayout()); infoLabel = new JLabel(); this.add(infoLabel); diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/view/panels/RequestPanel.java b/src/main/java/eu/omp/irap/vespa/epntapclient/view/panels/RequestPanel.java index 53b2423..2d7efa4 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/view/panels/RequestPanel.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/view/panels/RequestPanel.java @@ -44,6 +44,7 @@ import eu.omp.irap.vespa.epntapclient.view.ParamField.TargetNameField; */ public class RequestPanel extends JPanel implements ActionListener { /** The logger for the class RequestView. */ + @SuppressWarnings("unused") private static final Logger logger = Logger.getLogger(RequestPanel.class.getName()); /** The serial version UID (affected with a random number). */ @@ -96,7 +97,7 @@ public class RequestPanel extends JPanel implements ActionListener { // TODO: new GUI field column to allow the user to select the comparison operator: // - if the field is a String: listbox with 'xx', '%xx', 'xx%', and '%xx%'. // - if the field is a numeric value: listbox with <, <=, =, =>, >. - paramFields = new ArrayList(); + paramFields = new ArrayList<>(); paramFields.add(new TargetNameField(mainView, "target_name")); paramFields.add(new DateRangeField(mainView, "time_")); paramFields.add(new FloatRangeField(mainView, "spectral_range_")); diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/view/panels/ResultsPanel.java b/src/main/java/eu/omp/irap/vespa/epntapclient/view/panels/ResultsPanel.java index 0bec476..9c66a7d 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/view/panels/ResultsPanel.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/view/panels/ResultsPanel.java @@ -30,11 +30,18 @@ import eu.omp.irap.vespa.epntapclient.votable.view.VOTableView; * @author N. Jourdane */ public class ResultsPanel extends JPanel { + /** */ + private static final long serialVersionUID = -3387526562625069156L; + /** The logger for the class ResultPanel. */ + @SuppressWarnings("unused") private static final Logger logger = Logger.getLogger(ResultsPanel.class.getName()); - EpnTapMainView mainView; - VOTableView voTableView; + @SuppressWarnings("unused") + private EpnTapMainView mainView; + + @SuppressWarnings("unused") + private VOTableView voTableView; public ResultsPanel(EpnTapMainView mainView, VOTableView voTableView) { super(); diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/view/panels/ServicesPanel.java b/src/main/java/eu/omp/irap/vespa/epntapclient/view/panels/ServicesPanel.java index 3395e2a..b20cfc9 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/view/panels/ServicesPanel.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/view/panels/ServicesPanel.java @@ -33,11 +33,17 @@ import eu.omp.irap.vespa.epntapclient.votable.view.VOTableView; * @author N. Jourdane */ public class ServicesPanel extends JPanel { + /** */ + private static final long serialVersionUID = 7850369546415832758L; + /** The logger for the class ServicesView. */ + @SuppressWarnings("unused") private static final Logger logger = Logger.getLogger(ServicesPanel.class.getName()); - EpnTapMainView mainView; - VOTableView voTableView; + @SuppressWarnings("unused") + private EpnTapMainView mainView; + + private VOTableView voTableView; public ServicesPanel(final EpnTapMainView mainView, final VOTableView voTableView) { super(); @@ -53,6 +59,7 @@ public class ServicesPanel extends JPanel { // TODO: Support multi-selection voTableView.getTable().getSelectionModel() .addListSelectionListener(new ListSelectionListener() { + @Override public void valueChanged(ListSelectionEvent evt) { mainView.event(Event.serviceSelected, voTableView.getTable().getSelectedRow()); diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/votable/Utils.java b/src/main/java/eu/omp/irap/vespa/epntapclient/votable/Utils.java index 8a96cdc..798f9f6 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/votable/Utils.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/votable/Utils.java @@ -41,7 +41,7 @@ public class Utils { public StringJoiner(String separator) { this.separator = separator; - this.list = new ArrayList(); + this.list = new ArrayList<>(); string = ""; } diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/votable/VOTableApp.java b/src/main/java/eu/omp/irap/vespa/epntapclient/votable/VOTableApp.java index 23059c2..438a2c2 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/votable/VOTableApp.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/votable/VOTableApp.java @@ -33,7 +33,7 @@ import eu.omp.irap.vespa.epntapclient.votable.controller.VOTableException; */ public class VOTableApp { /** The logger for the class VOTableApp. */ - private static final Logger logger = Logger.getLogger(VOTableApp.class.getName()); + static final Logger logger = Logger.getLogger(VOTableApp.class.getName()); /** * Main function to start the application as standalone. @@ -64,6 +64,7 @@ public class VOTableApp { voTableControl = new VOTableController(args[0]); } catch (VOTableException e) { System.console().writer().println("Error: " + e.getMessage()); + return; } } else if (args.length == 3) { voTableControl = new VOTableController(args[0], args[1], args[2]); -- libgit2 0.21.2