Exemplo n.º 1
0
        public int CompareTo(Product other)
        {
            if (ReferenceEquals(this, other))
            {
                return(0);
            }
            if (ReferenceEquals(null, other))
            {
                return(1);
            }

            var priceComparison = Price.CompareTo(other.Price);

            if (priceComparison != 0)
            {
                return(priceComparison);
            }

            var nameComparison = string.Compare(Name, other.Name, StringComparison.Ordinal);

            if (nameComparison != 0)
            {
                return(nameComparison);
            }

            return(string.Compare(Type, other.Type, StringComparison.Ordinal));
        }
Exemplo n.º 2
0
        public int CompareTo(object obj)
        {
            var or = obj as OrderRecord;

            if (or == null)
            {
                throw new ArgumentException("Object is not an OrderRecord");
            }
            if (Side != or.Side)
            {
                throw new ArgumentException("Trying to sort orders from different market sides");
            }
            if (Symbol != or.Symbol)
            {
                throw new ArgumentException("Trying to sort orders with different symbols");
            }

            if (Price != or.Price)
            {
                return(Side == MarketSide.Ask
                    ? Price.CompareTo(or.Price)
                    : or.Price.CompareTo(Price));
            }
            if (LastUpdateTime != or.LastUpdateTime)
            {
                return(LastUpdateTime.CompareTo(or.LastUpdateTime));
            }
            return(String.Compare(OrderID, or.OrderID, StringComparison.Ordinal));
        }
Exemplo n.º 3
0
 public int CompareTo(Part other)
 {
     if (other == null)
     {
         throw new ArgumentNullException();
     }
     return(Price.CompareTo(other.Price));
 }
        public int CompareTo(object obj)
        {
            DreamTeam dreamTeam      = (DreamTeam)obj;
            int       compareByPrice = -Price.CompareTo(dreamTeam.Price);
            int       compareByName  = this.ToString().CompareTo(dreamTeam.ToString());

            return(compareByPrice != 0 ? compareByPrice : compareByName);
        }
        public int CompareTo(object obj)
        {
            DreamTeamComponent driver = (DreamTeamComponent)obj;
            int compareByPrice        = -Price.CompareTo(driver.Price);
            int compareBySurname      = Name.CompareTo(driver.Name);

            return(compareByPrice != 0 ? compareByPrice : compareBySurname);
        }
Exemplo n.º 6
0
 /// <summary>
 /// Compares the current object with another object of the same type.
 /// </summary>
 /// <returns>
 /// A value that indicates the relative order of the objects being compared. The return value has the following meanings: Value Meaning Less than zero This object is less than the <paramref name="other"/> parameter.Zero This object is equal to <paramref name="other"/>. Greater than zero This object is greater than <paramref name="other"/>.
 /// </returns>
 /// <param name="other">An object to compare with this object.</param>
 public int CompareTo(IndicatorDataPoint other)
 {
     if (ReferenceEquals(other, null))
     {
         // everything is greater than null via MSDN
         return(1);
     }
     return(Price.CompareTo(other.Price));
 }
Exemplo n.º 7
0
        public int CompareTo(Book other)
        {
            if (ReferenceEquals(other, null))
            {
                throw new ArgumentNullException();
            }

            return(Price.CompareTo(other.Price));
        }
Exemplo n.º 8
0
        public int CompareTo(Order other)
        {
            int cmp = Price.CompareTo(other.Price);

            if (cmp == 0)
            {
                cmp = Id.CompareTo(other.Id);
            }
            return(cmp * Math.Sign(Size));
        }
Exemplo n.º 9
0
        public void ComparisonTest()
        {
            Price p  = new Price(1000);
            Price p1 = new Price(1001);
            Price p2 = new Price(1000);

            Assert.IsTrue(p < p1, "operator< fails");
            Assert.IsTrue(p1 > p, "operator> fails");

            Assert.IsFalse(p2 > p, "operator> fails");
            Assert.IsFalse(p2 < p, "operator> fails");

            Assert.IsTrue(p.Equals(p2), "Equals fails");
            Assert.IsFalse(p.Equals(null), "Equals fails");
            Assert.IsFalse(p.Equals(1), "Equals fails");

            Assert.IsTrue(p.CompareTo(p1) < 0, "CompareTo fails");
            Assert.IsTrue(p.CompareTo(p2) == 0, "CompareTo fails");
            Assert.IsTrue(p1.CompareTo(p2) > 0, "CompareTo fails");
        }
