Esempio n. 1
0
        public override object Clone()
        {
            Place      clone  = new Place(this.Latitude, this.Longitude);
            Area       clone1 = new Area(clone, this.NameOfArea, this.NameOfContinetn, this.CountOfCity, this.SquearOfArea);
            City       clone2 = new City(clone1, this.NameOfCity, this.CountOfPeople, this.SquearOfCity);
            Megapolice clone3 = new Megapolice(clone2, this.CountOfAglommeration);

            return(new Address(clone3, this.streatName, this.numberOfStreat));
        }
Esempio n. 2
0
        public override bool Equals(object obj)
        {
            if (obj == null || GetType() != obj.GetType())
            {
                return(false);
            }
            Megapolice p = (Megapolice)obj;

            return((latitude == p.Latitude) && (longitude == p.Longitude));
        }
Esempio n. 3
0
 public Address(Megapolice megapolice, string name, int num)
 {
     Latitude             = megapolice.Latitude;
     Longitude            = megapolice.Longitude;
     NameOfContinetn      = megapolice.NameOfContinetn;
     NameOfArea           = megapolice.NameOfArea;
     CountOfCity          = megapolice.CountOfCity;
     SquearOfArea         = megapolice.SquearOfArea;
     CountOfPeople        = megapolice.CountOfPeople;
     NameOfCity           = megapolice.NameOfCity;
     SquearOfCity         = megapolice.SquearOfCity;
     CountOfAglommeration = megapolice.CountOfAglommeration;
     if (megapolice.CountOfAglommeration == -1)
     {
         CountOfAglommeration = 1;
     }
     placeSaver     = (Place)megapolice.placeSaver.Clone();
     streatName     = name;
     numberOfStreat = num;
 }
