From 2ad30817d7edb1152619d0f837e66ffe7e4bead6 Mon Sep 17 00:00:00 2001 From: "Josiah (Gaming32) Glosson" Date: Tue, 6 Apr 2021 08:33:56 -0500 Subject: [PATCH] Create RunQuickSorts.java --- src/threads/RunQuickSorts.java | 91 ++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 src/threads/RunQuickSorts.java diff --git a/src/threads/RunQuickSorts.java b/src/threads/RunQuickSorts.java new file mode 100644 index 00000000..34d9c658 --- /dev/null +++ b/src/threads/RunQuickSorts.java @@ -0,0 +1,91 @@ +package threads; + +import main.ArrayVisualizer; +import panes.JErrorPane; +import sorts.quick.*; +import sorts.templates.Sort; +import utils.Shuffles; + +/* + * +MIT License + +Copyright (c) 2021 ArrayV 4.0 Team + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + * + */ + +final public class RunQuickSorts extends MultipleSortThread { + private Sort CubeRootQuickSort; + + public RunQuickSorts(ArrayVisualizer arrayVisualizer) { + super(arrayVisualizer); + this.sortCount = 1; + this.categoryCount = this.sortCount; + + CubeRootQuickSort = new CubeRootQuickSort(this.arrayVisualizer); + } + + @Override + protected synchronized void executeSortList(int[] array) throws Exception { + RunQuickSorts.this.runIndividualSort(CubeRootQuickSort, 0, array, 2048, 1, false); + } + + @Override + protected synchronized void runThread(int[] array, int current, int total, boolean runAllActive) throws Exception { + if(arrayVisualizer.isActive()) + return; + + Sounds.toggleSound(true); + arrayVisualizer.setSortingThread(new Thread() { + @Override + public void run() { + try{ + if(runAllActive) { + RunQuickSorts.this.sortNumber = current; + RunQuickSorts.this.sortCount = total; + } + else { + RunQuickSorts.this.sortNumber = 1; + } + + arrayManager.toggleMutableLength(false); + + arrayVisualizer.setCategory("Exchange Sorts"); + + RunQuickSorts.this.executeSortList(array); + + if(!runAllActive) { + arrayVisualizer.setCategory("Run Exchange Sorts"); + arrayVisualizer.setHeading("Done"); + } + + arrayManager.toggleMutableLength(true); + } + catch (Exception e) { + JErrorPane.invokeErrorMessage(e); + } + Sounds.toggleSound(false); + arrayVisualizer.setSortingThread(null); + } + }); + arrayVisualizer.runSortingThread(); + } +}