Exemplo n.º 10
0
        public int CompareTo(object obj)
        {
            if (!(obj is Product))
            {
                throw new Exception("um erro ocorreu.");
            }

            Product other = obj as Product;

            return(Price.CompareTo(other.Price));
        }
Exemplo n.º 11
0
        // Implement the generic CompareTo method with the Printed_Edition
        // class as the Type parameter.
        public int CompareTo(Printed_Edition other)
        {
            // If other is not a valid object reference, this instance is greater.
            if (other == null)
            {
                return(1);
            }

            // The  comparison depends on the comparison of
            // price
            return(Price.CompareTo(other.Price));
        }
Exemplo n.º 12
0
 public int CompareTo(UnmatchedOrder other)
 {
     if (other == null)
     {
         return(-1);
     }
     if (Price != other.Price)
     {
         return(BidOrAsk == 1 ? Price.CompareTo(other.Price) : other.Price.CompareTo(Price));
     }
     return(PrivID.CompareTo(other.PrivID));
 }
Exemplo n.º 13
0
        public string correct()
        {
            if (Id < Book.smallestIdPossible)
            {
                return("book has bad id");
            }
            if (Title == "")
            {
                return("new book has empty title");
            }
            if (Price.CompareTo(0.0m) <= 0)
            {
                return("new book has price lower than or equal to 0");
            }
            if (priceMinusDiscountInProcent < 0 || priceMinusDiscountInProcent > 100)
            {
                return("new book price minus discount in procent must range from 0 to 100");
            }
            if (quantity < 0)
            {
                return("new book quantity must be equal to or greater than 0");
            }
            if (startSellingDate == null)
            {
                return("enter start selling date");
            }

            foreach (Author a in authors)
            {
                if (!a.correct())
                {
                    return("one of authors is incorrect (empty name, lastname or id <= 0)");
                }
            }
            foreach (Category c in categories)
            {
                if (!c.correct())
                {
                    return("One of categories is incorrect (empty name)");
                }
            }
            foreach (Bonus b in bonuses)
            {
                if (!b.correct())
                {
                    return("One of bonuses is incorrect (start date >= end date or score is 0)");
                }
            }

            return("");
        }
Exemplo n.º 14
0
        public int CompareTo(Product other)
        {
            if (Object.ReferenceEquals(other, null))
            {
                return(1);
            }
            int result = Name.CompareTo(other.Name);

            if (result == 0)
            {
                result = Price.CompareTo(other.Price);
            }
            return(result);
        }
Exemplo n.º 15
0
        public void CompareTo_same_by_current_price()
        {
            var lhs = new Price() { Symbol = "GOOG", CurrentPrice = (decimal)123.45, PreviousPrice = 0 };

              var rhs = new Price();
              rhs.Symbol = "MSFT";
              rhs.CurrentPrice = (decimal)123.45;
              rhs.PreviousPrice = (decimal)999;

              var expected = 0;
              var actual = rhs.CompareTo(lhs, PriceComparisonType.CurrentPrice);

              Assert.Equal(expected, actual);
        }
        public int CompareTo(Product other)
        {
            int resultOfCompare = Name.CompareTo(other.Name);

            if (resultOfCompare == 0)
            {
                resultOfCompare = Producer.CompareTo(other.Producer);
            }
            if (resultOfCompare == 0)
            {
                resultOfCompare = Price.CompareTo(other.Price);
            }
            return(resultOfCompare);
        }
Exemplo n.º 17
0
        public int CompareTo(Package other)
        {
            int compare = Price.CompareTo(other.Price);

            if (compare == 0)
            {
                compare = Deadline.CompareTo(other.Deadline);
                if (compare == 0)
                {
                    compare = Id.CompareTo(other.Id);
                }
            }

            return(compare);
        }
