Exemple #1
0
        /// <summary>
        /// Search in a list of <see cref="Munro"/> the items loosely matching the given parameters, ignoring invalid values (if maxHeight smaller then minHeight they will be inverted so to keep the correct range)
        /// </summary>
        /// <param name="munros">List of the munros</param>
        /// <param name="hillCategory">Type of hill to search for</param>
        /// <param name="minHeight">Minimum height the munro needs to have</param>
        /// <param name="maxHeight">Maximum height the munro can have</param>
        /// <param name="numberResults">Number of results to be returned</param>
        /// <param name="limitPosition">Where the limiting begins</param>
        /// <param name="sortCriterias">Criterias for sorting the list</param>
        /// <returns>List of <see cref="Munro"/> matching the given parameters</returns>
        public static List <Munro> SearchLoosely(List <Munro> munros, Munro.CategoryType hillCategory = Munro.CategoryType.NONE, double minHeight = 0, double maxHeight = 0, int numberResults = 0, LimitResultsFilter.LimitType limitPosition = LimitResultsFilter.LimitType.TOP, params SortCriteria[] sortCriterias)
        {
            if (minHeight < 0)
            {
                minHeight = 0;
            }
            if (maxHeight < 0)
            {
                maxHeight = 0;
            }
            if (maxHeight > 0)
            {
                if (maxHeight - minHeight < 0)
                {
                    var temp = maxHeight;
                    maxHeight = minHeight;
                    minHeight = temp;
                }
            }

            if (numberResults < 0)
            {
                numberResults = 0;
            }

            return(Search(munros, hillCategory, minHeight, maxHeight, numberResults, limitPosition, sortCriterias));
        }
Exemple #2
0
        /// <summary>
        /// Search in a list of <see cref="Munro"/> the items matching the given parameters
        /// </summary>
        /// <param name="munros">List of the munros</param>
        /// <param name="hillCategory">Type of hill to search for</param>
        /// <param name="minHeight">Minimum height the munro needs to have</param>
        /// <param name="maxHeight">Maximum height the munro can have</param>
        /// <param name="numberResults">Number of results to be returned</param>
        /// <param name="limitPosition">Where the limiting begins</param>
        /// <param name="sortCriterias">Criterias for sorting the list</param>
        /// <returns>List of <see cref="Munro"/> matching the given parameters</returns>
        public static List <Munro> Search(List <Munro> munros, Munro.CategoryType hillCategory = Munro.CategoryType.NONE, double minHeight = 0, double maxHeight = 0, int numberResults = 0, LimitResultsFilter.LimitType limitPosition = LimitResultsFilter.LimitType.TOP, params SortCriteria[] sortCriterias)
        {
            List <Munro> results = munros;

            switch (CheckHeightValues(minHeight, maxHeight))
            {
            case HeightFilterType.ERROR:
            {
                throw new ArgumentException("Minimum height can't be greater then maximum height and they both need to be positive numbers");
            }

            case HeightFilterType.MIN:
            {
                var minHeightFilter = new MinHeightFilter(results, minHeight);
                results = minHeightFilter.GetResults();
                break;
            }

            case HeightFilterType.MAX:
            {
                var maxHeightFilter = new MinHeightFilter(results, maxHeight);
                results = maxHeightFilter.GetResults();
                break;
            }

            case HeightFilterType.BOTH:
            {
                var minHeightFilter = new MinHeightFilter(munros, minHeight);
                results = minHeightFilter.GetResults();
                var maxHeightFilter = new MaxHeightFilter(results, maxHeight);
                results = maxHeightFilter.GetResults();
                break;
            }
            }

            var categoryFilter = new HillCategoryFilter(results, hillCategory);

            results = categoryFilter.GetResults();

            var sortFilter = new SortFilter(results, sortCriterias);

            results = sortFilter.GetResults();

            var limitFilter = new LimitResultsFilter(results, numberResults, limitPosition);

            results = limitFilter.GetResults();

            return(results);
        }
Exemple #3
0
 /// <summary>
 /// Instantiate the filter with another filter for <see cref="BaseMunroFilter.Munros"/> and the given value for <see cref="HillCategory"/>
 /// </summary>
 public HillCategoryFilter(IMunroFilter filterMunrosSource, Munro.CategoryType category = Munro.CategoryType.NONE) : base(filterMunrosSource)
 {
     HillCategory = category;
 }
