예제 #1
0
        public void AddDefaults()
        {
            //List<ResearchTeam> ResearchTeams = new List<ResearchTeam>();
            Person person  = new Person("Tetiana", "Deretorska", new DateTime(2001, 02, 22));
            Person person1 = new Person("Olha", "Deretorska", new DateTime(2001, 02, 22));
            Paper  paper   = new Paper(person, "Science", new DateTime(2020, 11, 20));

            ResearchTeam researchTeam = new ResearchTeam("Nature2", TimeFrame.TwoYears);

            researchTeam.NameOfOrganisation = "Organization1";
            researchTeam.RegistrationNumber = 23;
            researchTeam.AddPerson(person);
            researchTeam.AddPerson(person1);
            researchTeam.AddPapers(paper);
            researchTeam.AddPapers(paper);
            ResearchTeams.Add(researchTeam);

            // List<ResearchTeam> ResearchTeams = new List<ResearchTeam>();
            Person       personw       = new Person("Olia", "Melnyk", new DateTime(2001, 02, 22));
            Paper        paperw        = new Paper(personw, "Science", new DateTime(2020, 11, 20));
            ResearchTeam researchTeamw = new ResearchTeam("Nature1", TimeFrame.Long);

            researchTeamw.NameOfOrganisation = "Organization2";
            researchTeamw.RegistrationNumber = 21;
            researchTeamw.AddPerson(person);
            researchTeamw.AddPapers(paper);
            ResearchTeams.Add(researchTeamw);
        }
예제 #2
0
        public void ShowTime(int n)
        {
            Team t1 = new Team("Organization " + n, n);

            Stopwatch watch = new Stopwatch();

            watch.Start();
            bool contains = teamList.Contains <Team>(t1);

            watch.Stop();
            long msec = watch.ElapsedTicks;



            Console.WriteLine("List<Team>: " + contains + " " + msec);



            watch.Restart();
            contains = stringList.Contains <string>(t1.ToString());
            watch.Stop();
            msec = watch.ElapsedTicks;

            Console.WriteLine("List<string>: " + contains + " " + msec);


            //---------------------------------------------------------------------
            ResearchTeam researchTeam = new ResearchTeam("invName " + n, TimeFrame.Year);

            researchTeam.NameOfOrganisation = "Organization " + n;
            researchTeam.RegistrationNumber = n;


            watch.Restart();
            contains = teamRTDictionary.ContainsKey(t1);
            watch.Stop();
            msec = watch.ElapsedTicks;

            Console.WriteLine("List<Team, ResearchTeam>: " + contains + " " + msec);



            watch.Restart();
            contains = stringRTDictionary.ContainsKey(t1.ToString());
            watch.Stop();
            msec = watch.ElapsedTicks;

            Console.WriteLine("List<string, ResearchTeam>: " + contains + " " + msec);

            //---------------------------------------------------------------------


            watch.Restart();
            contains = teamRTDictionary.ContainsValue(researchTeam);
            watch.Stop();
            msec = watch.ElapsedTicks;


            Console.WriteLine("List<Team, ResearchTeam> CONTAINSValue res: " + contains + " " + msec);
        }
예제 #3
0
        public override object DeepCopy()
        {
            ResearchTeam temp = new ResearchTeam();

            temp.Name             = Name;
            temp.RegNumber        = RegNumber;
            temp.ResearchTheme    = ResearchTheme;
            temp.ResearchDuration = ResearchDuration;

            ArrayList members = new ArrayList();

            foreach (Person p in ResearchTeamMembers)
            {
                members.Add(p.DeepCopy());
            }
            temp.ResearchTeamMembers = members;

            ArrayList puplications = new ArrayList();

            foreach (Paper paper in ResearchPublications)
            {
                puplications.Add(paper.DeepCopy());
            }
            temp.ResearchPublications = puplications;

            return(temp);
        }
예제 #4
0
        static ResearchTeam CreateResearchTeam(int n)
        {
            ResearchTeam obj = new ResearchTeam("invName " + n, TimeFrame.Year);

            obj.NameOfOrganisation = "Organization " + n;
            obj.RegistrationNumber = n;
            return(obj);
        }
예제 #5
0
        // MARK - Lab 2

        public override bool Equals(object obj)
        {
            ResearchTeam other = obj as ResearchTeam;

            if (other != null)
            {
                return(_researchTitle.Equals(other._researchTitle) && _orgName.Equals(other._orgName) && _regNum.Equals(other._regNum) && _duration.Equals(other._duration));
            }
            return(false);
        }