Exemplo n.º 18
0
        internal BetResult CalculateBetResult(Price hitPrice, BetDirection betDirection)
        {
            int priceCompareResult = hitPrice.CompareTo(this.ExecutePrice);

            if (priceCompareResult == 0)
            {
                return(_bOBetType.HitCount > 1 ? BinaryOption.BetResult.Lose : BinaryOption.BetResult.Draw);
            }
            else if ((priceCompareResult > 0 && betDirection == BetDirection.Up) ||
                     (priceCompareResult < 0 && betDirection == BetDirection.Down))
            {
                return(BinaryOption.BetResult.Win);
            }
            else
            {
                return(BinaryOption.BetResult.Lose);
            }
        }
Exemplo n.º 19
0
        public void CompareTo_different_by_previous_price()
        {
            var lhs = new Price() { Symbol = "GOOG", CurrentPrice = (decimal)123.45, PreviousPrice = 0 };

              var rhs = new Price();
              rhs.Symbol = "MSFT";
              rhs.CurrentPrice = (decimal)9;
              rhs.PreviousPrice = (decimal)999;

              var expected = -1;
              var actual = lhs.CompareTo(rhs, PriceComparisonType.PreviousPrice);

              Assert.Equal(expected, actual);

              expected = 1;
              actual = rhs.CompareTo(lhs, PriceComparisonType.PreviousPrice);
              Assert.Equal(expected, actual);
        }
Exemplo n.º 20
0
 public int CompareTo(Ticket other)
 {
     if (ValidityDate < DateTime.Now)
     {
         return(-1);
     }
     if (other.Class < this.Class)
     {
         return(1);
     }
     else if (other.Class == this.Class)
     {
         return(Price.CompareTo(other.Price));
     }
     else
     {
         return(-1);
     }
 }
Exemplo n.º 21
0
        public void CompareTo_different_by_symbol_implicit_comparer()
        {
            var lhs = new Price() { Symbol = "GOOG", CurrentPrice = (decimal)123.45, PreviousPrice = 0 };

              var rhs = new Price();
              rhs.Symbol = "AAPL";
              rhs.CurrentPrice = (decimal)123.45;
              rhs.PreviousPrice = 0;

              var expected = 1;
              var actual = lhs.CompareTo(rhs);

              Assert.Equal(expected, actual);

              expected = -1;
              actual = rhs.CompareTo(lhs);

              Assert.Equal(expected, actual);
        }
Exemplo n.º 22
0
        public int CompareTo(Product other)
        {
            if (this == other)
            {
                return(0);
            }

            var cmp = string.Compare(Name, other.Name, StringComparison.InvariantCulture);

            if (cmp == 0)
            {
                cmp = string.Compare(Producer, other.Producer, StringComparison.InvariantCulture);
            }

            if (cmp == 0)
            {
                cmp = Price.CompareTo(other.Price);
            }

            return(cmp);
        }
