Exemple #1
0
        // implementation of CompareTo method
        //     comapres first by State,then City,
        //     then streetName and Address number
        //     then apartment unit
        // Exception if( Null object found )
        public int CompareTo(Object alpha)
        {
            if (alpha == null)
            {
                throw new ArgumentNullException("Property object being compared with is NULL");
            }

            Property rightOp = alpha as Property;

            if (rightOp != null)
            {
                if (State.ToLower().CompareTo(rightOp.State.ToLower()) == 0)
                {
                    if (City.ToLower().CompareTo(rightOp.City.ToLower()) == 0)
                    {
                        if (StreetName.ToLower().CompareTo(rightOp.StreetName.ToLower()) == 0)
                        {
                            if (AddNumber.CompareTo(rightOp.AddNumber) == 0)
                            {
                                if (rightOp is Apartment)
                                {
                                    Apartment rightObject = (Apartment)rightOp;
                                    Apartment thisObject  = (Apartment)this;
                                    return(thisObject.Unit.ToLower().CompareTo(rightObject.Unit.ToLower()));
                                }
                                else
                                {
                                    return(0); //becasue we have more typies of property now, if the addresses are the same, then the ranking of two properties are the same
                                    //throw new ArgumentNullException("Error:the address of house has been inputted");
                                }
                            }
                            else
                            {
                                return(AddNumber.CompareTo(rightOp.AddNumber));
                            }
                        }
                        else
                        {
                            return(StreetName.CompareTo(rightOp.StreetName));
                        }
                    }
                    else
                    {
                        return(City.CompareTo(rightOp.City));
                    }
                }

                else
                {
                    return(State.CompareTo(rightOp.State));
                }
            }
            else
            {
                throw new ArgumentNullException("Property object being compared with is NULL");
            }
        }