/// <summary>
        /// Filter divers by certificate category.
        /// Divers with highest category will be deleted.
        /// </summary>
        /// <param name="divers">List of divers</param>
        /// <param name="numOfDiversToRemove">Number of divers to delete</param>
        public void FilterDivers(List <Diver> divers, int numOfDiversToRemove)
        {
            // Find max category
            int max = divers.Max(x => x.certificate.AbsoluteLevel);

            // Find divers with max category
            List <Diver> diversToRemove = divers.Where(x => x.certificate.AbsoluteLevel == max).ToList();

            foreach (Diver diverToRemove in diversToRemove)
            {
                if (numOfDiversToRemove-- > 0)
                {
                    divers.Remove(diverToRemove);
                }
                else
                {
                    break;
                }
            }

            // If there are more divers that need to be deleted then go to next filter/chain
            if (numOfDiversToRemove > 0)
            {
                nextFilter.FilterDivers(divers, numOfDiversToRemove);
            }
        }
        /// <summary>
        /// Filter divers by number of dives
        /// Divers with less dives will not be deleted.
        /// </summary>
        /// <param name="divers">List of divers</param>
        /// <param name="numOfDiversToRemove">Number of divers to delete</param>
        public void FilterDivers(List <Diver> divers, int numOfDiversToRemove)
        {
            // Find maximum number of dives per diver
            int max = divers.Max(x => x.NumOfDives);

            // Create list of divers that have max number of dives
            List <Diver> diversToRemove = divers.Where(x => x.NumOfDives == max).ToList();

            foreach (Diver diverToRemove in diversToRemove)
            {
                if (numOfDiversToRemove-- > 0)
                {
                    divers.Remove(diverToRemove);
                }
                else
                {
                    break;
                }
            }

            // If there are more divers that need to be deleted then go to next filter/chain
            if (numOfDiversToRemove > 0)
            {
                nextFilter.FilterDivers(divers, numOfDiversToRemove);
            }
        }
Пример #3
0
        /// <summary>
        /// Remove divers with most recent dive date
        /// and keep those with oldest dive date
        /// </summary>
        /// <param name="divers">List of divers</param>
        /// <param name="numOfDiversToRemove">Number of divers to remove</param>
        public void FilterDivers(List <Diver> divers, int numOfDiversToRemove)
        {
            // Find most recent date
            DateTime mostRecentDiveDate = divers.Max(x => x.DiveList.Max(y => y.dateTime));

            for (int i = divers.Count() - 1; i >= 0; i--)
            {
                // Check if diver have dive with most recent date
                // if he have then delete him
                bool hasDive = divers[i].DiveList.Exists(x => x.dateTime == mostRecentDiveDate);
                if (hasDive && numOfDiversToRemove-- > 0)
                {
                    divers.Remove(divers[i]);
                }
            }

            // If there are more divers that need to be deleted then go to next filter/chain
            if (numOfDiversToRemove > 0)
            {
                nextFilter.FilterDivers(divers, numOfDiversToRemove);
            }
        }
Пример #4
0
 /// <summary>
 /// Pass list of divers through filter chain
 /// </summary>
 /// <param name="diverList">List of divers for filtering</param>
 /// <param name="numOfDiversToRemove">Number of divers to remove</param>
 public void FilterDivers(List <Diver> diverList, int numOfDiversToRemove)
 {
     filterFirst.FilterDivers(diverList, numOfDiversToRemove);
 }