Exemplo n.º 23
0
        private MatchResult MatchPrice(Player player, Price price)
        {
            if (price == null)
            {
                return(MatchResult.InvalidType);
            }
            if (price.Resource != Price.Resource)
            {
                return(MatchResult.BadPriceResource);
            }

            if (price.Resource == Resource.Gold && price.Ammount + AppCore.AccountantSettings.MinMoney > player.Money)
            {
                return(MatchResult.BadPriceAmmount);
            }
            switch (Strategy)
            {
            case TradeStrategy.BelowOrEqualExists:
                if (price.Ammount > player.GetResourceCount(price.Resource))
                {
                    return(MatchResult.BadPriceAmmount);
                }
                break;

            case TradeStrategy.BelowOrEqualAmmount:

                if (price.CompareTo(Price) == 1)
                {
                    return(MatchResult.BadPriceAmmount);
                }
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
            return(MatchResult.Ok);
        }
Exemplo n.º 24
0
        public override int CompareTo(object product)
        {
            if (!(product is FoodProduct p))
            {
                return(-1);
            }

            if (Name.CompareTo(p.Name) == 0)
            {
                if (Company.CompareTo(p.Company) == 0)
                {
                    if (Price.CompareTo(p.Price) == 0)
                    {
                        if (FitTo.CompareTo(p.FitTo) == 0)
                        {
                            return(0);
                        }
                        else
                        {
                            return(FitTo.CompareTo(p.FitTo));
                        }
                    }
                    else
                    {
                        return(Price.CompareTo(p.Price));
                    }
                }
                else
                {
                    return(Company.CompareTo(p.Company));
                }
            }
            else
            {
                return(Name.CompareTo(p.Name));
            }
        }
Exemplo n.º 25
0
        public override int CompareTo(object product)
        {
            if (!(product is NonFoodProduct p))
            {
                return(-1);
            }

            if (Name.CompareTo(p.Name) == 0)
            {
                if (Company.CompareTo(p.Company) == 0)
                {
                    if (Price.CompareTo(p.Price) == 0)
                    {
                        if (Guarantee.CompareTo(p.Guarantee) == 0)
                        {
                            return(0);
                        }
                        else
                        {
                            return(Guarantee.CompareTo(p.Guarantee));
                        }
                    }
                    else
                    {
                        return(Price.CompareTo(p.Price));
                    }
                }
                else
                {
                    return(Company.CompareTo(p.Company));
                }
            }
            else
            {
                return(Name.CompareTo(p.Name));
            }
        }
Exemplo n.º 26
0
 public int CompareTo(IProduct other)
 {
     return(Price.CompareTo(other.Price));
 }
Exemplo n.º 27
0
        public int CompareTo(object obj)
        {
            Product outro = obj as Product;

            return(Price.CompareTo(outro.Price));
        }
Exemplo n.º 28
0
        public int CompareTo(object obj)
        {
            Toy toy = (Toy)obj;

            return(Price.CompareTo(toy.Price));
        }
Exemplo n.º 29
0
        public int CompareTo(AppInfo other)
        {
            if (ReferenceEquals(this, other))
            {
                return(0);
            }
            if (ReferenceEquals(null, other))
            {
                return(1);
            }
            var iapRangeComparison = string.Compare(IAPRange, other.IAPRange, StringComparison.Ordinal);

            if (iapRangeComparison != 0)
            {
                return(iapRangeComparison);
            }
            var adSupportedComparison = AdSupported.CompareTo(other.AdSupported);

            if (adSupportedComparison != 0)
            {
                return(adSupportedComparison);
            }
            var androidVersionComparison = string.Compare(AndroidVersion, other.AndroidVersion, StringComparison.Ordinal);

            if (androidVersionComparison != 0)
            {
                return(androidVersionComparison);
            }
            var androidVersionTextComparison = string.Compare(AndroidVersionText, other.AndroidVersionText, StringComparison.Ordinal);

            if (androidVersionTextComparison != 0)
            {
                return(androidVersionTextComparison);
            }
            var appIdComparison = string.Compare(AppId, other.AppId, StringComparison.Ordinal);

            if (appIdComparison != 0)
            {
                return(appIdComparison);
            }
            var contentRatingComparison = string.Compare(ContentRating, other.ContentRating, StringComparison.Ordinal);

            if (contentRatingComparison != 0)
            {
                return(contentRatingComparison);
            }
            var contentRatingDescriptionComparison = string.Compare(ContentRatingDescription, other.ContentRatingDescription, StringComparison.Ordinal);

            if (contentRatingDescriptionComparison != 0)
            {
                return(contentRatingDescriptionComparison);
            }
            var currencyComparison = string.Compare(Currency, other.Currency, StringComparison.Ordinal);

            if (currencyComparison != 0)
            {
                return(currencyComparison);
            }
            var descriptionComparison = string.Compare(Description, other.Description, StringComparison.Ordinal);

            if (descriptionComparison != 0)
            {
                return(descriptionComparison);
            }
            var descriptionHtmlComparison = string.Compare(DescriptionHTML, other.DescriptionHTML, StringComparison.Ordinal);

            if (descriptionHtmlComparison != 0)
            {
                return(descriptionHtmlComparison);
            }
            var developerComparison = string.Compare(Developer, other.Developer, StringComparison.Ordinal);

            if (developerComparison != 0)
            {
                return(developerComparison);
            }
            var developerAddressComparison = string.Compare(DeveloperAddress, other.DeveloperAddress, StringComparison.Ordinal);

            if (developerAddressComparison != 0)
            {
                return(developerAddressComparison);
            }
            var developerEmailComparison = string.Compare(DeveloperEmail, other.DeveloperEmail, StringComparison.Ordinal);

            if (developerEmailComparison != 0)
            {
                return(developerEmailComparison);
            }
            var developerIdComparison = string.Compare(DeveloperId, other.DeveloperId, StringComparison.Ordinal);

            if (developerIdComparison != 0)
            {
                return(developerIdComparison);
            }
            var developerInternalIdComparison = string.Compare(DeveloperInternalID, other.DeveloperInternalID, StringComparison.Ordinal);

            if (developerInternalIdComparison != 0)
            {
                return(developerInternalIdComparison);
            }
            var developerWebsiteComparison = string.Compare(DeveloperWebsite, other.DeveloperWebsite, StringComparison.Ordinal);

            if (developerWebsiteComparison != 0)
            {
                return(developerWebsiteComparison);
            }
            var editorsChoiceComparison = EditorsChoice.CompareTo(other.EditorsChoice);

            if (editorsChoiceComparison != 0)
            {
                return(editorsChoiceComparison);
            }
            var familyGenreComparison = string.Compare(FamilyGenre, other.FamilyGenre, StringComparison.Ordinal);

            if (familyGenreComparison != 0)
            {
                return(familyGenreComparison);
            }
            var familyGenreIdComparison = string.Compare(FamilyGenreId, other.FamilyGenreId, StringComparison.Ordinal);

            if (familyGenreIdComparison != 0)
            {
                return(familyGenreIdComparison);
            }
            var freeComparison = Free.CompareTo(other.Free);

            if (freeComparison != 0)
            {
                return(freeComparison);
            }
            var genreComparison = string.Compare(Genre, other.Genre, StringComparison.Ordinal);

            if (genreComparison != 0)
            {
                return(genreComparison);
            }
            var genreIdComparison = string.Compare(GenreId, other.GenreId, StringComparison.Ordinal);

            if (genreIdComparison != 0)
            {
                return(genreIdComparison);
            }
            var headerImageComparison = string.Compare(HeaderImage, other.HeaderImage, StringComparison.Ordinal);

            if (headerImageComparison != 0)
            {
                return(headerImageComparison);
            }
            var iconComparison = string.Compare(Icon, other.Icon, StringComparison.Ordinal);

            if (iconComparison != 0)
            {
                return(iconComparison);
            }
            var installsComparison = string.Compare(Installs, other.Installs, StringComparison.Ordinal);

            if (installsComparison != 0)
            {
                return(installsComparison);
            }
            var minInstallsComparison = MinInstalls.CompareTo(other.MinInstalls);

            if (minInstallsComparison != 0)
            {
                return(minInstallsComparison);
            }
            var offersIapComparison = OffersIAP.CompareTo(other.OffersIAP);

            if (offersIapComparison != 0)
            {
                return(offersIapComparison);
            }
            var priceComparison = Price.CompareTo(other.Price);

            if (priceComparison != 0)
            {
                return(priceComparison);
            }
            var priceTextComparison = string.Compare(PriceText, other.PriceText, StringComparison.Ordinal);

            if (priceTextComparison != 0)
            {
                return(priceTextComparison);
            }
            var privacyPolicyComparison = string.Compare(PrivacyPolicy, other.PrivacyPolicy, StringComparison.Ordinal);

            if (privacyPolicyComparison != 0)
            {
                return(privacyPolicyComparison);
            }
            var ratingsComparison = Ratings.CompareTo(other.Ratings);

            if (ratingsComparison != 0)
            {
                return(ratingsComparison);
            }
            var recentChangesComparison = string.Compare(RecentChanges, other.RecentChanges, StringComparison.Ordinal);

            if (recentChangesComparison != 0)
            {
                return(recentChangesComparison);
            }
            var releasedComparison = string.Compare(Released, other.Released, StringComparison.Ordinal);

            if (releasedComparison != 0)
            {
                return(releasedComparison);
            }
            var reviewsComparison = Reviews.CompareTo(other.Reviews);

            if (reviewsComparison != 0)
            {
                return(reviewsComparison);
            }
            var scoreComparison = Score.CompareTo(other.Score);

            if (scoreComparison != 0)
            {
                return(scoreComparison);
            }
            var scoreTextComparison = string.Compare(ScoreText, other.ScoreText, StringComparison.Ordinal);

            if (scoreTextComparison != 0)
            {
                return(scoreTextComparison);
            }
            var sizeComparison = string.Compare(Size, other.Size, StringComparison.Ordinal);

            if (sizeComparison != 0)
            {
                return(sizeComparison);
            }
            var summaryComparison = string.Compare(Summary, other.Summary, StringComparison.Ordinal);

            if (summaryComparison != 0)
            {
                return(summaryComparison);
            }
            var titleComparison = string.Compare(Title, other.Title, StringComparison.Ordinal);

            if (titleComparison != 0)
            {
                return(titleComparison);
            }
            var updatedComparison = Updated.CompareTo(other.Updated);

            if (updatedComparison != 0)
            {
                return(updatedComparison);
            }
            var urlComparison = string.Compare(Url, other.Url, StringComparison.Ordinal);

            if (urlComparison != 0)
            {
                return(urlComparison);
            }
            var versionComparison = string.Compare(Version, other.Version, StringComparison.Ordinal);

            if (versionComparison != 0)
            {
                return(versionComparison);
            }
            var videoComparison = string.Compare(Video, other.Video, StringComparison.Ordinal);

            if (videoComparison != 0)
            {
                return(videoComparison);
            }
            return(string.Compare(VideoImage, other.VideoImage, StringComparison.Ordinal));
        }
 public int CompareTo(Order other)
 {
     return(Price.CompareTo(other.Price));
 }
Exemplo n.º 31
0
        public void CompareTo_the_same_by_symbol_implicit_comparer()
        {
            var lhs = new Price() { Symbol = "GOOG", CurrentPrice = (decimal)123.45, PreviousPrice = 0 };

              var rhs = new Price();
              rhs.Symbol = "GOOG";
              rhs.CurrentPrice = (decimal)999;
              rhs.PreviousPrice = 0;

              var expected = 0;
              var actual = lhs.CompareTo(rhs);

              Assert.Equal(expected, actual);
        }
 //---------------------------------------------------------------------------------------------------------
 /// <summary>
 /// Сравнение объектов для упорядочивания
 /// </summary>
 /// <param name="other">Сравниваемый объект</param>
 /// <returns>Статус сравнения объектов</returns>
 //---------------------------------------------------------------------------------------------------------
 public Int32 CompareTo(CPrice other)
 {
     return(Price.CompareTo(other));
 }
Exemplo n.º 33
0
        public int CompareTo(object obj)
        {
            var component = (Component)obj;

            return(Price.CompareTo(component.Price));
        }
Exemplo n.º 34
0
        public int CompareTo(object obj)
        {
            var newObj = obj as Book;

            if (ReferenceEquals(this, newObj))
            {
                return(0);
            }
            else if (newObj == null)
            {
                return(1);
            }

            var cmp = string.Compare(Isbn, newObj.Isbn, StringComparison.Ordinal);

            if (cmp != 0)
            {
                return(cmp);
            }

            cmp = Authors.OrderBy(t => t).SequenceEqual(newObj.Authors.OrderBy(t => t)) ? 1 : 0;
            if (cmp != 0)
            {
                return(cmp);
            }

            cmp = string.Compare(Name, newObj.Name, StringComparison.Ordinal);
            if (cmp != 0)
            {
                return(cmp);
            }

            cmp = string.Compare(PubCity, newObj.PubCity, StringComparison.Ordinal);
            if (cmp != 0)
            {
                return(cmp);
            }

            cmp = string.Compare(PubName, newObj.PubName, StringComparison.Ordinal);
            if (cmp != 0)
            {
                return(cmp);
            }

            cmp = PubYear.CompareTo(newObj.PubYear);
            if (cmp != 0)
            {
                return(cmp);
            }

            cmp = string.Compare(Note, newObj.Note, StringComparison.Ordinal);
            if (cmp != 0)
            {
                return(cmp);
            }

            cmp = CountPages.CompareTo(newObj.CountPages);
            if (cmp != 0)
            {
                return(cmp);
            }

            cmp = Price.CompareTo(newObj.Price);
            if (cmp != 0)
            {
                return(cmp);
            }

            cmp = CountCopies.CompareTo(newObj.CountCopies);
            if (cmp != 0)
            {
                return(cmp);
            }

            return(0);
        }