From 2b9b5af23f485eeda7bde59dff51e5bd94e29d9e Mon Sep 17 00:00:00 2001 From: Bengt Martensson Date: Tue, 12 Mar 2024 19:55:59 +0100 Subject: [PATCH] Minot, findbugs related, cleanups. --- .../org/harctoolbox/guicomponents/GirsClientBean.java | 4 ++-- .../org/harctoolbox/guicomponents/GlobalCacheManager.java | 4 ++-- .../java/org/harctoolbox/guicomponents/IrpRenderBean.java | 2 +- .../org/harctoolbox/guicomponents/SerialHardwareBean.java | 2 +- .../org/harctoolbox/guicomponents/SerialPortBean.java | 2 +- src/main/java/org/harctoolbox/irscrutinizer/GuiMain.java | 8 +++----- .../irscrutinizer/exporter/ExportFormatManager.java | 2 +- .../org/harctoolbox/irscrutinizer/exporter/Exporter.java | 1 + .../harctoolbox/irscrutinizer/importer/CsvImporter.java | 2 +- .../irscrutinizer/importer/CsvRawImporter.java | 2 +- .../irscrutinizer/importer/IrTransImporter.java | 1 + .../irscrutinizer/importer/RemoteLocatorImporter.java | 6 +++--- 12 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/main/java/org/harctoolbox/guicomponents/GirsClientBean.java b/src/main/java/org/harctoolbox/guicomponents/GirsClientBean.java index b64906c1..c09dce21 100644 --- a/src/main/java/org/harctoolbox/guicomponents/GirsClientBean.java +++ b/src/main/java/org/harctoolbox/guicomponents/GirsClientBean.java @@ -69,7 +69,7 @@ public GirsClientBean(GuiUtils guiUtils, boolean verbose, int timeout, String in DefaultComboBoxModel model; try { portNames = LocalSerialPort.getSerialPortNames(true); - model = new DefaultComboBoxModel<>(portNames.toArray(new String[portNames.size()])); + model = new DefaultComboBoxModel<>(portNames.toArray(new String[0])); } catch (IOException | LinkageError ex) { portNames = new ArrayList<>(0); model = new DefaultComboBoxModel<>(new String[]{ initialPort != null ? initialPort : NOT_INITIALIZED }); @@ -241,7 +241,7 @@ private void setupPortComboBox(boolean useCached) throws IOException { portNames = LocalSerialPort.getSerialPortNames(useCached); portNames.add(0, ""); - DefaultComboBoxModel model = new DefaultComboBoxModel<>(portNames.toArray(new String[portNames.size()])); + DefaultComboBoxModel model = new DefaultComboBoxModel<>(portNames.toArray(new String[0])); portComboBox.setModel(model); } diff --git a/src/main/java/org/harctoolbox/guicomponents/GlobalCacheManager.java b/src/main/java/org/harctoolbox/guicomponents/GlobalCacheManager.java index 1e4ba105..cf2a1db5 100644 --- a/src/main/java/org/harctoolbox/guicomponents/GlobalCacheManager.java +++ b/src/main/java/org/harctoolbox/guicomponents/GlobalCacheManager.java @@ -121,11 +121,11 @@ public boolean removeManualGlobalCache(InetAddress inetAddress) { } public InetAddress[] getManual() { - return manualGlobalCaches.toArray(new InetAddress[manualGlobalCaches.size()]); + return manualGlobalCaches.toArray(new InetAddress[0]); } public InetAddress[] getAutomatic() { - return automaticGlobalCaches.toArray(new InetAddress[automaticGlobalCaches.size()]); + return automaticGlobalCaches.toArray(new InetAddress[0]); } public String[] getAllNames() { diff --git a/src/main/java/org/harctoolbox/guicomponents/IrpRenderBean.java b/src/main/java/org/harctoolbox/guicomponents/IrpRenderBean.java index 1e841fb0..499555c7 100644 --- a/src/main/java/org/harctoolbox/guicomponents/IrpRenderBean.java +++ b/src/main/java/org/harctoolbox/guicomponents/IrpRenderBean.java @@ -144,7 +144,7 @@ private String[] irpMasterProtocols() { if (irpDatabase == null) return new String[]{"--"}; - String[] protocolList = irpDatabase.getNames().toArray(new String[irpDatabase.getNames().size()]); + String[] protocolList = irpDatabase.getNames().toArray(new String[0]); java.util.Arrays.sort(protocolList, String.CASE_INSENSITIVE_ORDER); return protocolList; } diff --git a/src/main/java/org/harctoolbox/guicomponents/SerialHardwareBean.java b/src/main/java/org/harctoolbox/guicomponents/SerialHardwareBean.java index 2e5e70a2..2c94c7c5 100644 --- a/src/main/java/org/harctoolbox/guicomponents/SerialHardwareBean.java +++ b/src/main/java/org/harctoolbox/guicomponents/SerialHardwareBean.java @@ -41,7 +41,7 @@ protected static DefaultComboBoxModel createModel(boolean useCached) { portNames.add(""); } //portNames.add(0, ""); - return new DefaultComboBoxModel<>(portNames.toArray(new String[portNames.size()])); + return new DefaultComboBoxModel<>(portNames.toArray(new String[0])); } protected String portName; diff --git a/src/main/java/org/harctoolbox/guicomponents/SerialPortBean.java b/src/main/java/org/harctoolbox/guicomponents/SerialPortBean.java index 63d14952..687f5fd3 100644 --- a/src/main/java/org/harctoolbox/guicomponents/SerialPortBean.java +++ b/src/main/java/org/harctoolbox/guicomponents/SerialPortBean.java @@ -216,7 +216,7 @@ public void setupPortComboBox(boolean useCached) throws IOException { List portNames = LocalSerialPort.getSerialPortNames(useCached); portNames.add(0, null); - DefaultComboBoxModel model = new DefaultComboBoxModel(portNames.toArray(new String[portNames.size()])); + DefaultComboBoxModel model = new DefaultComboBoxModel(portNames.toArray(new String[0])); portComboBox.setModel(model); } diff --git a/src/main/java/org/harctoolbox/irscrutinizer/GuiMain.java b/src/main/java/org/harctoolbox/irscrutinizer/GuiMain.java index c8603197..35dcf054 100755 --- a/src/main/java/org/harctoolbox/irscrutinizer/GuiMain.java +++ b/src/main/java/org/harctoolbox/irscrutinizer/GuiMain.java @@ -48,8 +48,6 @@ import java.util.Locale; import java.util.Map; import java.util.function.Function; -import java.util.logging.Level; -import java.util.logging.Logger; import javax.comm.DriverGenUnix; import javax.swing.DefaultComboBoxModel; import javax.swing.ImageIcon; @@ -1022,7 +1020,7 @@ private Command.CommandTextFormat[] setupExtraTextFormats() { formats.add(new BroadlinkHexFormatter()); if (properties.getExportGenerateBroadlinkBase64()) formats.add(new BroadlinkBase64Formatter()); - return formats.toArray(new Command.CommandTextFormat[formats.size()]); + return formats.toArray(new Command.CommandTextFormat[0]); } private GirrExporter newGirrExporter() { @@ -8738,7 +8736,7 @@ private void controlTowerManufacturerComboBoxActionPerformed(java.awt.event.Acti if (controlTowerIrDatabase == null) { controlTowerIrDatabase = new ControlTowerIrDatabase(properties.getVerbose()); Collection manufacturers = controlTowerIrDatabase.getManufacturers(); - String[] arr = manufacturers.toArray(new String[manufacturers.size()]); + String[] arr = manufacturers.toArray(new String[0]); //resetCursor(oldCursor); Arrays.sort(arr, String.CASE_INSENSITIVE_ORDER); DefaultComboBoxModel dcbm = new DefaultComboBoxModel(arr); @@ -8747,7 +8745,7 @@ private void controlTowerManufacturerComboBoxActionPerformed(java.awt.event.Acti } else { String manufacturer = (String) controlTowerManufacturerComboBox.getSelectedItem(); Collection devTypes = controlTowerIrDatabase.getDeviceTypes(manufacturer); - String[] arr = devTypes.toArray(new String[devTypes.size()]); + String[] arr = devTypes.toArray(new String[0]); Arrays.sort(arr, String.CASE_INSENSITIVE_ORDER); DefaultComboBoxModel dcbm = new DefaultComboBoxModel(arr); controlTowerDeviceTypeComboBox.setModel(dcbm); diff --git a/src/main/java/org/harctoolbox/irscrutinizer/exporter/ExportFormatManager.java b/src/main/java/org/harctoolbox/irscrutinizer/exporter/ExportFormatManager.java index 63ad2157..185286f8 100644 --- a/src/main/java/org/harctoolbox/irscrutinizer/exporter/ExportFormatManager.java +++ b/src/main/java/org/harctoolbox/irscrutinizer/exporter/ExportFormatManager.java @@ -137,7 +137,7 @@ public Set getNames() { public String[] toArray() { ArrayList list = new ArrayList<>(exportFormats.keySet()); Collections.sort(list, String.CASE_INSENSITIVE_ORDER); - return list.toArray(new String[list.size()]); + return list.toArray(new String[0]); } @SuppressWarnings("PublicInnerClass") diff --git a/src/main/java/org/harctoolbox/irscrutinizer/exporter/Exporter.java b/src/main/java/org/harctoolbox/irscrutinizer/exporter/Exporter.java index 329ad034..4f4fb721 100644 --- a/src/main/java/org/harctoolbox/irscrutinizer/exporter/Exporter.java +++ b/src/main/java/org/harctoolbox/irscrutinizer/exporter/Exporter.java @@ -152,6 +152,7 @@ protected static DocumentFragment parseToDocumentFragment(String str) { protected Exporter() { } + @SuppressWarnings("NoopMethodInAbstractClass") protected void possiblyMakeExecutable(File file) { } diff --git a/src/main/java/org/harctoolbox/irscrutinizer/importer/CsvImporter.java b/src/main/java/org/harctoolbox/irscrutinizer/importer/CsvImporter.java index cace4592..d1998fb7 100644 --- a/src/main/java/org/harctoolbox/irscrutinizer/importer/CsvImporter.java +++ b/src/main/java/org/harctoolbox/irscrutinizer/importer/CsvImporter.java @@ -92,7 +92,7 @@ protected static String[] gobbleString(String[] chunks, int column, boolean name } arrayList.add(chunk); } - return arrayList.toArray(new String[arrayList.size()]); + return arrayList.toArray(new String[0]); } protected static String join(String[] arr) { if (arr == null) diff --git a/src/main/java/org/harctoolbox/irscrutinizer/importer/CsvRawImporter.java b/src/main/java/org/harctoolbox/irscrutinizer/importer/CsvRawImporter.java index ff8295cd..7ec21c3c 100644 --- a/src/main/java/org/harctoolbox/irscrutinizer/importer/CsvRawImporter.java +++ b/src/main/java/org/harctoolbox/irscrutinizer/importer/CsvRawImporter.java @@ -132,7 +132,7 @@ private String[] csvSplit(String line, String separator) { } chunks.add(chunk.trim()); } - return chunks.toArray(new String[chunks.size()]); + return chunks.toArray(new String[0]); } @Override diff --git a/src/main/java/org/harctoolbox/irscrutinizer/importer/IrTransImporter.java b/src/main/java/org/harctoolbox/irscrutinizer/importer/IrTransImporter.java index a320e382..b403a62f 100644 --- a/src/main/java/org/harctoolbox/irscrutinizer/importer/IrTransImporter.java +++ b/src/main/java/org/harctoolbox/irscrutinizer/importer/IrTransImporter.java @@ -95,6 +95,7 @@ private String parseName(LineNumberReader reader) throws IOException, ParseExcep String line = reader.readLine(); if (line == null) throw new ParseException("[NAME] not found.", reader.getLineNumber()); + @SuppressWarnings("SingleCharRegex") String[] arr = line.trim().split("]"); if (!arr[0].equals("[NAME")) throw new ParseException("[NAME] not found.", reader.getLineNumber()); diff --git a/src/main/java/org/harctoolbox/irscrutinizer/importer/RemoteLocatorImporter.java b/src/main/java/org/harctoolbox/irscrutinizer/importer/RemoteLocatorImporter.java index 81a2a06a..ef347be2 100644 --- a/src/main/java/org/harctoolbox/irscrutinizer/importer/RemoteLocatorImporter.java +++ b/src/main/java/org/harctoolbox/irscrutinizer/importer/RemoteLocatorImporter.java @@ -76,7 +76,7 @@ public void clear() { public String[] getManufacturers() throws IOException, SAXException { assertDatabase(); List manufacturer = remoteDatabase.getManufacturers(); - return manufacturer.toArray(new String[manufacturer.size()]); + return manufacturer.toArray(new String[0]); } @Override @@ -100,12 +100,12 @@ public Remote.MetaData getMetaData() { public String[] getDeviceClasses(String manufacturer) throws NotFoundException { List deviceClasses = remoteDatabase.getDeviceTypes(manufacturer); - return deviceClasses.toArray(new String[deviceClasses.size()]); + return deviceClasses.toArray(new String[0]); } public String[] getRemotes(String manufacturer, String deviceType) throws NotFoundException { List remotes = remoteDatabase.getRemotes(manufacturer, deviceType); - return remotes.toArray(new String[remotes.size()]); + return remotes.toArray(new String[0]); } public void load(String manufacturer, String deviceType, String remoteName) throws NotFoundException {