예제 #6
0
        public static void Main(string[] args)
        {
            Team firstTeam  = new Team();
            Team secondTeam = new Team();

            Console.WriteLine("Equals? - {0}", firstTeam.Equals(secondTeam));
            Console.WriteLine("Ref Equals? - {0}", Object.ReferenceEquals(firstTeam, secondTeam));
            Console.WriteLine("Hash for first - {0}, Hash for second - {1}", firstTeam.GetHashCode(), secondTeam.GetHashCode());

            try
            {
                firstTeam.RegistrationNumber = -1;
            }
            catch (System.ArgumentException ex)
            {
                Console.WriteLine("Exception caugh - {0}.", ex.Message);
            }

            ResearchTeam animals = new ResearchTeam();
            Person       richard = new Person("Richard", "Black", new DateTime(1989, 12, 12));
            Person       den     = new Person("Den", "Simpson", new DateTime(1993, 1, 24));
            Person       nelly   = new Person("Nelly", "Smile", new DateTime(1981, 4, 22));

            Paper cobra   = new Paper();
            Paper sparrow = new Paper("Sparrows", nelly, new DateTime(2015, 4, 21));



            cobra.PublicationName = "Black Mamba";
            cobra.Author          = richard;
            cobra.PublicationDate = new DateTime(2012, 8, 12);

            animals.PublicationList.Add(cobra);
            animals.PublicationList.Add(sparrow);

            animals.ProjectsMember.Add(richard);
            animals.ProjectsMember.Add(den);
            animals.ProjectsMember.Add(nelly);

            Console.WriteLine(animals);
            Console.WriteLine(animals.Team);


            ResearchTeam copy = (ResearchTeam)animals.DeepCopy();

            Console.WriteLine(copy);
            animals.Name = "aimals";
            Console.WriteLine(animals);

            foreach (Paper element in animals.GetPublicationsForTheLastYears(2))
            {
                Console.WriteLine(element);
            }
        }
예제 #7
0
        public override object DeepCopy()
        {
            ResearchTeam other = (ResearchTeam)this.MemberwiseClone();

            other._projectMembers   = new System.Collections.ArrayList(_projectMembers);
            other._publicationList  = new System.Collections.ArrayList(_publicationList);
            other._topicOfResearch  = String.Copy(_topicOfResearch);
            other._durationResearch = _durationResearch;
            other._organizationName = String.Copy(_organizationName);
            return(other);
        }
예제 #8
0
 public TestCollections(int n)
 {
     for (int i = 1; i <= n; i++)
     {
         ResearchTeam obj  = CreateResearchTeam(i);
         Team         tobj = obj.GetTeam;
         teamList.Add(tobj);
         teamRTDictionary.Add(tobj, obj);
         stringList.Add(tobj.ToString());
         stringRTDictionary.Add(stringList[i - 1], obj);
     }
 }
