Beispiel #1
0
        /// <summary>
        /// Takes a <c>CourseJSON</c> instance and serializes it.
        /// Necessary instances of <c>LectureType</c>, <c>CourseMain</c> and <c>CourseEvent</c> are created.
        /// Duplicates of exsisting instances are ignored.
        /// All new instances are added to their respective list holding all instances.
        /// </summary>
        /// <param name="c">An instance of <c>CourseJSON</c> to deserialize.</param>
        public static void SerializeCourseData(CourseJSON c)
        {
            //Serialize LectureType
            LectureType lt = new LectureType(Library.SplitRawCourse(c.GetSubject())[1]);

            //Check for duplicate, add if new
            if (!ALL_LECTURE_TYPE.Contains(lt))
            {
                ALL_LECTURE_TYPE.Add(lt);
            }
            //Retrieve fitting LectureType instance
            lt = ALL_LECTURE_TYPE[ALL_LECTURE_TYPE.IndexOf(lt)];

            //Serialize CourseMain
            CourseMain cm = new CourseMain(Library.SplitRawCourse(c.GetSubject())[0]);

            //Check for duplicate, add if new
            if (!ALL_COURSE_MAIN.Contains(cm))
            {
                ALL_COURSE_MAIN.Add(cm);
                COURSE_MAIN_SUBJ.Add(cm.Subject, cm);
            }
            //Retrieve fitting CourseMain instance
            cm = ALL_COURSE_MAIN[ALL_COURSE_MAIN.IndexOf(cm)];

            //Serialize CourseEvent
            CourseEvent ce = new CourseEvent(c.GetDate(), c.GetStart(), c.GetEnd(), c.GetRoom(), c.GetBuilding(), c.GetTeacher(), cm, lt);

            //Check for duplicate, add if new
            if (!ALL_COURSE_EVENT.Contains(ce))
            {
                ALL_COURSE_EVENT.Add(ce);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Compares the instance of the class to a given object.
        /// </summary>
        /// <param name="obj">Object to compare to.</param>
        /// <returns>If the given object is greater, equal or lesser.</returns>
        public int CompareTo(object obj)
        {
            if (obj.GetType() == this.GetType())
            {
                CourseEvent ce = (CourseEvent)obj;

                if (ce.Date < this.Date)
                {
                    return(1);
                }
                else if (ce.Date > this.Date)
                {
                    return(-1);
                }
                else
                {
                    if (ce.Start < this.Start)
                    {
                        return(1);
                    }
                    else if (ce.Start > this.Start)
                    {
                        return(-1);
                    }
                    else
                    {
                        if (ce.End < this.End)
                        {
                            return(1);
                        }
                        else if (ce.End > this.End)
                        {
                            return(-1);
                        }
                        else
                        {
                            return(0);
                        }
                    }
                }
            }
            return(0);
        }