From b6640e161c84a20695cce8fa1f18ac1b7774f5be Mon Sep 17 00:00:00 2001 From: "Vincent A. Cicirello" Date: Fri, 3 Jul 2026 15:46:37 -0400 Subject: [PATCH 1/3] fixed dead store --- src/main/java/org/cicirello/ibp/InteractiveBinPacking.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/cicirello/ibp/InteractiveBinPacking.java b/src/main/java/org/cicirello/ibp/InteractiveBinPacking.java index a9af535..e815ca2 100644 --- a/src/main/java/org/cicirello/ibp/InteractiveBinPacking.java +++ b/src/main/java/org/cicirello/ibp/InteractiveBinPacking.java @@ -86,6 +86,6 @@ public static void main(String[] args) { theFrame.setResizable(false); theFrame.setLocationRelativeTo(null); theFrame.setVisible(true); - About about = new About(theFrame); + new About(theFrame); } } From fe30bd12a2a9061197b342b864984d63afeec291 Mon Sep 17 00:00:00 2001 From: "Vincent A. Cicirello" Date: Fri, 3 Jul 2026 16:07:17 -0400 Subject: [PATCH 2/3] refactored checkInstance to eliminate brain method --- .../org/cicirello/ibp/SolutionValidator.java | 107 ++++++++++-------- 1 file changed, 62 insertions(+), 45 deletions(-) diff --git a/src/main/java/org/cicirello/ibp/SolutionValidator.java b/src/main/java/org/cicirello/ibp/SolutionValidator.java index 6307259..ea0315b 100644 --- a/src/main/java/org/cicirello/ibp/SolutionValidator.java +++ b/src/main/java/org/cicirello/ibp/SolutionValidator.java @@ -1,6 +1,6 @@ /* * Interactive Bin Packing. - * Copyright (C) 2021-2023 Vincent A. Cicirello + * Copyright (C) 2021-2026 Vincent A. Cicirello * * This file is part of Interactive Bin Packing. * @@ -188,67 +188,84 @@ boolean checkItemOrder(int[] sizes, String[] items, int modeNum) { return true; } - boolean checkInstance(int[] sizes, String[] items, String instance) { - boolean goodInstance = true; - HashMap foundItems = new HashMap(); - for (int i = 0; i < sizes.length; i++) { - if (foundItems.containsKey(items[i])) { - alertList.add("Duplicate items in solution."); - goodInstance = false; + private boolean checkDefaultInstance(HashMap foundItems, boolean goodInstance) { + int[] weights = {36, 33, 39, 43, 7, 19, 37, 8, 29, 28, 37, 23, 29, 10, 22, 11, 33, 9, 17, 30}; + char c = 'A'; + for (int i = 0; i < weights.length; i++, c = (char) (c + 1)) { + if (foundItems.containsKey("" + c)) { + int w = foundItems.get("" + c); + if (w != weights[i]) { + alertList.add("Wrong item size found in solution of default instance."); + goodInstance = false; + } } else { - foundItems.put(items[i], sizes[i]); + alertList.add("Unknown items found in solution of default instance."); + goodInstance = false; } } - if (instance.equals("Default")) { - int[] weights = {36, 33, 39, 43, 7, 19, 37, 8, 29, 28, 37, 23, 29, 10, 22, 11, 33, 9, 17, 30}; - char c = 'A'; - for (int i = 0; i < weights.length; i++, c = (char) (c + 1)) { - if (foundItems.containsKey("" + c)) { - int w = foundItems.get("" + c); - if (w != weights[i]) { - alertList.add("Wrong item size found in solution of default instance."); - goodInstance = false; - } - } else { - alertList.add("Unknown items found in solution of default instance."); + return goodInstance; + } + + private boolean checkRandomInstance( + HashMap foundItems, boolean goodInstance, int numItems) { + char c = 'A'; + for (int i = 0; i < numItems; i++, c = (char) (c + 1)) { + if (foundItems.containsKey("" + c)) { + int w = foundItems.get("" + c); + if (w < 20 || w > 50) { + alertList.add("Wrong item size found in solution of random instance."); goodInstance = false; } + } else { + alertList.add("Unknown items found in solution of random instance."); + goodInstance = false; } - } else if (instance.equals("Random")) { + } + return goodInstance; + } + + private boolean checkSeededInstance( + HashMap foundItems, boolean goodInstance, String instance) { + try { + long seed = Long.parseLong(instance.substring(1)); + int[] weights = ApplicationState.createRandomItemSizes(20, 50, 20, new Random(seed)); char c = 'A'; - for (int i = 0; i < items.length; i++, c = (char) (c + 1)) { + for (int i = 0; i < weights.length; i++, c = (char) (c + 1)) { if (foundItems.containsKey("" + c)) { int w = foundItems.get("" + c); - if (w < 20 || w > 50) { - alertList.add("Wrong item size found in solution of random instance."); + if (w != weights[i]) { + alertList.add("Wrong item size found in solution of instance: " + instance); goodInstance = false; } } else { - alertList.add("Unknown items found in solution of random instance."); + alertList.add("Unknown items found in solution of instance: " + instance); goodInstance = false; } } - } else if (instance.startsWith("#")) { - try { - long seed = Long.parseLong(instance.substring(1)); - int[] weights = ApplicationState.createRandomItemSizes(20, 50, 20, new Random(seed)); - char c = 'A'; - for (int i = 0; i < weights.length; i++, c = (char) (c + 1)) { - if (foundItems.containsKey("" + c)) { - int w = foundItems.get("" + c); - if (w != weights[i]) { - alertList.add("Wrong item size found in solution of instance: " + instance); - goodInstance = false; - } - } else { - alertList.add("Unknown items found in solution of instance: " + instance); - goodInstance = false; - } - } - } catch (NumberFormatException ex) { - alertList.add("Malformed instance number in solution."); + } catch (NumberFormatException ex) { + alertList.add("Malformed instance number in solution."); + goodInstance = false; + } + return goodInstance; + } + + boolean checkInstance(int[] sizes, String[] items, String instance) { + boolean goodInstance = true; + HashMap foundItems = new HashMap(); + for (int i = 0; i < sizes.length; i++) { + if (foundItems.containsKey(items[i])) { + alertList.add("Duplicate items in solution."); goodInstance = false; + } else { + foundItems.put(items[i], sizes[i]); } + } + if (instance.equals("Default")) { + goodInstance = checkDefaultInstance(foundItems, goodInstance); + } else if (instance.equals("Random")) { + goodInstance = checkRandomInstance(foundItems, goodInstance, items.length); + } else if (instance.startsWith("#")) { + goodInstance = checkSeededInstance(foundItems, goodInstance, instance); } else { alertList.add("Unknown instance type found in solution."); goodInstance = false; From ade6236040fdf4d45be41b4078ffda3751554f45 Mon Sep 17 00:00:00 2001 From: "Vincent A. Cicirello" Date: Fri, 3 Jul 2026 16:07:21 -0400 Subject: [PATCH 3/3] Update CHANGELOG.md --- CHANGELOG.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 935a2d1..35b7d54 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,9 +15,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Removed ### Fixed -* Fixed "constructor throws" in Bin class detected by SpotBugs -* Fixed "constructor throws" in InfoDialog class detected by SpotBugs +* Fixed "constructor throws" in Bin class detected by SpotBugs. +* Fixed "constructor throws" in InfoDialog class detected by SpotBugs. * Refactored MenuBar, UI, and other classes to eliminate class cycles based on RefactorFirst report. +* Refactored SolutionValidator.checkInstance based on RefactorFirst reporting as a brain method. ### Dependencies