private static ISortingStrategy GetSortingStrategy(ObjectTypeEnum objectsType) { ISortingStrategy sortingStrategy = null; switch (objectsType) { case ObjectTypeEnum.Resident: sortingStrategy = new QuickSort(); break; case ObjectTypeEnum.TicketNumber: sortingStrategy = new MergeSort(); break; case ObjectTypeEnum.Passenger: sortingStrategy = new HeapSort(); break; default: break; } System.Console.WriteLine($"Type of elements in collection: {objectsType} -> Chosen Strategy: {sortingStrategy}"); return(sortingStrategy); }
static void Main(string[] args) { ISortingStrategy sortingStrategy = null; //Sorting the countyResidents List <string> countyResidents = new List <string> { "ad", "ac", "ax", "zw" }; sortingStrategy = GetSortingOption(ObjectToSort.CountyResidents); sortingStrategy.Sort(countyResidents); //Sorting student numbers List <int> studentNumbers = new List <int> { 123, 678, 543, 189 }; sortingStrategy = GetSortingOption(ObjectToSort.StudentNumber); sortingStrategy.Sort(studentNumbers); //Sorting railway passengers List <string> railwayPassengers = new List <string> { "A21", "Z2", "F3", "G43" }; sortingStrategy = GetSortingOption(ObjectToSort.RailwayPassengers); sortingStrategy.Sort(railwayPassengers); }
public ICollection <int> Sort(ICollection <int> collection, string algorithm) { //ISortingStrategy strategy = null; // Without Reflection // if (algorithm.ToLower() == "selection") // { // strategy = new SelectionSorter(); // } // if (algorithm.ToLower() == "quick") // { // strategy = new QuickSorter(); // } // if (algorithm.ToLower() == "merge") // { // strategy = new MergeSorter(); // } var sorterType = Assembly .GetExecutingAssembly() .GetTypes() .Where(t => typeof(ISortingStrategy).IsAssignableFrom(t) && t.IsClass) .FirstOrDefault(t => t.Name.ToLower().Contains(algorithm)); ISortingStrategy strategy = (ISortingStrategy)Activator.CreateInstance(sorterType); return(strategy.Sort(collection)); }
static void Main(string[] args) { Console.WriteLine("What strategy do you want?"); var strategyName = Console.ReadLine(); var strategy = Assembly.GetExecutingAssembly() .GetTypes() .Where(t => (typeof(ISortingStrategy).IsAssignableFrom(t)) && typeof(ISortingStrategy) != t) .First(t => t.Name.StartsWith(strategyName)); ISortingStrategy soringStrategy = (ISortingStrategy)Activator.CreateInstance(strategy); if (strategyName == "Merge") { soringStrategy = new MergeSorter(); } if (strategyName == "Merge") { soringStrategy = new MergeSorter(); } if (strategyName == "Merge") { soringStrategy = new MergeSorter(); } Sorter sorter = new Sorter(soringStrategy); sorter.Sort(new List <int>()); }
private void Sort(ISortingStrategy algorithm, long[] unsortedArray, out long[] manuallySorted, out long[] dotnetSorted) { manuallySorted = (long[])unsortedArray.Clone(); dotnetSorted = (long[])unsortedArray.Clone(); ArraySorter sorter = new ArraySorter(algorithm); sorter.Sort(manuallySorted); Array.Sort(dotnetSorted); }
public void SortCards(ISortingStrategy sortStrategy) { List <PlayingCard> playingCardList = new List <PlayingCard>(); cardList.ForEach(element => playingCardList.Add(element.GetComponent <PlayingCard>())); List <PlayingCard> sortedList = sortStrategy.Sort(playingCardList); cardList.Clear(); sortedList.ForEach(element => cardList.Add(element.gameObject)); RepositionCards(); }
static void Main(string[] args) { ISortingStrategy sortingStrategy = null; List <int> studentNumbers = new List <int>() { 123, 32, 12, 1 }; sortingStrategy = GetSortingOptions(ObjectsToSort.StudentNumber); sortingStrategy.Sort(studentNumbers); }
public GRMFacade(SortingStrategyType sortingStrategy, TransactionIDsStorageStrategyType transactionIdsStorageStrategy, DecisionSupergeneratorsHandlingStrategyType decisionSupergeneratorsHandlingStrategy) { _dataSetRepresentationBuilder = new DataSetRepresentationBuilder(new TransactionProcessor()); _frequentItemsSelector = new FrequentItemsSelector(); _sortingStrategy = new SortingStrategyFactory().Create(sortingStrategy); var storageStrategy = new TransactionIDsStorageStrategyFactory().Create(transactionIdsStorageStrategy); _treeBuilder = new TreeBuilder(storageStrategy); _decisionGeneratorsCollector = new DecisionGeneratorsCollectorFactory().Create(decisionSupergeneratorsHandlingStrategy); _garmProcedure = new GARMProcedure(_decisionGeneratorsCollector, new GARMPropertyProcedure(storageStrategy)); _grmResultBuilder = new GRMResultBuilder(); }
public IntList(ISortingStrategy sortingStrategy) { this.sortingStrategy = sortingStrategy; Random rng = new Random(); for (int i = 0; i < listLen; ++i) { list[i] = rng.Next(0, 100); } Console.WriteLine("Original List:"); Print(); }
static void Main(string[] args) { string sortType = Console.ReadLine(); Type strategyType = Assembly.GetExecutingAssembly() .GetTypes() .Where(x => typeof(ISortingStrategy).IsAssignableFrom(x) && x.Name.StartsWith(sortType) ).FirstOrDefault(); ISortingStrategy strategy = (ISortingStrategy)Activator.CreateInstance(strategyType); Sorter sorter = new Sorter(strategy); sorter.Sort(new List <int> { 1, 3, 5, 6, 8 }); }
public virtual string GetQueryText ( TableKey sourceTable, IQueryOptions options = null, ISortingStrategy sorting = null ) { if ((Returns == null || Returns.Count == 0)) { throw new InvalidOperationException("No columns has been processed."); } string selectText = string.Join(",", Returns); string joinsText = string.Join(" ", Joins.ToString( )); string whereText = string.Join(" AND ", Conditions); if (string.IsNullOrWhiteSpace(joinsText)) { joinsText = ""; } if (string.IsNullOrWhiteSpace(whereText)) { whereText = ""; } else { whereText = " AND " + whereText; } StringBuilder queryBuilder = new StringBuilder( ); queryBuilder.AppendFormat(SqlQueries.Select_Command_Formatted, selectText, sourceTable, joinsText, whereText); if (null != sorting && !string.IsNullOrWhiteSpace(sorting.SortBy)) { queryBuilder.Append(" ORDER BY " + sorting.SortBy + " " + ((sorting.Direction == SortingDirection.DESC) ? "DESC" : "ASC")); } return(queryBuilder.ToString( )); }
static void Main(string[] args) { // adding a new functionality happens only in one place, thus O/C string sortType = Console.ReadLine(); Type strategy = Assembly.GetExecutingAssembly() .GetTypes() .Where(x => typeof(ISortingStrategy) .IsAssignableFrom(x) && x.Name.StartsWith(sortType)) .FirstOrDefault(); ISortingStrategy iStrategy = Activator .CreateInstance(strategy) as ISortingStrategy; Sorter s = new Sorter(iStrategy); s.Sort(new List <int>() { 5, 7, 99, 0, 62 }); }
static void Main(string[] args) { string strategyType = Console.ReadLine().ToLower(); ISortingStrategy sortingStrategy = null; if (strategyType == "selection") { sortingStrategy = new SelectionSort(); } else if (strategyType == "bubble") { sortingStrategy = new BubbleSort(); } else if (strategyType == "quick") { sortingStrategy = new QuickSort(); } Sorter sorter = new Sorter(sortingStrategy); sorter.Sort(new List <int>()); }
private static ISortingStrategy GetSortingOption(ObjectToSort objectToSort) { ISortingStrategy sortingStrategy = null; switch (objectToSort) { case ObjectToSort.StudentNumber: sortingStrategy = new MergeSort(); break; case ObjectToSort.RailwayPassengers: sortingStrategy = new HeapSort(); break; case ObjectToSort.CountyResidents: sortingStrategy = new QuickSort(); break; default: break; } return(sortingStrategy); }
public IntSorter(ISortingStrategy <int> sortingStrategy) { _sortingStrategy = sortingStrategy; }
public void ChangeSortingStrategy(ISortingStrategy <int> sortingStrategy) { _sortingStrategy = sortingStrategy; }
public IntSorter() { _sortingStrategy = new QuickSortStrategy <int>(); }
public string SortString(ISortingStrategy Strategy, string InputText) { string TmpVar = Strategy.Execute(InputText); return(TmpVar); }
public SortingContext(ISortingStrategy sortingStrategy) { this.sortingStrategy = sortingStrategy; }
public Sorter WithSortingStrategy(ISortingStrategy sortingStrategy) { return(new Sorter(sortingStrategy)); }
public Sorter(ISortingStrategy strategy) { this.strategy = strategy; }
public IEnumerable <T> Sort(IEnumerable <T> source, ISortingStrategy <T> strategy) { return(strategy.Sort(source)); }
public Sorter WithSortingStrategy(ISortingStrategy sortingStrategy) { return new Sorter(sortingStrategy); }
public void SetStrategy(ISortingStrategy strategy) { this.strategy = strategy; }
public Context(ISortingStrategy strategy) { SetStrategy(strategy); }
public XmlExporter(ISortingStrategy sortingStrategy) { _sortingStrategy = sortingStrategy; }
public ExternalSorter(ISortingStrategy <Row> sortingStrategy, ExternalSorterOptions options = null) { _sortingStrategy = sortingStrategy; _chunkSizeBytes = options?.ChunkSizeBytes ?? DefaultChunkSizeBytes; }
public CsvExporter(ISortingStrategy sortingStrategy) { _sortingStrategy = sortingStrategy; }
private static void Process(string sourceFolderPath, string destinationFolderPath, ISortingStrategy sortingStrategy, ProgressTracker progressTracker) { var index = 1; if (!Directory.Exists(destinationFolderPath)) { Directory.CreateDirectory(destinationFolderPath); } Directory .GetFiles(sourceFolderPath, "*.*", SearchOption.TopDirectoryOnly) .Where(x => PhotoExtensions.Any(pe => { return(string.Equals(pe, Path.GetExtension(x).Substring(1), StringComparison.InvariantCultureIgnoreCase)); })) .OrderBy(sortingStrategy.GetDate) .ToList() .ForEach(x => { var destFileName = string.Format("{0}{1}", index.ToString().PadLeft(5, '0'), Path.GetExtension(x)); File.Copy(x, Path.Combine(destinationFolderPath, destFileName)); index++; progressTracker.TrackFileProcessed(); }); var subFolders = Directory.GetDirectories(sourceFolderPath, "*.*", SearchOption.TopDirectoryOnly); Array.ForEach(subFolders, x => Process(x, Path.Combine(destinationFolderPath, Path.GetFileName(x)), sortingStrategy, progressTracker)); }
public SortContextClass(ISortingStrategy strategy) { this.Strategy = strategy; }
public SimpleSorter(ISortingStrategy <Row> sortingStrategy) { _sortingStrategy = sortingStrategy; }
public Sorter(ISortingStrategy sortingStrategy) { _sortingStrategy = sortingStrategy; }