internal FilesSorterRenamerCommand(FilesSorterRenamerCommandRequest request)
 {
     _sourceFolderPath           = request.SourceFolderPath;
     _destinationFolderPath      = request.DestinationFolderPath;
     _sortingStrategy            = request.SortingStrategy;
     OnPercentageProgressChanged = x => { };
 }
Esempio n. 2
0
            public SortedList(List<int> list, SortingStrategy sortingStrategy)
            {
                if (sortingStrategy == null || list == null)
                {
                    throw new ArgumentNullException();
                }

                _list = list;
                _sortingStrategy = sortingStrategy;
            }
        public void SortInputMatrixBySmallestElementAscending()
        {
            int[,] inputMatrix = { { 75, 19, 45 }, { 49, 52, 78 }, { 81, 6, 40 } };
            int[,] actual      = inputMatrix;
            int row        = 3;
            int column     = 3;
            var descending = false;

            int[] indexes = MatrixHelper.MatrixIndexes(inputMatrix, row, column);
            MatrixSortByMinElement sortBySumAsc = new MatrixSortByMinElement(inputMatrix, row, column, indexes);
            var chooseSortingStrategy           = new SortingStrategy(((IMatrixSort)sortBySumAsc).SortMatrix);

            actual          = chooseSortingStrategy.Invoke(descending);
            int[,] expected = { { 6, 40, 81 }, { 19, 45, 75 }, { 49, 52, 78 } };
            CollectionAssert.AreEqual(expected, actual, "{0} != {1}", expected, actual);
        }
Esempio n. 4
0
        public void SetStrategy(SortingStrategy type)
        {
            switch (type)
            {
            case SortingStrategy.BUBBLE:
                _strategy = new BubbleSortStrategy();
                break;

            case SortingStrategy.QUICK:
                _strategy = new QuickSortStrategy();
                break;

            default:
                break;
            }
        }
        public void SortInputMatrixBySmallestElementAscending()
        {
            var sortingStrategy = new SortingStrategy();

            sortingStrategy.MatrixSortStrategy = new MatrixSortByMinElement();
            bool descending = false;

            int[,] inputMatrix = { { 75, 19, 45 }, { 49, 52, 78 }, { 81, 6, 40 } };
            int[,] actual      = inputMatrix;
            int row    = 3;
            int column = 3;

            int[] indexes = MatrixHelper.MatrixIndexes(inputMatrix, row, column);
            actual          = sortingStrategy.ExecuteSort(inputMatrix, row, column, indexes, descending);
            int[,] expected = { { 81, 6, 40 }, { 75, 19, 45 }, { 49, 52, 78 } };
            CollectionAssert.AreEqual(expected, actual, "{0} != {1}", expected, actual);
        }
Esempio n. 6
0
        public void Sort()
        {
            PhotoWrapper temp;

            for (int x = 0; x < m_Photos.Count; x++)
            {
                for (int y = 0; y < m_Photos.Count - 1; y++)

                {
                    if (SortingStrategy.Invoke(m_Photos[y], m_Photos[y + 1]))
                    {
                        temp            = m_Photos[y];
                        m_Photos[y]     = m_Photos[y + 1];
                        m_Photos[y + 1] = temp;
                    }
                }
            }
        }
Esempio n. 7
0
        internal static ISortingStrategy GetStrategy(SortingStrategy sortingStrategy)
        {
            switch (sortingStrategy)
            {
            case SortingStrategy.DateTaken:
                return(new DateTakenSortingStrategy());

            case SortingStrategy.DateCreated:
                return(new DateCreatedSortingStrategy());

            case SortingStrategy.DateModified:
                return(new DateModifiedSortingStrategy());

            case SortingStrategy.DateAccessed:
                return(new DateAccessedSortingStrategy());
            }

            throw new ArgumentOutOfRangeException("sortingStrategy", sortingStrategy, null);
        }