예제 #9
0
        static void Main(string[] args)
        {
            Team t1 = new Team("Team1", 1);
            Team t2 = new Team("Team1", 1);

            Console.WriteLine("t1 equel t2 -> {0}", t1.Equals(t2));
            Console.WriteLine("t1 == t2 -> {0}", t1 == t2);
            t2.NameOfOrganization = "Team2";
            Console.WriteLine("t1 equel t2 -> {0}", t1.Equals(t2));
            Console.WriteLine("t1 == t2 -> {0}", t1 == t2);

            Console.WriteLine("hash code t1: {0}", t1.GetHashCode());
            Console.WriteLine("hash code t2: {0}", t2.GetHashCode());

            try
            {
                t1.RegistrationNumber = -1;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            ResearchTeam rt = new ResearchTeam("reseach", "reseach team1", 123, TimeFrame.Long);

            rt.ListOfPublication = new System.Collections.ArrayList()
            {
                new Paper {
                    Name              = "some paper",
                    Author            = new Person(fName: "Roman", sName: "Chubak", bDay: DateTime.Today),
                    DateOfPublication = DateTime.Today
                }
            };
            rt.ListOfMembers = new System.Collections.ArrayList()
            {
                new Person("roman", "chubak", DateTime.Today),
                new Person("f", "dfa", new DateTime(1999, 5, 4)),
                new Person(fName: "Roman", sName: "Chubak", bDay: DateTime.Today)
            };
            Console.WriteLine(rt);
            Console.WriteLine(rt.Team);

            ResearchTeam newrt = (ResearchTeam)rt.DeepCopy();

            rt.NameOfOrganization = "team";
            Console.WriteLine(rt);
            Console.WriteLine(newrt);



            Console.ReadKey();
        }
예제 #10
0
        static void Main(string[] args)
        {
            Team a = new Team();
            Team b = new Team();

            Console.WriteLine("Если, внезапно, ссылки на объекты равны, то вот тут >>"
                              + ReferenceEquals(a, b) + "<< будет тру:) ");

            Console.WriteLine("Если, внезапно, объекты не равны, то вот тут >>"
                              + a.Equals(b) + "<< будет фолс:) ");

            Console.Write("Тест на присваивание отрицательных значений: ");
            try
            {
                a.RegNumber = int.Parse(Console.ReadLine());
            }
            catch (ArgumentOutOfRangeException AE)
            {
                Console.WriteLine(AE.Message);
            }

            ResearchTeam c      = new ResearchTeam();
            Person       person = new Person("Sting", "Shape", DateTime.Now);

            c.AddMembers(new Person(), person);
            c.AddPapers(new Paper(), new Paper("Kosmos", person, DateTime.Now));

            Console.WriteLine(c.ToString() + "\n\n\n");


            ResearchTeam cpTeam = (ResearchTeam)c.DeepCopy();

            c.RegNumber = 23423;
            c.AddMembers(new Person("qqq", "Shape", DateTime.Now));

            Console.WriteLine("Base RT: " + c.ToString() + "\n\n\n");
            Console.WriteLine("Copy RT: " + cpTeam.ToString() + "\n\n\n");

            c.AddPapers(new Paper("rrrrrr", person, DateTime.Now));

            foreach (Paper t in c.GetPapers(2))
            {
                Console.WriteLine(t.ToString() + "\n");
            }



            Console.ReadKey();
        }
예제 #11
0
        //public object DeepCopy()
        //{
        //	using (var ms = new MemoryStream())
        //	{
        //		var formatter = new BinaryFormatter();
        //		formatter.Serialize(ms, this);
        //		ms.Position = 0;

        //		return (Person)formatter.Deserialize(ms);
        //	}
        //}


        override public object DeepCopy()
        {
            ResearchTeam other = new ResearchTeam();

            other.ResearchTitle = String.Copy(ResearchTitle);
            other.Name          = String.Copy(Name);
            other.RegNum        = RegNum;
            other.Duration      = Duration;
            other._publications = new System.Collections.ArrayList(Publications.Count);
            for (int i = 0; i < Publications.Count; ++i)
            {
                other._publications.Add(new Paper((Lab2.Paper)_publications[i]));
            }
            return(other);
        }
예제 #12
0
        public object DeepCopy()
        {
            ResearchTeam res_object = new ResearchTeam(ResearchName, CompanyName, LicenceNumber, Name, ResearchDuration);

            res_object.Name = Name;

            ArrayList articles_copy = new ArrayList();

            foreach (var article_obj in articlesArr)
            {
                articles_copy.Add(((Paper)article_obj).DeepCopy());
            }
            res_object.ArticleArr = articles_copy;

            ArrayList members_copy = new ArrayList();

            foreach (var member_obj in teamMembers)
            {
                members_copy.Add(((Person)member_obj).DeepCopy());
            }
            res_object.teamMembers = articles_copy;

            return(res_object);
        }
예제 #13
0
        static void Main(string[] args)
        {
            Team team1 = new Team("Горішок", 099);
            Team team2 = new Team("Горішок", 099);

            if (team1 == team2)
            {
                Console.WriteLine("однаковi");
            }
            Console.WriteLine("Хеш код для першого об'кта:" + team1.GetHashCode() + "\nХеш код для другого об'кта:" + team2.GetHashCode() + "\n");

            try
            {
                team1.RegistrationNumber = -1;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            List <Person> people = new List <Person>();

            people.Add(new Person());
            List <Paper> papers = new List <Paper>();

            papers.Add(new Paper());
            ResearchTeam researchTeam = new ResearchTeam();

            researchTeam.People = people;
            researchTeam.Papers = papers;
            // Console.WriteLine(researchTeam);

            Team team = new Team();

            team = researchTeam.GetTeam;
            //Console.WriteLine(team);

            ResearchTeam researchTeam1 = new ResearchTeam();

            researchTeam1 = (ResearchTeam)researchTeam.DeepCopy();
            //researchTeam.DeepCopy();
            researchTeam.ThemeResearch = "Some Organization";
            //Console.WriteLine(researchTeam);
            //Console.WriteLine(researchTeam1);

            researchTeam1.AddPerson(new Person("Olha", "Melnyk", new DateTime(2019, 03, 23)));
            researchTeam1.AddPerson(new Person("Tetiana", "Deretorska", new DateTime(1999, 05, 26)));


            //researchTeam1.AddPapers(new Paper("Name Ukr", new Person("Olha","Polop",new DateTime(1998, 03, 23)),new DateTime(2018, 03, 23)));
            Console.WriteLine(researchTeam1);
            //Console.WriteLine(researchTeam1);
            foreach (Person person in researchTeam1)
            {
                Console.WriteLine(person);
            }

            /*foreach(Paper paper in researchTeam1.GetEnumeratorPaper(4))
             * {
             *  Console.WriteLine(paper);
             * }
             */



            /*string userInput;
             * int n, m;
             * Console.WriteLine("Input n&m:");
             * userInput = Console.ReadLine();
             * n = Convert.ToInt32(userInput);
             * userInput = Console.ReadLine();
             * m = Convert.ToInt32(userInput);
             *
             *
             *
             * Person person = new Person("Olha", "Melnyk", new DateTime(1999, 06, 01));
             * Person personTwo = new Person("Tania", "Deretorska", new DateTime(1999, 05, 26));
             * person.PersonBirthdayYear = 1995;
             *
             * List<Paper> paper = new List<Paper>();
             * paper.Add(new Paper() {_publicationName = "Name Publication", _author = person, _publicationDate = new DateTime(2017, 12, 23)});
             * paper.Add(new Paper() {_publicationName = "Name Publication1", _author = personTwo, _publicationDate = new DateTime(2019, 12, 23)});
             *
             *
             * Paper[] papers = { new Paper() { _publicationName = "Name Publication", _author = person, _publicationDate = new DateTime(2017, 02, 23) },
             *                 new Paper() { _publicationName = "Name Publication1", _author = person, _publicationDate = new DateTime(2017, 12, 23) }
             *               };
             *
             * ResearchTeam researchTeam = new ResearchTeam("thema", "organization", TimeFrame.Long, 9);
             *
             * Console.WriteLine(researchTeam.ToShortString());
             *
             * Console.WriteLine("Long = " + researchTeam[TimeFrame.Long] + "\n" + "TwoYears = " + researchTeam[TimeFrame.TwoYears] + "\n" + "Year = " + researchTeam[TimeFrame.Year] + "\n");
             * researchTeam.ListOfPublications = papers;
             *
             * Console.WriteLine(researchTeam.ToString());
             *
             *
             * Paper[] listOfPublications1 = { new Paper() { _publicationName = "Name Publication2", _author = person, _publicationDate = new DateTime(2018, 12, 23) },
             *                              new Paper() { _publicationName = "Name Publication3", _author = person, _publicationDate = new DateTime(2019, 12, 23) }
             *                            };
             *
             * researchTeam.AddPapers(listOfPublications1);
             *
             * Console.WriteLine(researchTeam.ToString());
             * Console.WriteLine("Last Publication: " + researchTeam.LinkToPublication);
             *
             *
             * Paper[] papers1 = new Paper[n * m];
             * Paper[,] papers2 = new Paper[n, m];
             * Paper[][] papers3 = new Paper[n][];
             * Paper paperToCompare = new Paper() { _publicationName = "Name Publication1", _author = person, _publicationDate = new DateTime(2017, 12, 23) };
             *
             * int Start = Environment.TickCount;
             * for (int i = 0; i < n * m; i++)
             * {
             *  papers1[i] = paperToCompare;
             * }
             * Console.WriteLine("Duration of operation: " + (Environment.TickCount - Start));
             *
             *
             * //Start = Environment.TickCount;
             * for (int i = 0; i < n; i++)
             *  for (int j = 0; j < m; j++)
             *  {
             *      papers2[i, j] = paperToCompare;
             *  }
             * Console.WriteLine("Duration of operation: " + (Environment.TickCount - Start));
             *
             * int k = m;
             * for (int j = 0; j < n; j++)
             * {
             *  papers3[j] = new Paper[k--];
             * }
             *
             * //Start = Environment.TickCount;
             * for (int i = 0; i < n; i++)
             * {
             *  for (int j = 0; j < m - i; j++)
             *  {
             *      papers3[i][j] = paperToCompare;
             *  }
             * }
             * Console.WriteLine("Duration of operation: " + (Environment.TickCount - Start));*/
            Console.ReadLine();
        }
예제 #14
0
        public static void Main(string[] args)
        {
            Team firstTeam  = new Team();
            Team secondTeam = new Team();

            Console.WriteLine("TEST 1 \nEquals? - {0}", firstTeam.Equals(secondTeam));
            Console.WriteLine("Reference Equals? - {0}", Object.ReferenceEquals(firstTeam, secondTeam));
            int h1 = firstTeam.GetHashCode();
            int h2 = secondTeam.GetHashCode();

            Console.WriteLine("Hash1 = {0}, Hash2 = {1}, Hash1==Hash2? {2}", h1, h2, h1 == h2);

            try
            {
                firstTeam.RegNum = -1;
            }
            catch (System.ArgumentException ex)
            {
                Console.WriteLine("\nTEST 2 \nException caught - {0}.", ex.Message);
            }

            ResearchTeam team    = new ResearchTeam();
            Person       person1 = new Person("person", "one", new DateTime(1989, 12, 12));
            Person       person2 = new Person("person", "two", new DateTime(1993, 1, 24));
            Person       person3 = new Person("person", "three", new DateTime(1981, 4, 22));

            Paper paper1 = new Paper();
            Paper paper2 = new Paper("paper 2", person3, new DateTime(2016, 4, 21));



            paper1.name             = "paper1";
            paper1.author           = person1;
            paper1.dateOfPublishing = new DateTime(2012, 8, 12);

            team.Publications.Add(paper1);
            team.Publications.Add(paper2);

            team.Members.Add(person1);
            team.Members.Add(person2);
            team.Members.Add(person3);

            Console.WriteLine("\nTEST 3 \n");
            Console.WriteLine(team);
            Console.WriteLine(team.Team);


            ResearchTeam copy = (ResearchTeam)team.DeepCopy();

            team.Name = "Changed team name";
            Console.WriteLine("Modified original: " + team + "\nCopy" + copy);

            Console.WriteLine("\nTEST 4 \n");

            foreach (Person person in team.PersonsWithoutPublications())
            {
                Console.WriteLine(person);
            }

            Console.WriteLine("\nTEST 5 \n");

            foreach (Paper element in team.PublicationsUpTo(2))
            {
                Console.WriteLine(element);
            }
        }
예제 #15
0
        static void Main(string[] args)
        {
            //1
            Team team_1 = new Team("ABC", 123);
            Team team_2 = new Team("ABC", 123);

            if (team_1 == team_2)
            {
                Console.WriteLine("Объекты равны по значению");
            }

            if (!ReferenceEquals(team_1, team_2))
            {
                Console.WriteLine("Ссылки на объекты не равны");
            }
            //2
            try
            {
                team_1.LicenceNumber = -1;
            }
            catch (ArgumentException ex)
            {
                Console.WriteLine(ex.Message);
            }
            //3
            ResearchTeam researchTeam = new ResearchTeam();

            researchTeam.AddPapers(new Paper("Статья №1", new Person(), new DateTime(2000, 1, 1)), new Paper());
            researchTeam.AddMembers(new Person(), new Person("Иван", "Иванов", new DateTime(1997, 5, 12)));
            Console.WriteLine(researchTeam);
            //4
            Console.WriteLine(researchTeam.Team + "\n");
            //5
            ResearchTeam rTeamCopy = (ResearchTeam)researchTeam.DeepCopy();

            researchTeam.Name = "New Name";
            Console.WriteLine("Данные исходного объекта(изменённые): ");
            Console.WriteLine(researchTeam);
            Console.WriteLine("Данные копии: ");
            Console.WriteLine(rTeamCopy);
            //6
            Console.WriteLine("Участники без публикаций: ");
            foreach (var member in researchTeam.GetMembersWithZeroArticles())
            {
                Console.WriteLine(member);
            }
            //7
            researchTeam.AddPapers(new Paper("Новая статья №1", new Person(), DateTime.Now));
            researchTeam.AddPapers(new Paper("Новая статья №2", new Person(), new DateTime(2020, 10, 11)));
            researchTeam.AddPapers(new Paper("Старая статья №2", new Person(), new DateTime(2010, 10, 11)));

            Console.WriteLine("\nПубликации за последние 2 года");
            foreach (var article in researchTeam.GetLatestPapers(2))
            {
                Console.WriteLine(article);
            }
            //8
            Console.WriteLine("\nУчастники проекта, у которых есть публикации:");
            foreach (var member in researchTeam)
            {
                Console.WriteLine(member);
            }
            //9
            Console.WriteLine("\nУчастники, у которых больше одной публикации:");
            foreach (var member in researchTeam.GetMembersWithMoreThanOneArticle())
            {
                Console.WriteLine(member);
            }
            //10
            Console.WriteLine("\nПубликации за последний год: ");
            foreach (var article in researchTeam.GetLastYearPapers())
            {
                Console.WriteLine(article);
            }
        }