Skip to content
Permalink
Browse files

spotbugs flagged iterators and casts for all (abstr)conn.config

  • Loading branch information...
silverailscolo committed Jun 8, 2019
1 parent 3a941b6 commit f8c34f301e9994c2cbeb7a2098070b224d48bd28
@@ -230,15 +230,15 @@ protected int addStandardDetails(PortAdapter adapter, boolean incAdvanced, int i
cL.gridy = i;
gbLayout.setConstraints(systemPrefixLabel, cL);
gbLayout.setConstraints(systemPrefixField, cR);
systemPrefixLabel.setLabelFor(systemPrefixField);
systemPrefixLabel.setLabelFor(systemPrefixField);
_details.add(systemPrefixLabel);
_details.add(systemPrefixField);
i++;
cR.gridy = i;
cL.gridy = i;
gbLayout.setConstraints(connectionNameLabel, cL);
gbLayout.setConstraints(connectionNameField, cR);
connectionNameLabel.setLabelFor(connectionNameField);
connectionNameLabel.setLabelFor(connectionNameField);
_details.add(connectionNameLabel);
_details.add(connectionNameField);
i++;
@@ -159,11 +159,8 @@ public void keyTyped(KeyEvent keyEvent) {
for (Map.Entry<String, Option> entry : options.entrySet()) {
final String item = entry.getKey();
if (entry.getValue().getComponent() instanceof JComboBox) {
((JComboBox<?>) entry.getValue().getComponent()).addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
adapter.setOptionState(item, options.get(item).getItem());
}
((JComboBox<?>) entry.getValue().getComponent()).addActionListener((ActionEvent e) -> {
adapter.setOptionState(item, options.get(item).getItem());
});
}
}
@@ -376,7 +373,7 @@ public void itemStateChanged(ItemEvent e) {

@Override
@edu.umd.cs.findbugs.annotations.SuppressFBWarnings(value = "BC_UNCONFIRMED_CAST_OF_RETURN_VALUE",
justification = "type was checked before casting")
justification = "type was checked before casting")
protected void showAdvancedItems() {
_details.removeAll();
cL.anchor = GridBagConstraints.WEST;
@@ -445,14 +442,14 @@ protected void showAdvancedItems() {
i++;
}

for (String item : options.keySet()) {
if (options.get(item).isAdvanced()) {
for (Map.Entry<String, Option> entry : options.entrySet()) {
if (entry.getValue().isAdvanced()) {
cR.gridy = i;
cL.gridy = i;
gbLayout.setConstraints(options.get(item).getLabel(), cL);
gbLayout.setConstraints(options.get(item).getComponent(), cR);
_details.add(options.get(item).getLabel());
_details.add(options.get(item).getComponent());
gbLayout.setConstraints(entry.getValue().getLabel(), cL);
gbLayout.setConstraints(entry.getValue().getComponent(), cR);
_details.add(entry.getValue().getLabel());
_details.add(entry.getValue().getComponent());
i++;
}
}
@@ -179,6 +179,8 @@ public void setOptionState(String option, String value) {
* @return the option value
*/
@Override
@edu.umd.cs.findbugs.annotations.SuppressFBWarnings(value = "PZLA_PREFER_ZERO_LENGTH_ARRAYS",
justification = "availability was checked before, should never get here")
public String getOptionState(String option) {
if (options.containsKey(option)) {
return options.get(option).getCurrent();
@@ -187,12 +189,14 @@ public String getOptionState(String option) {
}

/**
* Get a list of the various choices allowed with an given option.
* Get a list of the various choices allowed with a given option.
*
* @param option the name of the option to query
* @return list of valid values for the option
* @return list of valid values for the option, null if none are available
*/
@Override
@edu.umd.cs.findbugs.annotations.SuppressFBWarnings(value = "PZLA_PREFER_ZERO_LENGTH_ARRAYS",
justification = "availability was checked before, should never get here")
public String[] getOptionChoices(String option) {
if (options.containsKey(option)) {
return options.get(option).getOptions();
@@ -201,6 +205,8 @@ public String getOptionState(String option) {
}

@Override
@edu.umd.cs.findbugs.annotations.SuppressFBWarnings(value = "PZLA_PREFER_ZERO_LENGTH_ARRAYS",
justification = "availability was checked before, should never get here")
public String getOptionDisplayName(String option) {
if (options.containsKey(option)) {
return options.get(option).getDisplayText();
@@ -12,7 +12,7 @@
import java.awt.event.ItemEvent;
import java.util.Collections;
import java.util.Enumeration;
import java.util.Map.Entry;
import java.util.Map;
import java.util.ResourceBundle;
import java.util.Vector;
import javax.swing.JComboBox;
@@ -41,8 +41,9 @@
*
* @param p port being configured
*/
@edu.umd.cs.findbugs.annotations.SuppressFBWarnings(value = "BC_UNCONFIRMED_CAST", justification = "Thought to be safe as default connection config")
public AbstractSerialConnectionConfig(jmri.jmrix.PortAdapter p) {
this((jmri.jmrix.SerialPortAdapter) p);
this((jmri.jmrix.SerialPortAdapter) p);
}

public AbstractSerialConnectionConfig(jmri.jmrix.SerialPortAdapter p) {
@@ -142,10 +143,10 @@ public void focusLost(FocusEvent e) {
}
});

for (String i : options.keySet()) {
final String item = i;
if (options.get(i).getComponent() instanceof JComboBox) {
((JComboBox<?>) options.get(i).getComponent()).addActionListener((ActionEvent e) -> {
for (Map.Entry<String, Option> entry : options.entrySet()) {
final String item = entry.getKey();
if (entry.getValue().getComponent() instanceof JComboBox) {
((JComboBox<?>) entry.getValue().getComponent()).addActionListener((ActionEvent e) -> {
adapter.setOptionState(item, options.get(item).getItem());
});
}
@@ -159,8 +160,8 @@ public void updateAdapter() {
log.debug("updateAdapter() to {}", systemPrefixField.getText());
adapter.setPort(PortNameMapper.getPortFromName((String) portBox.getSelectedItem()));
adapter.configureBaudRate((String) baudBox.getSelectedItem());
for (String i : options.keySet()) {
adapter.setOptionState(i, options.get(i).getItem());
for (Map.Entry<String, Option> entry : options.entrySet()) {
adapter.setOptionState(entry.getKey(), entry.getValue().getItem());
}

if (adapter.getSystemConnectionMemo() != null && !adapter.getSystemConnectionMemo().setSystemPrefix(systemPrefixField.getText())) {
@@ -387,6 +388,8 @@ public void loadDetails(final JPanel details) {
}

@Override
@edu.umd.cs.findbugs.annotations.SuppressFBWarnings(value = "BC_UNCONFIRMED_CAST_OF_RETURN_VALUE",
justification = "Type is checked before casting")
protected void showAdvancedItems() {
_details.removeAll();
cL.anchor = GridBagConstraints.WEST;
@@ -404,8 +407,8 @@ protected void showAdvancedItems() {
if (!isPortAdvanced()) {
stdrows++;
}
for (String item : options.keySet()) {
if (!options.get(item).isAdvanced()) {
for (Map.Entry<String, Option> entry : options.entrySet()) {
if (!entry.getValue().isAdvanced()) {
stdrows++;
}
}
@@ -441,14 +444,14 @@ protected void showAdvancedItems() {
i++;
}

for (String item : options.keySet()) {
if (options.get(item).isAdvanced()) {
for (Map.Entry<String, Option> entry : options.entrySet()) {
if (entry.getValue().isAdvanced()) {
cR.gridy = i;
cL.gridy = i;
gbLayout.setConstraints(options.get(item).getLabel(), cL);
gbLayout.setConstraints(options.get(item).getComponent(), cR);
_details.add(options.get(item).getLabel());
_details.add(options.get(item).getComponent());
gbLayout.setConstraints(entry.getValue().getLabel(), cL);
gbLayout.setConstraints(entry.getValue().getComponent(), cR);
_details.add(entry.getValue().getLabel());
_details.add(entry.getValue().getComponent());
i++;
}
}
@@ -601,7 +604,7 @@ public Component getListCellRendererComponent(
*/
@SuppressWarnings("UseOfObsoleteCollectionType")
protected synchronized static void updateSerialPortNames(String portName, JComboBox<String> portCombo, Vector<String> portList) {
for (Entry<String, SerialPortFriendlyName> en : PortNameMapper.getPortNameMap().entrySet()) {
for (Map.Entry<String, SerialPortFriendlyName> en : PortNameMapper.getPortNameMap().entrySet()) {
en.getValue().setValidPort(false);
}
for (int i = 0; i < portList.size(); i++) {
@@ -164,6 +164,8 @@ public String getCurrentBaudRate() {
* This method need not be reimplemented unless the subclass is using
* currentBaudNumber, which requires it.
*/
@edu.umd.cs.findbugs.annotations.SuppressFBWarnings(value = "PZLA_PREFER_ZERO_LENGTH_ARRAYS",
justification = "null signal incorrect implementation of portcontroller")
public int[] validBaudNumber() {
log.error("default validBaudNumber implementation should not be used", new Exception());
return null;
@@ -9,6 +9,7 @@
import java.awt.event.FocusListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.util.Map;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JOptionPane;
@@ -108,14 +109,11 @@ public void focusLost(FocusEvent e) {
public void focusGained(FocusEvent e) {
}
});
for (String i : options.keySet()) {
final String item = i;
if (options.get(i).getComponent() instanceof JComboBox) {
((JComboBox<?>) options.get(i).getComponent()).addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
adapter.setOptionState(item, options.get(item).getItem());
}
for (Map.Entry<String, Option> entry : options.entrySet()) {
final String item = entry.getKey();
if (entry.getValue().getComponent() instanceof JComboBox) {
((JComboBox<?>) entry.getValue().getComponent()).addActionListener((ActionEvent e) -> {
adapter.setOptionState(item, options.get(item).getItem());
});
}
}
@@ -126,8 +124,8 @@ public void actionPerformed(ActionEvent e) {

@Override
public void updateAdapter() {
for (String i : options.keySet()) {
adapter.setOptionState(i, options.get(i).getItem());
for (Map.Entry<String, Option> entry : options.entrySet()) {
adapter.setOptionState(entry.getKey(), entry.getValue().getItem());
}

if (!adapter.getSystemConnectionMemo().setSystemPrefix(systemPrefixField.getText())) {
@@ -202,6 +200,8 @@ public void itemStateChanged(ItemEvent e) {
}

@Override
@edu.umd.cs.findbugs.annotations.SuppressFBWarnings(value = "BC_UNCONFIRMED_CAST_OF_RETURN_VALUE",
justification = "Type is checked before casting")
protected void showAdvancedItems() {
_details.removeAll();
cL.anchor = GridBagConstraints.WEST;
@@ -214,23 +214,23 @@ protected void showAdvancedItems() {
int i = 0;

boolean incAdvancedOptions = false;
for (String item : options.keySet()) {
if (options.get(item).isAdvanced()) {
for (Map.Entry<String, Option> entry : options.entrySet()) {
if (entry.getValue().isAdvanced()) {
incAdvancedOptions = true;
}
}

i = addStandardDetails(adapter, incAdvancedOptions, i);

if (showAdvanced.isSelected()) {
for (String item : options.keySet()) {
if (options.get(item).isAdvanced()) {
for (Map.Entry<String, Option> entry : options.entrySet()) {
if (entry.getValue().isAdvanced()) {
cR.gridy = i;
cL.gridy = i;
gbLayout.setConstraints(options.get(item).getLabel(), cL);
gbLayout.setConstraints(options.get(item).getComponent(), cR);
_details.add(options.get(item).getLabel());
_details.add(options.get(item).getComponent());
gbLayout.setConstraints(entry.getValue().getLabel(), cL);
gbLayout.setConstraints(entry.getValue().getComponent(), cR);
_details.add(entry.getValue().getLabel());
_details.add(entry.getValue().getComponent());
i++;
}
}
@@ -9,6 +9,7 @@
import java.awt.event.FocusListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.util.Map;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JOptionPane;
@@ -106,14 +107,11 @@ public void focusLost(FocusEvent e) {
public void focusGained(FocusEvent e) {
}
});
for (String i : options.keySet()) {
final String item = i;
if (options.get(i).getComponent() instanceof JComboBox) {
((JComboBox<?>) options.get(i).getComponent()).addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
adapter.setOptionState(item, options.get(item).getItem());
}
for (Map.Entry<String, Option> entry : options.entrySet()) {
final String item = entry.getKey();
if (entry.getValue().getComponent() instanceof JComboBox) {
((JComboBox<?>) entry.getValue().getComponent()).addActionListener((ActionEvent e) -> {
adapter.setOptionState(item, options.get(item).getItem());
});
}
}
@@ -124,8 +122,8 @@ public void actionPerformed(ActionEvent e) {

@Override
public void updateAdapter() {
for (String i : options.keySet()) {
adapter.setOptionState(i, options.get(i).getItem());
for (Map.Entry<String, Option> entry : options.entrySet()) {
adapter.setOptionState(entry.getKey(), entry.getValue().getItem());
}

if (!adapter.getSystemConnectionMemo().setSystemPrefix(systemPrefixField.getText())) {
@@ -193,6 +191,8 @@ public void itemStateChanged(ItemEvent e) {
}

@Override
@edu.umd.cs.findbugs.annotations.SuppressFBWarnings(value = "BC_UNCONFIRMED_CAST_OF_RETURN_VALUE",
justification = "Type is checked before casting")
protected void showAdvancedItems() {
_details.removeAll();
cL.anchor = GridBagConstraints.WEST;
@@ -205,23 +205,24 @@ protected void showAdvancedItems() {
int i = 0;

boolean incAdvancedOptions = false;
for (String item : options.keySet()) {
if (options.get(item).isAdvanced()) {
for (Map.Entry<String, Option> entry : options.entrySet()) {
if (entry.getValue().isAdvanced()) {
incAdvancedOptions = true;
break;
}
}

i = addStandardDetails(adapter, incAdvancedOptions, i);

if (showAdvanced.isSelected()) {
for (String item : options.keySet()) {
if (options.get(item).isAdvanced()) {
for (Map.Entry<String, Option> entry : options.entrySet()) {
if (entry.getValue().isAdvanced()) {
cR.gridy = i;
cL.gridy = i;
gbLayout.setConstraints(options.get(item).getLabel(), cL);
gbLayout.setConstraints(options.get(item).getComponent(), cR);
_details.add(options.get(item).getLabel());
_details.add(options.get(item).getComponent());
gbLayout.setConstraints(entry.getValue().getLabel(), cL);
gbLayout.setConstraints(entry.getValue().getComponent(), cR);
_details.add(entry.getValue().getLabel());
_details.add(entry.getValue().getComponent());
i++;
}
}

0 comments on commit f8c34f3

Please sign in to comment.
You can’t perform that action at this time.