Esempio n. 8
0
        /// <summary>
        /// Factory method of sorting strategies
        /// </summary>
        /// <param name="strategy"> Strategy to sort animal list </param>
        /// <returns> Comparison delegate that is then passes to Sort() as a parameter</returns>
        public static Comparison <Animal> ResolveSortingStrategy(SortingStrategy strategy)
        {
            switch (strategy)
            {
            case SortingStrategy.ByAgeAsc:
                return(CompareByAgeAscending);

            case SortingStrategy.ByAgeDesc:
                return(CompareByAgeDescending);

            case SortingStrategy.ByNameAsc:
                return(CompareByNameAscending);

            case SortingStrategy.ByNameDesc:
                return(CompareByNameDescending);

            default:
                return(CompareByAgeAscending);
            }
        }
Esempio n. 9
0
 public void SetSortingStrategy(SortingStrategy strategy)
 {
     _strategy = strategy;
 }
Esempio n. 10
0
 public SortingList(List <int> list, SortingStrategy strategy)
 {
     _list     = list;
     _strategy = strategy;
 }
Esempio n. 11
0
        static void Main()
        {
            Console.WriteLine("Enter number of elements in row:\n");
            var row = InputHelper.ParseInput();

            Console.WriteLine("Enter number of elements in column:\n");
            var column = InputHelper.ParseInput();

            var matrix  = MatrixHelper.CreateMatrix(row, column);
            var indexes = MatrixHelper.MatrixIndexes(matrix, row, column);
            var result  = matrix;

            Console.WriteLine("Choose sorting type\n1 - sort by row sum (ascending);\n2 - sort by row sum (descending);\n3 - sort by max element in row (ascending);\n4 - sort by max element in row (descending)\n5 - sort by min element in row (ascending)\n6 - sort by min element in row(descending)\n");
            var sortingType = InputHelper.ParseInput();

            MatrixHelper.PrintMatrix(matrix, row, column);

            var             descending            = false;
            SortingStrategy chooseSortingStrategy = null;

            MatrixSortBySum sortBySum = new MatrixSortBySum(result, row, column, indexes);

            if (sortingType == 1)
            {
                chooseSortingStrategy = new SortingStrategy(((IMatrixSort)sortBySum).SortMatrix);
            }

            if (sortingType == 2)
            {
                descending            = true;
                chooseSortingStrategy = new SortingStrategy(((IMatrixSort)sortBySum).SortMatrix);
            }

            MatrixSortByMaxElement sortByMaxElement = new MatrixSortByMaxElement(result, row, column, indexes);

            if (sortingType == 3)
            {
                chooseSortingStrategy = new SortingStrategy(((IMatrixSort)sortByMaxElement).SortMatrix);
            }

            if (sortingType == 4)
            {
                descending            = true;
                chooseSortingStrategy = new SortingStrategy(((IMatrixSort)sortByMaxElement).SortMatrix);
            }

            MatrixSortByMinElement sortByMinElement = new MatrixSortByMinElement(result, row, column, indexes);

            if (sortingType == 5)
            {
                chooseSortingStrategy = new SortingStrategy(((IMatrixSort)sortByMinElement).SortMatrix);
            }

            if (sortingType == 6)
            {
                descending            = true;
                chooseSortingStrategy = new SortingStrategy(((IMatrixSort)sortByMinElement).SortMatrix);
            }

            result = chooseSortingStrategy.Invoke(descending);

            Console.WriteLine("Sorted matrix:");
            for (var i = 0; i < row; i++)
            {
                for (var j = 0; j < column; j++)
                {
                    Console.Write(result[i, j] + " ");
                }
                Console.WriteLine();
            }
        }
Esempio n. 12
0
 public void SetSortStrategy(SortingStrategy strategy)
 {
     this._sortingStrategy = strategy;
 }
Esempio n. 13
0
 public void SetSortingStrategy(SortingStrategy sortingStrategy)
 {
     this.sortingStrategy = sortingStrategy;
 }
Esempio n. 14
0
 private static void Sort(List <int> arr, SortingStrategy strategy)
 {
     strategy.Sort(arr);
 }
 public ComboBoxPairs(string key, SortingStrategy value)
 {
     Key   = key;
     Value = value;
 }