Exemple #4
0
 /// <summary>
 /// Instantiate the filter with the given list of <see cref="Munro"/> for <see cref="BaseMunroFilter.Munros"/> and the given value for <see cref="HillCategory"/>
 /// </summary>
 public HillCategoryFilter(List <Munro> munros, Munro.CategoryType category = Munro.CategoryType.NONE) : base(munros)
 {
     HillCategory = category;
 }
Exemple #5
0
 /// <summary>
 /// Instantiate the filter with default value for <see cref="HillCategory"/>
 /// </summary>
 public HillCategoryFilter() : base()
 {
     HillCategory = Munro.CategoryType.NONE;
 }
Exemple #6
0
        //public MunroSearcher()
        //{

        //}

        #endregion

        /// <summary>
        /// Search in a CSV file containing a list of <see cref="Munro"/> the items matching the given parameters
        /// </summary>
        /// <param name="csvFilePath">String containing the file path of the CSV file</param>
        /// <param name="map">List of pairs of column name-property name to use when reading the CSV file</param>
        /// <param name="hillCategory">Type of hill to search for</param>
        /// <param name="minHeight">Minimum height the munro needs to have</param>
        /// <param name="maxHeight">Maximum height the munro can have</param>
        /// <param name="numberResults">Number of results to be returned</param>
        /// <param name="limitPosition">Where the limiting begins</param>
        /// <param name="sortCriterias">Criterias for sorting the list</param>
        /// <returns>List of <see cref="Munro"/> matching the given parameters</returns>
        public static List <Munro> Search(string csvFilePath, IEnumerable <ColumnToPropertyPair> map = null, Munro.CategoryType hillCategory = Munro.CategoryType.NONE, double minHeight = 0, double maxHeight = 0, int numberResults = 0, LimitResultsFilter.LimitType limitPosition = LimitResultsFilter.LimitType.TOP, params SortCriteria[] sortCriterias)
        {
            var csvReader = new CSVReader(map);
            var results   = csvReader.ReadCSV(csvFilePath);

            return(Search(results, hillCategory, minHeight, maxHeight, numberResults, limitPosition, sortCriterias));
        }
Exemple #7
0
        /// <summary>
        /// Search in a CSV file containing a list of <see cref="Munro"/> the items loosely matching the given parameters, ignoring invalid values (if maxHeight smaller then minHeight they will be inverted so to keep the correct range)
        /// </summary>
        /// <param name="csvFilePath">String containing the file path of the CSV file</param>
        /// <param name="map">List of pairs of column name-property name to use when reading the CSV file</param>
        /// <param name="hillCategory">Type of hill to search for</param>
        /// <param name="minHeight">Minimum height the munro needs to have</param>
        /// <param name="maxHeight">Maximum height the munro can have</param>
        /// <param name="numberResults">Number of results to be returned</param>
        /// <param name="limitPosition">Where the limiting begins</param>
        /// <param name="sortCriterias">Criterias for sorting the list</param>
        /// <returns>List of <see cref="Munro"/> matching the given parameters</returns>
        public static List <Munro> SearchLoosely(string csvFilePath, IEnumerable <ColumnToPropertyPair> map = null, Munro.CategoryType hillCategory = Munro.CategoryType.NONE, double minHeight = 0, double maxHeight = 0, int numberResults = 0, LimitResultsFilter.LimitType limitPosition = LimitResultsFilter.LimitType.TOP, params SortCriteria[] sortCriterias)
        {
            if (minHeight < 0)
            {
                minHeight = 0;
            }
            if (maxHeight < 0)
            {
                maxHeight = 0;
            }
            if (maxHeight > 0)
            {
                if (maxHeight - minHeight < 0)
                {
                    var temp = maxHeight;
                    maxHeight = minHeight;
                    minHeight = temp;
                }
            }

            if (numberResults < 0)
            {
                numberResults = 0;
            }

            return(Search(csvFilePath, map, hillCategory, minHeight, maxHeight, numberResults, limitPosition, sortCriterias));
        }