public bool ContainsNumber(int number)
        {
            ICSECourse temp = new CSECourse(number, "", "");

            /*
             * Even though the possible course in the list will most likely
             * have different data than temp, the implementaion of Contains
             * uses the provided IComparer. Since it returns 'equal' if the
             * numbers are equal, even if other properties are not equal, this
             * method call works.
             */
            return(CourseList.Contains(temp));
        }
        public ICSECourse GetCourseByNumber(int number)
        {
            if (!ContainsNumber(number))
            {
                throw new ArgumentException("Violation of: A course with the same number is in this");
            }

            // This is super inefficient but it's the best way I can think of
            var        courses = new List <ICSECourse>(CourseList);
            ICSECourse temp    = new CSECourse(number, "", "");

            // Again this works due to the IComparer design
            int idxToSearchFor = courses.BinarySearch(temp, new CompareCSECourseByNumber());

            return(courses[idxToSearchFor]);
        }
        private static void TestCSECourse()
        {
            int    number   = 4253;
            string name     = "Programming in C#";
            string syllabus = "http://coe-portal.cse.ohio-state.edu/pdf-exports/CSE/CSE-4253.pdf";

            int[] prereqs    = { 2122, 2123, 2231, 2321 };
            int[] successors = { 5194 };

            ICSECourse c = new CSECourse(number, name, syllabus);

            foreach (int p in prereqs)
            {
                c.AddPrereq(p);
            }
            foreach (int s in successors)
            {
                c.AddSuccessor(s);
            }

            Console.WriteLine(c);

            Console.WriteLine("\nPrereqs:");
            foreach (int p in c.Prereqs)
            {
                Console.WriteLine(p);
            }

            Console.WriteLine("\nSuccessors:");
            foreach (int s in c.Successors)
            {
                Console.WriteLine(s);
            }


            var set = new SortedSet <ICSECourse>(new CompareCSECourseByNumber());

            set.Add(c);

            ICSECourse tempC = new CSECourse(4253, "", "");

            Console.WriteLine("\nset.Contains({0}) = {1}", tempC, set.Contains(tempC));
        }
Esempio n. 4
0
        public override bool Equals(object other)
        {
            if (other == null)
            {
                return(false);
            }
            if (other == this)
            {
                return(true);
            }
            if (!(other is CSECourse))
            {
                return(false);
            }

            CSECourse otherCourse = other as CSECourse;

            return(Number == otherCourse.Number &&
                   Name == otherCourse.Name &&
                   Syllabus == otherCourse.Syllabus &&
                   Prereqs.Equals(otherCourse.Prereqs) &&
                   Successors.Equals(otherCourse.Successors));
        }