From f31bac214349d1207f2d16d1039835107de1fc57 Mon Sep 17 00:00:00 2001 From: "Josiah (Gaming32) Glosson" Date: Thu, 30 Dec 2021 07:27:14 -0600 Subject: [PATCH 01/16] Create stats-config.txt --- src/main/ArrayVisualizer.java | 2 +- stats-config.txt | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 stats-config.txt diff --git a/src/main/ArrayVisualizer.java b/src/main/ArrayVisualizer.java index c068d3a7..d36676b2 100644 --- a/src/main/ArrayVisualizer.java +++ b/src/main/ArrayVisualizer.java @@ -543,7 +543,7 @@ private void drawStats(Color textColor, boolean dropShadow) { this.mainRender.drawString(this.statSnapshot.getMainWriteCount(), xOffset, (int) (windowRatio * 275) + yOffset); this.mainRender.drawString(this.statSnapshot.getAuxWriteCount(), xOffset, (int) (windowRatio * 300) + yOffset); this.mainRender.drawString(this.statSnapshot.getAuxAllocAmount(), xOffset, (int) (windowRatio * 325) + yOffset); - this.mainRender.drawString(this.statSnapshot.getSegments(), xOffset, (int) (windowRatio * 355) + yOffset); + this.mainRender.drawString(this.statSnapshot.getSegments(), xOffset, (int) (windowRatio * 350) + yOffset); } public void updateNow() { diff --git a/stats-config.txt b/stats-config.txt new file mode 100644 index 00000000..e773415b --- /dev/null +++ b/stats-config.txt @@ -0,0 +1,15 @@ +sort +length + +delay +vtime +stime + +comps +swaps +revs + +wmain +waux +auxlen +segments From 2f1c70996b3959ffbd594e4e694e930ef5b4929a Mon Sep 17 00:00:00 2001 From: "Josiah (Gaming32) Glosson" Date: Thu, 30 Dec 2021 08:48:20 -0600 Subject: [PATCH 02/16] Implement stats-config.txt --- src/main/ArrayVisualizer.java | 197 ++++++++++++++++++++++++++++++---- 1 file changed, 176 insertions(+), 21 deletions(-) diff --git a/src/main/ArrayVisualizer.java b/src/main/ArrayVisualizer.java index d36676b2..4e26b3ba 100644 --- a/src/main/ArrayVisualizer.java +++ b/src/main/ArrayVisualizer.java @@ -8,13 +8,13 @@ import java.awt.Graphics2D; import java.awt.Image; import java.awt.KeyEventDispatcher; +import java.awt.KeyboardFocusManager; import java.awt.Stroke; import java.awt.Toolkit; +import java.awt.datatransfer.DataFlavor; +import java.awt.dnd.DnDConstants; import java.awt.dnd.DropTarget; import java.awt.dnd.DropTargetDropEvent; -import java.awt.dnd.DnDConstants; -import java.awt.datatransfer.DataFlavor; -import java.awt.KeyboardFocusManager; import java.awt.event.ComponentEvent; import java.awt.event.ComponentListener; import java.awt.event.InputEvent; @@ -22,16 +22,20 @@ import java.awt.event.KeyListener; import java.awt.event.WindowEvent; import java.io.File; +import java.io.IOException; import java.math.RoundingMode; import java.text.DecimalFormat; import java.text.DecimalFormatSymbols; import java.text.NumberFormat; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; import java.util.Hashtable; import java.util.List; import java.util.Locale; import java.util.Map; +import java.util.Scanner; import javax.swing.JFrame; import javax.swing.JOptionPane; @@ -45,14 +49,35 @@ import main.SortAnalyzer.SortPair; import panes.JErrorPane; import threads.RunScriptedSorts; -import utils.*; +import utils.AntiQSort; +import utils.ArrayFileWriter; +import utils.Delays; +import utils.Highlights; +import utils.MultipleScript; +import utils.Reads; +import utils.Renderer; +import utils.Rotations; +import utils.Sounds; +import utils.Statistics; +import utils.Timer; +import utils.Writes; import visuals.Visual; import visuals.VisualStyles; -import visuals.bars.*; -import visuals.circles.*; -import visuals.dots.*; -import visuals.image.*; -import visuals.misc.*; +import visuals.bars.BarGraph; +import visuals.bars.DisparityBarGraph; +import visuals.bars.Rainbow; +import visuals.bars.SineWave; +import visuals.circles.ColorCircle; +import visuals.circles.DisparityChords; +import visuals.circles.DisparityCircle; +import visuals.circles.Spiral; +import visuals.dots.DisparityDots; +import visuals.dots.ScatterPlot; +import visuals.dots.SpiralDots; +import visuals.dots.WaveDots; +import visuals.image.CustomImage; +import visuals.misc.HoopStack; +import visuals.misc.PixelMesh; /* * @@ -86,6 +111,50 @@ of this software and associated documentation files (the "Software"), to deal final public class ArrayVisualizer { private static ArrayVisualizer INSTANCE = null; + private static final String STAT_LINE_BREAK_S = ""; + private static final String STAT_SORT_IDENTITY_S = "sort"; + private static final String STAT_ARRAY_LENGTH_S = "length"; + private static final String STAT_SORT_DELAY_S = "delay"; + private static final String STAT_VISUAL_TIME_S = "vtime"; + private static final String STAT_EST_SORT_TIME_S = "stime"; + private static final String STAT_COMPARISONS_S = "comps"; + private static final String STAT_SWAPS_S = "swaps"; + private static final String STAT_REVERSALS_S = "revs"; + private static final String STAT_MAIN_WRITE_S = "wmain"; + private static final String STAT_AUX_WRITE_S = "waux"; + private static final String STAT_AUX_ALLOC_S = "auxlen"; + private static final String STAT_SEGMENTS_S = "segments"; + + private static final int STAT_LINE_BREAK_I = 0; + private static final int STAT_SORT_IDENTITY_I = 1; + private static final int STAT_ARRAY_LENGTH_I = 2; + private static final int STAT_SORT_DELAY_I = 3; + private static final int STAT_VISUAL_TIME_I = 4; + private static final int STAT_EST_SORT_TIME_I = 5; + private static final int STAT_COMPARISONS_I = 6; + private static final int STAT_SWAPS_I = 7; + private static final int STAT_REVERSALS_I = 8; + private static final int STAT_MAIN_WRITE_I = 9; + private static final int STAT_AUX_WRITE_I = 10; + private static final int STAT_AUX_ALLOC_I = 11; + private static final int STAT_SEGMENTS_I = 12; + + private static final Map STAT_CONFIG_KEYS = Collections.unmodifiableMap(new HashMap() {{ + put(STAT_LINE_BREAK_S, STAT_LINE_BREAK_I); + put(STAT_SORT_IDENTITY_S, STAT_SORT_IDENTITY_I); + put(STAT_ARRAY_LENGTH_S, STAT_ARRAY_LENGTH_I); + put(STAT_SORT_DELAY_S, STAT_SORT_DELAY_I); + put(STAT_VISUAL_TIME_S, STAT_VISUAL_TIME_I); + put(STAT_EST_SORT_TIME_S, STAT_EST_SORT_TIME_I); + put(STAT_COMPARISONS_S, STAT_COMPARISONS_I); + put(STAT_SWAPS_S, STAT_SWAPS_I); + put(STAT_REVERSALS_S, STAT_REVERSALS_I); + put(STAT_MAIN_WRITE_S, STAT_MAIN_WRITE_I); + put(STAT_AUX_WRITE_S, STAT_AUX_WRITE_I); + put(STAT_AUX_ALLOC_S, STAT_AUX_ALLOC_I); + put(STAT_SEGMENTS_S, STAT_SEGMENTS_I); + }}); + final JFrame window; final private int MIN_ARRAY_VAL; @@ -96,6 +165,7 @@ final public class ArrayVisualizer { final int[] stabilityTable; final int[] indexTable; final ArrayList arrays; + private final int[] statsConfig; private SortPair[] AllSorts; // First row of Comparison/DistributionSorts arrays consists of class names private SortPair[] ComparisonSorts; // First row of Comparison/DistributionSorts arrays consists of class names @@ -321,6 +391,40 @@ public void run() { this.arrays = new ArrayList<>(); this.arrays.add(this.array); + List statsInfoList = new ArrayList<>(); + try (Scanner statsScanner = new Scanner(new File("stats-config.txt"))) { + while (statsScanner.hasNextLine()) { + String line = statsScanner.nextLine().trim(); + if (line.length() > 0 && line.charAt(0) == '#') continue; + Integer type = STAT_CONFIG_KEYS.get(line.toLowerCase()); + if (type == null) { + System.err.println("Unknown statistic type: " + type); + continue; + } + statsInfoList.add(type); + } + } catch (IOException e) { + statsInfoList = null; + JOptionPane.showMessageDialog( + this.window, + "Unable to load stats-config, using default", + "ArrayVisualizer", + JOptionPane.WARNING_MESSAGE + ); + } + if (statsInfoList == null) { + statsConfig = new int[] { + 1, 2, 0, + 3, 4, 5, 0, + 6, 7, 8, 0, + 9, 10, 11, 12, 0 + }; + } else { + statsConfig = statsInfoList.stream() + .mapToInt(Integer::intValue) + .toArray(); + } + this.sortLength = Math.min(2048, this.MAX_ARRAY_VAL); this.uniqueItems = this.sortLength; @@ -529,21 +633,72 @@ private void drawStats(Color textColor, boolean dropShadow) { } double windowRatio = this.getWindowRatio(); + int yPos = 30; this.mainRender.setColor(textColor); - this.mainRender.drawString(this.statSnapshot.getSortIdentity(), xOffset, (int) (windowRatio * 30) + yOffset); - this.mainRender.drawString(this.statSnapshot.getArrayLength(), xOffset, (int) (windowRatio * 55) + yOffset); - this.mainRender.drawString(this.statSnapshot.getSortDelay(), xOffset, (int) (windowRatio * 95) + yOffset); - this.mainRender.drawString(this.statSnapshot.getVisualTime(), xOffset, (int) (windowRatio * 120) + yOffset); - this.mainRender.drawString(this.statSnapshot.getEstSortTime(), xOffset, (int) (windowRatio * 145) + yOffset); - this.mainRender.drawString(this.statSnapshot.getComparisonCount(), xOffset, (int) (windowRatio * 185) + yOffset); - this.mainRender.drawString(this.statSnapshot.getSwapCount(), xOffset, (int) (windowRatio * 210) + yOffset); - this.mainRender.drawString(this.statSnapshot.getReversalCount(), xOffset, (int) (windowRatio * 235) + yOffset); - this.mainRender.drawString(this.statSnapshot.getMainWriteCount(), xOffset, (int) (windowRatio * 275) + yOffset); - this.mainRender.drawString(this.statSnapshot.getAuxWriteCount(), xOffset, (int) (windowRatio * 300) + yOffset); - this.mainRender.drawString(this.statSnapshot.getAuxAllocAmount(), xOffset, (int) (windowRatio * 325) + yOffset); - this.mainRender.drawString(this.statSnapshot.getSegments(), xOffset, (int) (windowRatio * 350) + yOffset); + // this.mainRender.drawString(this.statSnapshot.getSortIdentity(), xOffset, (int) (windowRatio * 30) + yOffset); + // this.mainRender.drawString(this.statSnapshot.getArrayLength(), xOffset, (int) (windowRatio * 55) + yOffset); + // this.mainRender.drawString(this.statSnapshot.getSortDelay(), xOffset, (int) (windowRatio * 95) + yOffset); + // this.mainRender.drawString(this.statSnapshot.getVisualTime(), xOffset, (int) (windowRatio * 120) + yOffset); + // this.mainRender.drawString(this.statSnapshot.getEstSortTime(), xOffset, (int) (windowRatio * 145) + yOffset); + // this.mainRender.drawString(this.statSnapshot.getComparisonCount(), xOffset, (int) (windowRatio * 185) + yOffset); + // this.mainRender.drawString(this.statSnapshot.getSwapCount(), xOffset, (int) (windowRatio * 210) + yOffset); + // this.mainRender.drawString(this.statSnapshot.getReversalCount(), xOffset, (int) (windowRatio * 235) + yOffset); + // this.mainRender.drawString(this.statSnapshot.getMainWriteCount(), xOffset, (int) (windowRatio * 275) + yOffset); + // this.mainRender.drawString(this.statSnapshot.getAuxWriteCount(), xOffset, (int) (windowRatio * 300) + yOffset); + // this.mainRender.drawString(this.statSnapshot.getAuxAllocAmount(), xOffset, (int) (windowRatio * 325) + yOffset); + // this.mainRender.drawString(this.statSnapshot.getSegments(), xOffset, (int) (windowRatio * 350) + yOffset); + statLoop: + for (int statType : statsConfig) { + // System.out.println(yPos); + String stat; + switch (statType) { + case STAT_LINE_BREAK_I: + yPos += 15; + continue statLoop; + case STAT_SORT_IDENTITY_I: + stat = statSnapshot.getSortIdentity(); + break; + case STAT_ARRAY_LENGTH_I: + stat = statSnapshot.getArrayLength(); + break; + case STAT_SORT_DELAY_I: + stat = statSnapshot.getSortDelay(); + break; + case STAT_VISUAL_TIME_I: + stat = statSnapshot.getVisualTime(); + break; + case STAT_EST_SORT_TIME_I: + stat = statSnapshot.getEstSortTime(); + break; + case STAT_COMPARISONS_I: + stat = statSnapshot.getComparisonCount(); + break; + case STAT_SWAPS_I: + stat = statSnapshot.getSwapCount(); + break; + case STAT_REVERSALS_I: + stat = statSnapshot.getReversalCount(); + break; + case STAT_MAIN_WRITE_I: + stat = statSnapshot.getMainWriteCount(); + break; + case STAT_AUX_WRITE_I: + stat = statSnapshot.getAuxWriteCount(); + break; + case STAT_AUX_ALLOC_I: + stat = statSnapshot.getAuxAllocAmount(); + break; + case STAT_SEGMENTS_I: + stat = statSnapshot.getSegments(); + break; + default: + stat = null; // Unreachable + } + mainRender.drawString(stat, xOffset, (int)(windowRatio * yPos) + yOffset); + yPos += 25; + } } public void updateNow() { From cf89a60f18b712038b4b0fbb09575cb679339b7e Mon Sep 17 00:00:00 2001 From: "Josiah (Gaming32) Glosson" Date: Thu, 30 Dec 2021 08:50:40 -0600 Subject: [PATCH 03/16] Some code cleanup --- src/main/ArrayVisualizer.java | 92 +++++++++++++++-------------------- 1 file changed, 39 insertions(+), 53 deletions(-) diff --git a/src/main/ArrayVisualizer.java b/src/main/ArrayVisualizer.java index 4e26b3ba..8e7d4947 100644 --- a/src/main/ArrayVisualizer.java +++ b/src/main/ArrayVisualizer.java @@ -111,48 +111,34 @@ of this software and associated documentation files (the "Software"), to deal final public class ArrayVisualizer { private static ArrayVisualizer INSTANCE = null; - private static final String STAT_LINE_BREAK_S = ""; - private static final String STAT_SORT_IDENTITY_S = "sort"; - private static final String STAT_ARRAY_LENGTH_S = "length"; - private static final String STAT_SORT_DELAY_S = "delay"; - private static final String STAT_VISUAL_TIME_S = "vtime"; - private static final String STAT_EST_SORT_TIME_S = "stime"; - private static final String STAT_COMPARISONS_S = "comps"; - private static final String STAT_SWAPS_S = "swaps"; - private static final String STAT_REVERSALS_S = "revs"; - private static final String STAT_MAIN_WRITE_S = "wmain"; - private static final String STAT_AUX_WRITE_S = "waux"; - private static final String STAT_AUX_ALLOC_S = "auxlen"; - private static final String STAT_SEGMENTS_S = "segments"; - - private static final int STAT_LINE_BREAK_I = 0; - private static final int STAT_SORT_IDENTITY_I = 1; - private static final int STAT_ARRAY_LENGTH_I = 2; - private static final int STAT_SORT_DELAY_I = 3; - private static final int STAT_VISUAL_TIME_I = 4; - private static final int STAT_EST_SORT_TIME_I = 5; - private static final int STAT_COMPARISONS_I = 6; - private static final int STAT_SWAPS_I = 7; - private static final int STAT_REVERSALS_I = 8; - private static final int STAT_MAIN_WRITE_I = 9; - private static final int STAT_AUX_WRITE_I = 10; - private static final int STAT_AUX_ALLOC_I = 11; - private static final int STAT_SEGMENTS_I = 12; + private static final int STAT_LINE_BREAK = 0; + private static final int STAT_SORT_IDENTITY = 1; + private static final int STAT_ARRAY_LENGTH = 2; + private static final int STAT_SORT_DELAY = 3; + private static final int STAT_VISUAL_TIME = 4; + private static final int STAT_EST_SORT_TIME = 5; + private static final int STAT_COMPARISONS = 6; + private static final int STAT_SWAPS = 7; + private static final int STAT_REVERSALS = 8; + private static final int STAT_MAIN_WRITE = 9; + private static final int STAT_AUX_WRITE = 10; + private static final int STAT_AUX_ALLOC = 11; + private static final int STAT_SEGMENTS = 12; private static final Map STAT_CONFIG_KEYS = Collections.unmodifiableMap(new HashMap() {{ - put(STAT_LINE_BREAK_S, STAT_LINE_BREAK_I); - put(STAT_SORT_IDENTITY_S, STAT_SORT_IDENTITY_I); - put(STAT_ARRAY_LENGTH_S, STAT_ARRAY_LENGTH_I); - put(STAT_SORT_DELAY_S, STAT_SORT_DELAY_I); - put(STAT_VISUAL_TIME_S, STAT_VISUAL_TIME_I); - put(STAT_EST_SORT_TIME_S, STAT_EST_SORT_TIME_I); - put(STAT_COMPARISONS_S, STAT_COMPARISONS_I); - put(STAT_SWAPS_S, STAT_SWAPS_I); - put(STAT_REVERSALS_S, STAT_REVERSALS_I); - put(STAT_MAIN_WRITE_S, STAT_MAIN_WRITE_I); - put(STAT_AUX_WRITE_S, STAT_AUX_WRITE_I); - put(STAT_AUX_ALLOC_S, STAT_AUX_ALLOC_I); - put(STAT_SEGMENTS_S, STAT_SEGMENTS_I); + put("", STAT_LINE_BREAK); + put("sort", STAT_SORT_IDENTITY); + put("length", STAT_ARRAY_LENGTH); + put("delay", STAT_SORT_DELAY); + put("vtime", STAT_VISUAL_TIME); + put("stime", STAT_EST_SORT_TIME); + put("comps", STAT_COMPARISONS); + put("swaps", STAT_SWAPS); + put("revs", STAT_REVERSALS); + put("wmain", STAT_MAIN_WRITE); + put("waux", STAT_AUX_WRITE); + put("auxlen", STAT_AUX_ALLOC); + put("segments", STAT_SEGMENTS); }}); final JFrame window; @@ -654,43 +640,43 @@ private void drawStats(Color textColor, boolean dropShadow) { // System.out.println(yPos); String stat; switch (statType) { - case STAT_LINE_BREAK_I: + case STAT_LINE_BREAK: yPos += 15; continue statLoop; - case STAT_SORT_IDENTITY_I: + case STAT_SORT_IDENTITY: stat = statSnapshot.getSortIdentity(); break; - case STAT_ARRAY_LENGTH_I: + case STAT_ARRAY_LENGTH: stat = statSnapshot.getArrayLength(); break; - case STAT_SORT_DELAY_I: + case STAT_SORT_DELAY: stat = statSnapshot.getSortDelay(); break; - case STAT_VISUAL_TIME_I: + case STAT_VISUAL_TIME: stat = statSnapshot.getVisualTime(); break; - case STAT_EST_SORT_TIME_I: + case STAT_EST_SORT_TIME: stat = statSnapshot.getEstSortTime(); break; - case STAT_COMPARISONS_I: + case STAT_COMPARISONS: stat = statSnapshot.getComparisonCount(); break; - case STAT_SWAPS_I: + case STAT_SWAPS: stat = statSnapshot.getSwapCount(); break; - case STAT_REVERSALS_I: + case STAT_REVERSALS: stat = statSnapshot.getReversalCount(); break; - case STAT_MAIN_WRITE_I: + case STAT_MAIN_WRITE: stat = statSnapshot.getMainWriteCount(); break; - case STAT_AUX_WRITE_I: + case STAT_AUX_WRITE: stat = statSnapshot.getAuxWriteCount(); break; - case STAT_AUX_ALLOC_I: + case STAT_AUX_ALLOC: stat = statSnapshot.getAuxAllocAmount(); break; - case STAT_SEGMENTS_I: + case STAT_SEGMENTS: stat = statSnapshot.getSegments(); break; default: From 56beac89e0e0db894c7ef8cba32eddb2f1958d5d Mon Sep 17 00:00:00 2001 From: "Josiah (Gaming32) Glosson" Date: Thu, 30 Dec 2021 09:00:08 -0600 Subject: [PATCH 04/16] Improve error messages --- src/main/ArrayVisualizer.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/ArrayVisualizer.java b/src/main/ArrayVisualizer.java index 8e7d4947..43072fb1 100644 --- a/src/main/ArrayVisualizer.java +++ b/src/main/ArrayVisualizer.java @@ -389,11 +389,12 @@ public void run() { } statsInfoList.add(type); } - } catch (IOException e) { + } catch (Exception e) { statsInfoList = null; + JErrorPane.invokeErrorMessage(e, "ArrayVisualizer"); JOptionPane.showMessageDialog( this.window, - "Unable to load stats-config, using default", + "Unable to load stats-config, using default config", "ArrayVisualizer", JOptionPane.WARNING_MESSAGE ); From 1a32c6f5af28fcb68b750b513cb3c8a82bb8edcc Mon Sep 17 00:00:00 2001 From: "Josiah (Gaming32) Glosson" Date: Thu, 30 Dec 2021 09:28:46 -0600 Subject: [PATCH 05/16] Add FPS statistic --- src/main/ArrayVisualizer.java | 26 +++++++++++++------------- src/utils/Statistics.java | 28 +++++++++++++++++----------- stats-config.txt | 2 ++ 3 files changed, 32 insertions(+), 24 deletions(-) diff --git a/src/main/ArrayVisualizer.java b/src/main/ArrayVisualizer.java index 43072fb1..e5d6110c 100644 --- a/src/main/ArrayVisualizer.java +++ b/src/main/ArrayVisualizer.java @@ -22,7 +22,6 @@ import java.awt.event.KeyListener; import java.awt.event.WindowEvent; import java.io.File; -import java.io.IOException; import java.math.RoundingMode; import java.text.DecimalFormat; import java.text.DecimalFormatSymbols; @@ -114,6 +113,7 @@ final public class ArrayVisualizer { private static final int STAT_LINE_BREAK = 0; private static final int STAT_SORT_IDENTITY = 1; private static final int STAT_ARRAY_LENGTH = 2; + private static final int STAT_FRAMERATE = 13; private static final int STAT_SORT_DELAY = 3; private static final int STAT_VISUAL_TIME = 4; private static final int STAT_EST_SORT_TIME = 5; @@ -129,6 +129,7 @@ final public class ArrayVisualizer { put("", STAT_LINE_BREAK); put("sort", STAT_SORT_IDENTITY); put("length", STAT_ARRAY_LENGTH); + put("fps", STAT_FRAMERATE); put("delay", STAT_SORT_DELAY); put("vtime", STAT_VISUAL_TIME); put("stime", STAT_EST_SORT_TIME); @@ -545,7 +546,7 @@ public void run() { ArrayVisualizer.this.visualClasses[13] = new Spiral(ArrayVisualizer.this); ArrayVisualizer.this.visualClasses[14] = new SpiralDots(ArrayVisualizer.this); - while(ArrayVisualizer.this.visualsEnabled) { + while (ArrayVisualizer.this.visualsEnabled) { if (ArrayVisualizer.this.updateVisualsForced == 0) { try { synchronized (ArrayVisualizer.this) { @@ -555,6 +556,7 @@ public void run() { e.printStackTrace(); } } + long startTime = System.currentTimeMillis(); try { if(ArrayVisualizer.this.updateVisualsForced > 0) { ArrayVisualizer.this.updateVisualsForced--; @@ -574,19 +576,14 @@ public void run() { if (ArrayVisualizer.this.updateVisualsForced > 10000) { ArrayVisualizer.this.updateVisualsForced = 100; } - } - catch (Exception e) { + } catch (Exception e) { e.printStackTrace(); } - // See: https://stackoverflow.com/questions/580419/how-can-i-stop-a-java-while-loop-from-eating-50-of-my-cpu/583537#583537 - try { - Thread.sleep(ArrayVisualizer.this.benchmarking ? 1000 : 0); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - ArrayVisualizer.this.visualsEnabled = false; - } - - }}}; + long endTime = System.currentTimeMillis(); + statSnapshot.frameTimeMillis = endTime - startTime; + } + } + }; this.Sounds.startAudioThread(); this.drawWindows(); @@ -650,6 +647,9 @@ private void drawStats(Color textColor, boolean dropShadow) { case STAT_ARRAY_LENGTH: stat = statSnapshot.getArrayLength(); break; + case STAT_FRAMERATE: + stat = statSnapshot.getFramerate(); + break; case STAT_SORT_DELAY: stat = statSnapshot.getSortDelay(); break; diff --git a/src/utils/Statistics.java b/src/utils/Statistics.java index 18e23c21..828b0fae 100644 --- a/src/utils/Statistics.java +++ b/src/utils/Statistics.java @@ -5,28 +5,31 @@ import main.ArrayVisualizer; final public class Statistics { + public long frameTimeMillis; + private String sortCategory; private String sortHeading; private String sortExtraHeading; private String arrayLength; - + + private String framerate; private String sortDelay; private String visualTime; private String estSortTime; - + private String comparisonCount; private String swapCount; private String reversalCount; - + private String mainWriteCount; private String auxWriteCount; private String auxAllocAmount; private String segments; - + private DecimalFormat formatter; - + public Statistics(ArrayVisualizer ArrayVisualizer) { this.formatter = ArrayVisualizer.getNumberFormat(); this.updateStats(ArrayVisualizer); @@ -51,17 +54,18 @@ public void updateStats(ArrayVisualizer ArrayVisualizer) { this.sortHeading = ArrayVisualizer.getHeading(); this.sortExtraHeading = ArrayVisualizer.getExtraHeading(); int showUnique = Math.min(ArrayVisualizer.getUniqueItems(), ArrayVisualizer.getCurrentLength()); - this.arrayLength = this.formatter.format(ArrayVisualizer.getCurrentLength()) + " Numbers" + this.arrayLength = this.formatter.format(ArrayVisualizer.getCurrentLength()) + " Numbers" + ", " + this.formatter.format(showUnique) + " Unique"; - + + this.framerate = (1000.0 / frameTimeMillis) + " FPS"; this.sortDelay = "Delay: " + ArrayVisualizer.getDelays().displayCurrentDelay(); this.visualTime = "Visual Time: " + ArrayVisualizer.getTimer().getVisualTime(); this.estSortTime = "Sort Time: " + ArrayVisualizer.getTimer().getRealTime(); - + this.comparisonCount = ArrayVisualizer.getReads().getStats(); this.swapCount = ArrayVisualizer.getWrites().getSwaps(); this.reversalCount = ArrayVisualizer.getWrites().getReversals(); - + this.mainWriteCount = ArrayVisualizer.getWrites().getMainWrites(); this.auxWriteCount = ArrayVisualizer.getWrites().getAuxWrites(); @@ -72,13 +76,16 @@ public void updateStats(ArrayVisualizer ArrayVisualizer) { String plural = rawSegments[0] == 1 ? "" : "s"; this.segments = String.valueOf(rawSegments[1]) + "% Sorted (" + String.valueOf(rawSegments[0]) + " Segment" + plural + ")"; } - + public String getSortIdentity() { return this.sortCategory + ": " + this.sortHeading; } public String getArrayLength() { return this.arrayLength + this.sortExtraHeading; } + public String getFramerate() { + return this.framerate; + } public String getSortDelay() { return this.sortDelay; } @@ -106,7 +113,6 @@ public String getAuxWriteCount() { public String getAuxAllocAmount() { return this.auxAllocAmount; } - public String getSegments() { return this.segments; } diff --git a/stats-config.txt b/stats-config.txt index e773415b..72d7f1ab 100644 --- a/stats-config.txt +++ b/stats-config.txt @@ -1,3 +1,5 @@ +# fps +# sort length From ced226446e2c1e916842e37ecafa3329d043cfc2 Mon Sep 17 00:00:00 2001 From: "Josiah (Gaming32) Glosson" Date: Thu, 30 Dec 2021 13:40:26 -0600 Subject: [PATCH 06/16] Change the font family and scale NOTE: This does *not* change spacing between lines, so larger text sizes may look strange --- src/main/ArrayVisualizer.java | 20 +++++++++++++++++--- stats-config.txt | 1 + 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/main/ArrayVisualizer.java b/src/main/ArrayVisualizer.java index e5d6110c..cd161baf 100644 --- a/src/main/ArrayVisualizer.java +++ b/src/main/ArrayVisualizer.java @@ -194,6 +194,7 @@ final public class ArrayVisualizer { private Statistics statSnapshot; private String fontSelection; + private int fontSelectionScale; private volatile boolean TEXTDRAW; private volatile boolean COLOR; @@ -378,11 +379,25 @@ public void run() { this.arrays = new ArrayList<>(); this.arrays.add(this.array); + this.fontSelection = "Times New Roman"; + this.fontSelectionScale = 25; List statsInfoList = new ArrayList<>(); try (Scanner statsScanner = new Scanner(new File("stats-config.txt"))) { while (statsScanner.hasNextLine()) { String line = statsScanner.nextLine().trim(); if (line.length() > 0 && line.charAt(0) == '#') continue; + if (line.startsWith("FONT: ")) { + String font = line.substring(5); + int fontScale = 25; + int starIndex; + if ((starIndex = font.indexOf('*')) != -1) { + fontScale = Integer.parseInt(font.substring(starIndex + 1).trim()); + font = font.substring(0, starIndex); + } + fontSelection = font.trim(); + fontSelectionScale = fontScale; + continue; + } Integer type = STAT_CONFIG_KEYS.get(line.toLowerCase()); if (type == null) { System.err.println("Unknown statistic type: " + type); @@ -474,8 +489,7 @@ public void run() { this.category = ""; this.heading = ""; this.extraHeading = ""; - this.fontSelection = "Times New Roman"; - this.typeFace = new Font(this.fontSelection, Font.PLAIN, (int) (this.getWindowRatio() * 25)); + this.typeFace = new Font(fontSelection, Font.PLAIN, (int) (this.getWindowRatio() * fontSelectionScale)); this.statSnapshot = new Statistics(this); @@ -1110,7 +1124,7 @@ public double getWindowRatio() { return this.cw / 1280d; } public void updateFontSize() { - this.typeFace = new Font(this.fontSelection, Font.PLAIN, (int) (this.getWindowRatio() * 25)); + this.typeFace = new Font(fontSelection, Font.PLAIN, (int) (this.getWindowRatio() * fontSelectionScale)); this.mainRender.setFont(this.typeFace); } diff --git a/stats-config.txt b/stats-config.txt index 72d7f1ab..cd273a8a 100644 --- a/stats-config.txt +++ b/stats-config.txt @@ -1,3 +1,4 @@ +FONT: Times New Roman * 25 # fps # sort From 257acbd76f930724a247c66a33f479d7db768007 Mon Sep 17 00:00:00 2001 From: "Josiah (Gaming32) Glosson" Date: Thu, 30 Dec 2021 14:39:59 -0600 Subject: [PATCH 07/16] Fix bug --- src/main/ArrayVisualizer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/ArrayVisualizer.java b/src/main/ArrayVisualizer.java index cd161baf..8aa116f4 100644 --- a/src/main/ArrayVisualizer.java +++ b/src/main/ArrayVisualizer.java @@ -386,7 +386,7 @@ public void run() { while (statsScanner.hasNextLine()) { String line = statsScanner.nextLine().trim(); if (line.length() > 0 && line.charAt(0) == '#') continue; - if (line.startsWith("FONT: ")) { + if (line.startsWith("FONT:")) { String font = line.substring(5); int fontScale = 25; int starIndex; From 014cf78551d87ebad69daec8f1ae02b0ec59a766 Mon Sep 17 00:00:00 2001 From: "Josiah (Gaming32) Glosson" Date: Thu, 30 Dec 2021 16:22:22 -0600 Subject: [PATCH 08/16] Reposition the font too --- src/main/ArrayVisualizer.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/ArrayVisualizer.java b/src/main/ArrayVisualizer.java index 8aa116f4..db85b779 100644 --- a/src/main/ArrayVisualizer.java +++ b/src/main/ArrayVisualizer.java @@ -631,7 +631,7 @@ private void drawStats(Color textColor, boolean dropShadow) { } double windowRatio = this.getWindowRatio(); - int yPos = 30; + int yPos = (int)(fontSelectionScale / 25.0 * 30); this.mainRender.setColor(textColor); @@ -653,7 +653,7 @@ private void drawStats(Color textColor, boolean dropShadow) { String stat; switch (statType) { case STAT_LINE_BREAK: - yPos += 15; + yPos += fontSelectionScale / 25.0 * 15; continue statLoop; case STAT_SORT_IDENTITY: stat = statSnapshot.getSortIdentity(); @@ -698,7 +698,7 @@ private void drawStats(Color textColor, boolean dropShadow) { stat = null; // Unreachable } mainRender.drawString(stat, xOffset, (int)(windowRatio * yPos) + yOffset); - yPos += 25; + yPos += fontSelectionScale; } } From a26ea0bf576ed469c648f4c02f745d9a06b3fbe9 Mon Sep 17 00:00:00 2001 From: "Josiah (Gaming32) Glosson" Date: Thu, 30 Dec 2021 17:18:50 -0600 Subject: [PATCH 09/16] Use constants for default --- src/main/ArrayVisualizer.java | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/main/ArrayVisualizer.java b/src/main/ArrayVisualizer.java index db85b779..2c172ebc 100644 --- a/src/main/ArrayVisualizer.java +++ b/src/main/ArrayVisualizer.java @@ -417,10 +417,21 @@ public void run() { } if (statsInfoList == null) { statsConfig = new int[] { - 1, 2, 0, - 3, 4, 5, 0, - 6, 7, 8, 0, - 9, 10, 11, 12, 0 + STAT_SORT_IDENTITY, + STAT_ARRAY_LENGTH, + STAT_LINE_BREAK, + STAT_SORT_DELAY, + STAT_VISUAL_TIME, + STAT_EST_SORT_TIME, + STAT_LINE_BREAK, + STAT_COMPARISONS, + STAT_SWAPS, + STAT_REVERSALS, + STAT_LINE_BREAK, + STAT_MAIN_WRITE, + STAT_AUX_WRITE, + STAT_AUX_ALLOC, + STAT_SEGMENTS }; } else { statsConfig = statsInfoList.stream() From a430242ec09f25b9bfb2b6fd69e4ae15ec017c2d Mon Sep 17 00:00:00 2001 From: "Josiah (Gaming32) Glosson" Date: Thu, 30 Dec 2021 17:20:21 -0600 Subject: [PATCH 10/16] Change numbers for STAT_ constants --- src/main/ArrayVisualizer.java | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/main/ArrayVisualizer.java b/src/main/ArrayVisualizer.java index 2c172ebc..6984973e 100644 --- a/src/main/ArrayVisualizer.java +++ b/src/main/ArrayVisualizer.java @@ -113,17 +113,17 @@ final public class ArrayVisualizer { private static final int STAT_LINE_BREAK = 0; private static final int STAT_SORT_IDENTITY = 1; private static final int STAT_ARRAY_LENGTH = 2; - private static final int STAT_FRAMERATE = 13; - private static final int STAT_SORT_DELAY = 3; - private static final int STAT_VISUAL_TIME = 4; - private static final int STAT_EST_SORT_TIME = 5; - private static final int STAT_COMPARISONS = 6; - private static final int STAT_SWAPS = 7; - private static final int STAT_REVERSALS = 8; - private static final int STAT_MAIN_WRITE = 9; - private static final int STAT_AUX_WRITE = 10; - private static final int STAT_AUX_ALLOC = 11; - private static final int STAT_SEGMENTS = 12; + private static final int STAT_FRAMERATE = 3; + private static final int STAT_SORT_DELAY = 4; + private static final int STAT_VISUAL_TIME = 5; + private static final int STAT_EST_SORT_TIME = 6; + private static final int STAT_COMPARISONS = 7; + private static final int STAT_SWAPS = 8; + private static final int STAT_REVERSALS = 9; + private static final int STAT_MAIN_WRITE = 10; + private static final int STAT_AUX_WRITE = 11; + private static final int STAT_AUX_ALLOC = 12; + private static final int STAT_SEGMENTS = 13; private static final Map STAT_CONFIG_KEYS = Collections.unmodifiableMap(new HashMap() {{ put("", STAT_LINE_BREAK); From ed3eeea5c4074ae26a9df406fc45d76842813a02 Mon Sep 17 00:00:00 2001 From: "Josiah (Gaming32) Glosson" Date: Thu, 30 Dec 2021 18:32:32 -0600 Subject: [PATCH 11/16] Remove comments --- src/main/ArrayVisualizer.java | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/src/main/ArrayVisualizer.java b/src/main/ArrayVisualizer.java index 6984973e..23c6d9c6 100644 --- a/src/main/ArrayVisualizer.java +++ b/src/main/ArrayVisualizer.java @@ -646,18 +646,6 @@ private void drawStats(Color textColor, boolean dropShadow) { this.mainRender.setColor(textColor); - // this.mainRender.drawString(this.statSnapshot.getSortIdentity(), xOffset, (int) (windowRatio * 30) + yOffset); - // this.mainRender.drawString(this.statSnapshot.getArrayLength(), xOffset, (int) (windowRatio * 55) + yOffset); - // this.mainRender.drawString(this.statSnapshot.getSortDelay(), xOffset, (int) (windowRatio * 95) + yOffset); - // this.mainRender.drawString(this.statSnapshot.getVisualTime(), xOffset, (int) (windowRatio * 120) + yOffset); - // this.mainRender.drawString(this.statSnapshot.getEstSortTime(), xOffset, (int) (windowRatio * 145) + yOffset); - // this.mainRender.drawString(this.statSnapshot.getComparisonCount(), xOffset, (int) (windowRatio * 185) + yOffset); - // this.mainRender.drawString(this.statSnapshot.getSwapCount(), xOffset, (int) (windowRatio * 210) + yOffset); - // this.mainRender.drawString(this.statSnapshot.getReversalCount(), xOffset, (int) (windowRatio * 235) + yOffset); - // this.mainRender.drawString(this.statSnapshot.getMainWriteCount(), xOffset, (int) (windowRatio * 275) + yOffset); - // this.mainRender.drawString(this.statSnapshot.getAuxWriteCount(), xOffset, (int) (windowRatio * 300) + yOffset); - // this.mainRender.drawString(this.statSnapshot.getAuxAllocAmount(), xOffset, (int) (windowRatio * 325) + yOffset); - // this.mainRender.drawString(this.statSnapshot.getSegments(), xOffset, (int) (windowRatio * 350) + yOffset); statLoop: for (int statType : statsConfig) { // System.out.println(yPos); From d22487d0ddecc554d3af4a0b44c8dc99338c0bc1 Mon Sep 17 00:00:00 2001 From: "Josiah (Gaming32) Glosson" Date: Thu, 30 Dec 2021 20:23:35 -0600 Subject: [PATCH 12/16] Shuffle some code arround --- src/main/ArrayVisualizer.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/ArrayVisualizer.java b/src/main/ArrayVisualizer.java index 23c6d9c6..88c039d6 100644 --- a/src/main/ArrayVisualizer.java +++ b/src/main/ArrayVisualizer.java @@ -388,14 +388,12 @@ public void run() { if (line.length() > 0 && line.charAt(0) == '#') continue; if (line.startsWith("FONT:")) { String font = line.substring(5); - int fontScale = 25; int starIndex; if ((starIndex = font.indexOf('*')) != -1) { - fontScale = Integer.parseInt(font.substring(starIndex + 1).trim()); + fontSelectionScale = Integer.parseInt(font.substring(starIndex + 1).trim()); font = font.substring(0, starIndex); } fontSelection = font.trim(); - fontSelectionScale = fontScale; continue; } Integer type = STAT_CONFIG_KEYS.get(line.toLowerCase()); From 6a51f13c746058fb53b33fa9177c5e2e635aca7c Mon Sep 17 00:00:00 2001 From: "Josiah (Gaming32) Glosson" Date: Thu, 30 Dec 2021 20:26:02 -0600 Subject: [PATCH 13/16] Truncate FPS visual --- src/utils/Statistics.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/utils/Statistics.java b/src/utils/Statistics.java index 828b0fae..fa9e0f71 100644 --- a/src/utils/Statistics.java +++ b/src/utils/Statistics.java @@ -57,7 +57,11 @@ public void updateStats(ArrayVisualizer ArrayVisualizer) { this.arrayLength = this.formatter.format(ArrayVisualizer.getCurrentLength()) + " Numbers" + ", " + this.formatter.format(showUnique) + " Unique"; - this.framerate = (1000.0 / frameTimeMillis) + " FPS"; + if (frameTimeMillis == 0) { + this.framerate = ">1000 FPS"; + } else { + this.framerate = (int)(1000.0 / frameTimeMillis) + " FPS"; + } this.sortDelay = "Delay: " + ArrayVisualizer.getDelays().displayCurrentDelay(); this.visualTime = "Visual Time: " + ArrayVisualizer.getTimer().getVisualTime(); this.estSortTime = "Sort Time: " + ArrayVisualizer.getTimer().getRealTime(); From 10edae549ddfe7e53e8c0c2a8d6456989ec56253 Mon Sep 17 00:00:00 2001 From: "Josiah (Gaming32) Glosson" Date: Thu, 30 Dec 2021 20:27:18 -0600 Subject: [PATCH 14/16] Make cast --- src/main/ArrayVisualizer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/ArrayVisualizer.java b/src/main/ArrayVisualizer.java index 88c039d6..61f06786 100644 --- a/src/main/ArrayVisualizer.java +++ b/src/main/ArrayVisualizer.java @@ -650,7 +650,7 @@ private void drawStats(Color textColor, boolean dropShadow) { String stat; switch (statType) { case STAT_LINE_BREAK: - yPos += fontSelectionScale / 25.0 * 15; + yPos += (int)(fontSelectionScale / 25.0 * 15); continue statLoop; case STAT_SORT_IDENTITY: stat = statSnapshot.getSortIdentity(); From 49812dafe55e2a33f672e72d5d78bda34e5bbf81 Mon Sep 17 00:00:00 2001 From: EmeraldBlock Date: Fri, 31 Dec 2021 12:33:24 -0600 Subject: [PATCH 15/16] use enum --- src/main/ArrayVisualizer.java | 136 +++++++++++++++++----------------- 1 file changed, 68 insertions(+), 68 deletions(-) diff --git a/src/main/ArrayVisualizer.java b/src/main/ArrayVisualizer.java index 61f06786..d81ad153 100644 --- a/src/main/ArrayVisualizer.java +++ b/src/main/ArrayVisualizer.java @@ -110,37 +110,39 @@ of this software and associated documentation files (the "Software"), to deal final public class ArrayVisualizer { private static ArrayVisualizer INSTANCE = null; - private static final int STAT_LINE_BREAK = 0; - private static final int STAT_SORT_IDENTITY = 1; - private static final int STAT_ARRAY_LENGTH = 2; - private static final int STAT_FRAMERATE = 3; - private static final int STAT_SORT_DELAY = 4; - private static final int STAT_VISUAL_TIME = 5; - private static final int STAT_EST_SORT_TIME = 6; - private static final int STAT_COMPARISONS = 7; - private static final int STAT_SWAPS = 8; - private static final int STAT_REVERSALS = 9; - private static final int STAT_MAIN_WRITE = 10; - private static final int STAT_AUX_WRITE = 11; - private static final int STAT_AUX_ALLOC = 12; - private static final int STAT_SEGMENTS = 13; - - private static final Map STAT_CONFIG_KEYS = Collections.unmodifiableMap(new HashMap() {{ - put("", STAT_LINE_BREAK); - put("sort", STAT_SORT_IDENTITY); - put("length", STAT_ARRAY_LENGTH); - put("fps", STAT_FRAMERATE); - put("delay", STAT_SORT_DELAY); - put("vtime", STAT_VISUAL_TIME); - put("stime", STAT_EST_SORT_TIME); - put("comps", STAT_COMPARISONS); - put("swaps", STAT_SWAPS); - put("revs", STAT_REVERSALS); - put("wmain", STAT_MAIN_WRITE); - put("waux", STAT_AUX_WRITE); - put("auxlen", STAT_AUX_ALLOC); - put("segments", STAT_SEGMENTS); - }}); + private enum Stat { + LINE_BREAK, + SORT_IDENTITY, + ARRAY_LENGTH, + FRAMERATE, + SORT_DELAY, + VISUAL_TIME, + EST_SORT_TIME, + COMPARISONS, + SWAPS, + REVERSALS, + MAIN_WRITE, + AUX_WRITE, + AUX_ALLOC, + SEGMENTS; + + private static final Map CONFIG_KEYS = Collections.unmodifiableMap(new HashMap() {{ + put("", LINE_BREAK); + put("sort", SORT_IDENTITY); + put("length", ARRAY_LENGTH); + put("fps", FRAMERATE); + put("delay", SORT_DELAY); + put("vtime", VISUAL_TIME); + put("stime", EST_SORT_TIME); + put("comps", COMPARISONS); + put("swaps", SWAPS); + put("revs", REVERSALS); + put("wmain", MAIN_WRITE); + put("waux", AUX_WRITE); + put("auxlen", AUX_ALLOC); + put("segments", SEGMENTS); + }}); + } final JFrame window; @@ -152,7 +154,7 @@ final public class ArrayVisualizer { final int[] stabilityTable; final int[] indexTable; final ArrayList arrays; - private final int[] statsConfig; + private final Stat[] statsConfig; private SortPair[] AllSorts; // First row of Comparison/DistributionSorts arrays consists of class names private SortPair[] ComparisonSorts; // First row of Comparison/DistributionSorts arrays consists of class names @@ -381,7 +383,7 @@ public void run() { this.fontSelection = "Times New Roman"; this.fontSelectionScale = 25; - List statsInfoList = new ArrayList<>(); + List statsInfoList = new ArrayList<>(); try (Scanner statsScanner = new Scanner(new File("stats-config.txt"))) { while (statsScanner.hasNextLine()) { String line = statsScanner.nextLine().trim(); @@ -396,7 +398,7 @@ public void run() { fontSelection = font.trim(); continue; } - Integer type = STAT_CONFIG_KEYS.get(line.toLowerCase()); + Stat type = Stat.CONFIG_KEYS.get(line.toLowerCase()); if (type == null) { System.err.println("Unknown statistic type: " + type); continue; @@ -414,27 +416,25 @@ public void run() { ); } if (statsInfoList == null) { - statsConfig = new int[] { - STAT_SORT_IDENTITY, - STAT_ARRAY_LENGTH, - STAT_LINE_BREAK, - STAT_SORT_DELAY, - STAT_VISUAL_TIME, - STAT_EST_SORT_TIME, - STAT_LINE_BREAK, - STAT_COMPARISONS, - STAT_SWAPS, - STAT_REVERSALS, - STAT_LINE_BREAK, - STAT_MAIN_WRITE, - STAT_AUX_WRITE, - STAT_AUX_ALLOC, - STAT_SEGMENTS + statsConfig = new Stat[] { + Stat.SORT_IDENTITY, + Stat.ARRAY_LENGTH, + Stat.LINE_BREAK, + Stat.SORT_DELAY, + Stat.VISUAL_TIME, + Stat.EST_SORT_TIME, + Stat.LINE_BREAK, + Stat.COMPARISONS, + Stat.SWAPS, + Stat.REVERSALS, + Stat.LINE_BREAK, + Stat.MAIN_WRITE, + Stat.AUX_WRITE, + Stat.AUX_ALLOC, + Stat.SEGMENTS }; } else { - statsConfig = statsInfoList.stream() - .mapToInt(Integer::intValue) - .toArray(); + statsConfig = statsInfoList.toArray(new Stat[statsInfoList.size()]); } this.sortLength = Math.min(2048, this.MAX_ARRAY_VAL); @@ -645,50 +645,50 @@ private void drawStats(Color textColor, boolean dropShadow) { this.mainRender.setColor(textColor); statLoop: - for (int statType : statsConfig) { + for (Stat statType : statsConfig) { // System.out.println(yPos); String stat; switch (statType) { - case STAT_LINE_BREAK: + case LINE_BREAK: yPos += (int)(fontSelectionScale / 25.0 * 15); continue statLoop; - case STAT_SORT_IDENTITY: + case SORT_IDENTITY: stat = statSnapshot.getSortIdentity(); break; - case STAT_ARRAY_LENGTH: + case ARRAY_LENGTH: stat = statSnapshot.getArrayLength(); break; - case STAT_FRAMERATE: + case FRAMERATE: stat = statSnapshot.getFramerate(); break; - case STAT_SORT_DELAY: + case SORT_DELAY: stat = statSnapshot.getSortDelay(); break; - case STAT_VISUAL_TIME: + case VISUAL_TIME: stat = statSnapshot.getVisualTime(); break; - case STAT_EST_SORT_TIME: + case EST_SORT_TIME: stat = statSnapshot.getEstSortTime(); break; - case STAT_COMPARISONS: + case COMPARISONS: stat = statSnapshot.getComparisonCount(); break; - case STAT_SWAPS: + case SWAPS: stat = statSnapshot.getSwapCount(); break; - case STAT_REVERSALS: + case REVERSALS: stat = statSnapshot.getReversalCount(); break; - case STAT_MAIN_WRITE: + case MAIN_WRITE: stat = statSnapshot.getMainWriteCount(); break; - case STAT_AUX_WRITE: + case AUX_WRITE: stat = statSnapshot.getAuxWriteCount(); break; - case STAT_AUX_ALLOC: + case AUX_ALLOC: stat = statSnapshot.getAuxAllocAmount(); break; - case STAT_SEGMENTS: + case SEGMENTS: stat = statSnapshot.getSegments(); break; default: From 54ec84936e28fd83667f3504dabd8f242e79a03c Mon Sep 17 00:00:00 2001 From: "Josiah (Gaming32) Glosson" Date: Fri, 31 Dec 2021 12:35:28 -0600 Subject: [PATCH 16/16] Rename enum --- src/main/ArrayVisualizer.java | 46 +++++++++++++++++------------------ 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/src/main/ArrayVisualizer.java b/src/main/ArrayVisualizer.java index d81ad153..d77014dd 100644 --- a/src/main/ArrayVisualizer.java +++ b/src/main/ArrayVisualizer.java @@ -110,7 +110,7 @@ of this software and associated documentation files (the "Software"), to deal final public class ArrayVisualizer { private static ArrayVisualizer INSTANCE = null; - private enum Stat { + private enum StatisticType { LINE_BREAK, SORT_IDENTITY, ARRAY_LENGTH, @@ -126,7 +126,7 @@ private enum Stat { AUX_ALLOC, SEGMENTS; - private static final Map CONFIG_KEYS = Collections.unmodifiableMap(new HashMap() {{ + private static final Map CONFIG_KEYS = Collections.unmodifiableMap(new HashMap() {{ put("", LINE_BREAK); put("sort", SORT_IDENTITY); put("length", ARRAY_LENGTH); @@ -154,7 +154,7 @@ private enum Stat { final int[] stabilityTable; final int[] indexTable; final ArrayList arrays; - private final Stat[] statsConfig; + private final StatisticType[] statsConfig; private SortPair[] AllSorts; // First row of Comparison/DistributionSorts arrays consists of class names private SortPair[] ComparisonSorts; // First row of Comparison/DistributionSorts arrays consists of class names @@ -383,7 +383,7 @@ public void run() { this.fontSelection = "Times New Roman"; this.fontSelectionScale = 25; - List statsInfoList = new ArrayList<>(); + List statsInfoList = new ArrayList<>(); try (Scanner statsScanner = new Scanner(new File("stats-config.txt"))) { while (statsScanner.hasNextLine()) { String line = statsScanner.nextLine().trim(); @@ -398,7 +398,7 @@ public void run() { fontSelection = font.trim(); continue; } - Stat type = Stat.CONFIG_KEYS.get(line.toLowerCase()); + StatisticType type = StatisticType.CONFIG_KEYS.get(line.toLowerCase()); if (type == null) { System.err.println("Unknown statistic type: " + type); continue; @@ -416,25 +416,25 @@ public void run() { ); } if (statsInfoList == null) { - statsConfig = new Stat[] { - Stat.SORT_IDENTITY, - Stat.ARRAY_LENGTH, - Stat.LINE_BREAK, - Stat.SORT_DELAY, - Stat.VISUAL_TIME, - Stat.EST_SORT_TIME, - Stat.LINE_BREAK, - Stat.COMPARISONS, - Stat.SWAPS, - Stat.REVERSALS, - Stat.LINE_BREAK, - Stat.MAIN_WRITE, - Stat.AUX_WRITE, - Stat.AUX_ALLOC, - Stat.SEGMENTS + statsConfig = new StatisticType[] { + StatisticType.SORT_IDENTITY, + StatisticType.ARRAY_LENGTH, + StatisticType.LINE_BREAK, + StatisticType.SORT_DELAY, + StatisticType.VISUAL_TIME, + StatisticType.EST_SORT_TIME, + StatisticType.LINE_BREAK, + StatisticType.COMPARISONS, + StatisticType.SWAPS, + StatisticType.REVERSALS, + StatisticType.LINE_BREAK, + StatisticType.MAIN_WRITE, + StatisticType.AUX_WRITE, + StatisticType.AUX_ALLOC, + StatisticType.SEGMENTS }; } else { - statsConfig = statsInfoList.toArray(new Stat[statsInfoList.size()]); + statsConfig = statsInfoList.toArray(new StatisticType[statsInfoList.size()]); } this.sortLength = Math.min(2048, this.MAX_ARRAY_VAL); @@ -645,7 +645,7 @@ private void drawStats(Color textColor, boolean dropShadow) { this.mainRender.setColor(textColor); statLoop: - for (Stat statType : statsConfig) { + for (StatisticType statType : statsConfig) { // System.out.println(yPos); String stat; switch (statType) {