Esempio n. 4
0
        public static void Main(string[] args)
        {
            Place      place      = new Place(90, 65);
            Area       area       = new Area(place, "Пермский край", "Европа", 25, 160600);
            City       city       = new City(area, "Пермь", 1053938, 803);
            Place      place2     = new Place(12, 14);
            City       city1      = new City(area, "Кунгур", 66074, 68.7f);
            City       city3      = new City(area, "Соликамск", 95500, 166.6f);
            City       city4      = new City(area, "Березники", 141276, 66);
            Area       area2      = new Area(place2, "Свердловская область", "Европа", 47, 194800);
            City       city2      = new City(area2, "Екатеринбург", 1453938, 468);
            Area       area3      = new Area(place, "Гуандун", "Азия", 30, 177900);
            City       city5      = new City(area3, "Цинъюань", 3660000, 19152);
            Megapolice megapolice = new Megapolice(city2, 1);
            Address    address    = new Address(city, "Пушкина", 14);
            Address    address2   = new Address(megapolice, "Пушкина", 16);

            IExecutable[] mass1 = new IExecutable[] { place, city2, city, area3, city1, place2, city3, city4, city5 };

            foreach (IExecutable obj in mass1)
            {
                if (obj is Address)
                {
                    Address tmp = (Address)obj;
                    tmp.Show();
                }
                else if (obj is Megapolice)
                {
                    Megapolice tmp = (Megapolice)obj;
                    tmp.Show();
                }
                else if (obj is City)
                {
                    City tmp = (City)obj;
                    tmp.Show();
                }

                else if (obj is Area)
                {
                    Area tmp = (Area)obj;
                    tmp.Show();
                }
                else if (obj is Place)
                {
                    obj.Show();
                }
                Console.WriteLine("__________________________________________");
            }
            Console.WriteLine("############################");
            Array.Sort(mass1);
            foreach (IExecutable obj in mass1)
            {
                if (obj is Address)
                {
                    Address tmp = (Address)obj;
                    tmp.Show();
                }
                else if (obj is Megapolice)
                {
                    Megapolice tmp = (Megapolice)obj;
                    tmp.Show();
                }
                else if (obj is City)
                {
                    City tmp = (City)obj;
                    tmp.Show();
                }

                else if (obj is Area)
                {
                    Area tmp = (Area)obj;
                    tmp.Show();
                }
                else if (obj is Place)
                {
                    obj.Show();
                }
                Console.WriteLine("__________________________________________");
            }
            do
            {
                Console.WriteLine("__________________________________________");
                Console.WriteLine(@"Введите параметр поиска
Введите 0 для выхода");
                string enter = Console.ReadLine();
                if (enter == "0")
                {
                    break;
                }
                Console.WriteLine("__________________________________________");

                foreach (IExecutable obj in mass1)
                {
                    if (obj is Address)
                    {
                        Address tmp = (Address)obj;
                        if (tmp.StreatName == enter)
                        {
                            tmp.Show();
                            break;
                        }
                    }
                    else if (obj is Megapolice)
                    {
                        Megapolice tmp = (Megapolice)obj;
                        if (tmp.NameOfCity == enter)
                        {
                            tmp.Show();
                            break;
                        }
                    }
                    else if (obj is City)
                    {
                        City tmp = (City)obj;
                        if (tmp.NameOfCity == enter)
                        {
                            tmp.Show();
                            break;
                        }
                    }

                    else if (obj is Area)
                    {
                        Area tmp = (Area)obj;
                        if (tmp.NameOfArea == enter)
                        {
                            tmp.Show();
                            break;
                        }
                    }
                    else if (obj is Place)
                    {
                        Place tmp = (Place)obj;
                        if (tmp.Latitude.ToString() == enter || tmp.Longitude.ToString() == enter)
                        {
                            tmp.Show();
                            break;
                        }
                    }
                }
            } while (true);
            City clone  = city2.ShallowCopy();
            City clone2 = (City)city2.Clone();

            clone.Show();
            clone2.Show();
            Console.ReadKey();
        }
Esempio n. 5
0
        public static int Compare(object s1, object s2)
        {
            if (s1 is Address)
            {
                Address tmp1 = (Address)s1;
                if (s2 is Address)
                {
                    Address tmp2 = (Address)s2;
                    return(String.Compare(tmp1.NameOfCity, tmp2.NameOfCity));
                }
                else if (s2 is Megapolice)
                {
                    Megapolice tmp2 = (Megapolice)s2;
                    return(String.Compare(tmp1.NameOfCity, tmp2.NameOfCity));
                }
                else if (s2 is City)
                {
                    City tmp2 = (City)s2;
                    return(String.Compare(tmp1.NameOfCity, tmp2.NameOfCity));
                }

                else if (s2 is Area)
                {
                    Area tmp2 = (Area)s2;
                    return(String.Compare(tmp1.NameOfArea, tmp2.NameOfArea));
                }
                else if (s2 is Place)
                {
                    Place tmp2 = (Place)s2;
                    Place tmp  = new Place(tmp1.Latitude, tmp1.Longitude);
                    return(tmp2.CompareTo(tmp));
                }
                else
                {
                    return(0);
                }
            }
            else if (s1 is Megapolice)
            {
                Megapolice tmp1 = (Megapolice)s1;
                if (s2 is Address)
                {
                    Address tmp2 = (Address)s2;
                    return(String.Compare(tmp1.NameOfCity, tmp2.NameOfCity));
                }
                else if (s2 is Megapolice)
                {
                    Megapolice tmp2 = (Megapolice)s2;
                    return(String.Compare(tmp1.NameOfCity, tmp2.NameOfCity));
                }
                else if (s2 is City)
                {
                    City tmp2 = (City)s2;
                    return(String.Compare(tmp1.NameOfCity, tmp2.NameOfCity));
                }

                else if (s2 is Area)
                {
                    Area tmp2 = (Area)s2;
                    return(String.Compare(tmp1.NameOfArea, tmp2.NameOfArea));
                }
                else if (s2 is Place)
                {
                    Place tmp2 = (Place)s2;
                    Place tmp  = new Place(tmp1.Latitude, tmp1.Longitude);
                    return(tmp2.CompareTo(tmp));
                }
                else
                {
                    return(0);
                }
            }
            else if (s1 is City)
            {
                City tmp1 = (City)s1;
                if (s2 is Address)
                {
                    Address tmp2 = (Address)s2;
                    return(String.Compare(tmp1.NameOfCity, tmp2.NameOfCity));
                }
                else if (s2 is Megapolice)
                {
                    Megapolice tmp2 = (Megapolice)s2;
                    return(String.Compare(tmp1.NameOfCity, tmp2.NameOfCity));
                }
                else if (s2 is City)
                {
                    City tmp2 = (City)s2;
                    return(String.Compare(tmp1.NameOfCity, tmp2.NameOfCity));
                }

                else if (s2 is Area)
                {
                    Area tmp2 = (Area)s2;
                    return(String.Compare(tmp1.NameOfArea, tmp2.NameOfArea));
                }
                else if (s2 is Place)
                {
                    Place tmp2 = (Place)s2;
                    Place tmp  = new Place(tmp1.Latitude, tmp1.Longitude);
                    return(tmp2.CompareTo(tmp));
                }
                else
                {
                    return(0);
                }
            }

            else if (s1 is Area)
            {
                Area tmp1 = (Area)s1;
                if (s2 is Address)
                {
                    Address tmp2 = (Address)s2;
                    return(String.Compare(tmp1.NameOfArea, tmp2.NameOfArea));
                }
                else if (s2 is Megapolice)
                {
                    Megapolice tmp2 = (Megapolice)s2;
                    return(String.Compare(tmp1.NameOfArea, tmp2.NameOfArea));
                }
                else if (s2 is City)
                {
                    City tmp2 = (City)s2;
                    return(String.Compare(tmp1.NameOfArea, tmp2.NameOfArea));
                }

                else if (s2 is Area)
                {
                    Area tmp2 = (Area)s2;
                    return(String.Compare(tmp1.NameOfArea, tmp2.NameOfArea));
                }
                else if (s2 is Place)
                {
                    Place tmp2 = (Place)s2;
                    Place tmp  = new Place(tmp1.Latitude, tmp1.Longitude);
                    return(tmp2.CompareTo(tmp));
                }
                else
                {
                    return(0);
                }
            }
            else if (s1 is Place)
            {
                Place tmp1 = (Place)s1;
                if (s2 is Address)
                {
                    Address tmp  = (Address)s2;
                    Place   tmp2 = new Place(tmp.Latitude, tmp.Longitude);
                    return(tmp1.CompareTo(tmp2));
                }
                else if (s2 is Megapolice)
                {
                    Megapolice tmp  = (Megapolice)s2;
                    Place      tmp2 = new Place(tmp.Latitude, tmp.Longitude);
                    return(tmp1.CompareTo(tmp2));
                }
                else if (s2 is City)
                {
                    City  tmp  = (City)s2;
                    Place tmp2 = new Place(tmp.Latitude, tmp.Longitude);
                    return(tmp1.CompareTo(tmp2));
                }

                else if (s2 is Area)
                {
                    Area  tmp  = (Area)s2;
                    Place tmp2 = new Place(tmp.Latitude, tmp.Longitude);
                    return(tmp1.CompareTo(tmp2));
                }
                else if (s2 is Place)
                {
                    Place tmp2 = (Place)s2;
                    return(tmp1.CompareTo(tmp2));
                }
                else
                {
                    return(0);
                }
            }
            else
            {
                return(0);
            }
        }
Esempio n. 6
0
        public TestCollections(int numberOf)
        {
            for (int i = 0; i < numberOf; i++)
            {
                Random rnd   = new Random();
                int    menue = rnd.Next(1, 6);
                switch (menue)
                {
                case 1:
                    Place add = new Place();
                    while (true)
                    {
                        try
                        {
                            CollectionOneList.Add(add);
                            CollectionTwoList.Add(add.ToString());
                            CollectionTwoSD.Add(add.ToString(), add);
                            CollectionOneSD.Add(add, add);
                            break;
                        }
                        catch
                        {
                            CollectionOneList.Remove(add);
                            CollectionTwoList.Remove(add.ToString());
                            add = new Place();
                        }
                    }
                    break;

                case 2:
                    Area ad = new Area();
                    while (true)
                    {
                        try
                        {
                            CollectionOneList.Add(ad);
                            CollectionTwoList.Add(ad.ToString());
                            CollectionTwoSD.Add(ad.placeSaver.ToString(), ad);
                            CollectionOneSD.Add(ad.placeSaver, ad);
                            break;
                        }
                        catch
                        {
                            CollectionOneList.Remove(ad);
                            CollectionTwoList.Remove(ad.ToString());
                            ad = new Area();
                        }
                    }
                    break;

                case 3:
                    City addd = new City();
                    while (true)
                    {
                        try
                        {
                            CollectionOneList.Add(addd);
                            CollectionTwoList.Add(addd.ToString());
                            CollectionTwoSD.Add(addd.placeSaver.ToString(), addd);
                            CollectionOneSD.Add(addd.placeSaver, addd);
                            break;
                        }
                        catch
                        {
                            CollectionOneList.Remove(addd);
                            CollectionTwoList.Remove(addd.ToString());
                            addd = new City();
                        }
                    }
                    break;

                case 4:
                    Megapolice adddd = new Megapolice();
                    while (true)
                    {
                        try
                        {
                            CollectionOneList.Add(adddd);
                            CollectionTwoList.Add(adddd.ToString());
                            CollectionTwoSD.Add(adddd.placeSaver.ToString(), adddd);
                            CollectionOneSD.Add(adddd.placeSaver, adddd);
                            break;
                        }
                        catch
                        {
                            CollectionOneList.Remove(adddd);
                            CollectionTwoList.Remove(adddd.ToString());
                            adddd = new Megapolice();
                        }
                    }
                    break;

                case 5:
                    Address addddd = new Address();
                    while (true)
                    {
                        try
                        {
                            CollectionOneList.Add(addddd);
                            CollectionTwoList.Add(addddd.ToString());
                            CollectionTwoSD.Add(addddd.placeSaver.ToString(), addddd);
                            CollectionOneSD.Add(addddd.placeSaver, addddd);
                            break;
                        }
                        catch
                        {
                            CollectionOneList.Remove(addddd);
                            CollectionTwoList.Remove(addddd.ToString());
                            addddd = new Address();
                        }
                    }
                    break;
                }
            }
        }