Package pl.put.poznan.transformer.logic
Class Sorter
- java.lang.Object
-
- pl.put.poznan.transformer.logic.Sorter
-
public class Sorter extends Object
Sorting handler used by higher-level logic.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static booleancountingSort(int[] tab, SortAlgorithm.Order order)A simple implementation of the counting sort algorithm This implementation only works for 1-D arrays of integers.voidsetStrategy(SortAlgorithm algorithm)Method for switching sorting algorithms.booleansort(Cell[][] tab, int column, int maxIter, SortAlgorithm.Order order)Wrapper to callSortAlgorithm.sort(Cell[][], int, int, Order)of the currently chosenSortAlgorithm.
-
-
-
Constructor Detail
-
Sorter
public Sorter()
A light constructor which initializesalgoto aQuickSortobject.
-
-
Method Detail
-
setStrategy
public void setStrategy(SortAlgorithm algorithm)
Method for switching sorting algorithms.- Parameters:
algorithm- aSortAlgorithmobject to assign toalgoand be used from now on.
-
sort
public boolean sort(Cell[][] tab, int column, int maxIter, SortAlgorithm.Order order)
Wrapper to callSortAlgorithm.sort(Cell[][], int, int, Order)of the currently chosenSortAlgorithm. Allows using a singleSorterobject to perform sorting with differnt algorithms- Parameters:
tab- a 2-D array of typeCellto be sorted.column- the index of the column which will be the sorting criteria.maxIter- maximum number of iterations. Value of-1means unlimited iterations,<-1means none.order- an enum Order value determining the sorting direction.- Returns:
- a boolean value of whether sorting could be completed in the given number of iterations.
-
countingSort
public static boolean countingSort(int[] tab, SortAlgorithm.Order order)A simple implementation of the counting sort algorithm This implementation only works for 1-D arrays of integers.- Parameters:
tab- a 2-D array of typeCellto be sorted.order- an enum Order value determining the sorting direction.- Returns:
- a boolean value of whether sorting could be completed in the given number of iterations.
- Throws:
IllegalArgumentException- if given array contains negative values.
-
-