public int CompareTo(object obj)
        {
            if (ReferenceEquals(obj, null))
            {
                throw new ArgumentNullException(nameof(obj));
            }

            if (!(obj is Book))
            {
                throw new ArgumentException(nameof(obj));
            }

            var comparebleBook = obj as Book;

            if (string.Compare(ISBN, comparebleBook.ISBN) != 0)
            {
                return(string.Compare(ISBN, comparebleBook.ISBN));
            }

            if (string.Compare(Author, comparebleBook.Author) != 0)
            {
                return(string.Compare(Author, comparebleBook.Author));
            }

            if (string.Compare(Name, comparebleBook.Name) != 0)
            {
                return(string.Compare(Name, comparebleBook.Name));
            }

            if (string.Compare(Publisher, comparebleBook.Publisher) != 0)
            {
                return(string.Compare(Publisher, comparebleBook.Publisher));
            }

            if (PublicationYear.CompareTo(comparebleBook.PublicationYear) != 0)
            {
                return(PublicationYear.CompareTo(comparebleBook.PublicationYear));
            }

            if (PagesNumber.CompareTo(comparebleBook.PagesNumber) != 0)
            {
                return(PagesNumber.CompareTo(comparebleBook.PagesNumber));
            }

            if (Cost.CompareTo(comparebleBook.Cost) != 0)
            {
                return(Cost.CompareTo(comparebleBook.Cost));
            }

            return(0);
        }
Ejemplo n.º 2
0
        /// <inheritdoc />
        /// <exception cref="FormatException">Thrown when <paramref name="format"/> is not supported.</exception>
        public string ToString(string format, IFormatProvider formatProvider)
        {
            if (string.IsNullOrWhiteSpace(format))
            {
                format = "G";
            }

            if (ReferenceEquals(formatProvider, null))
            {
                formatProvider = CultureInfo.CurrentCulture;
            }

            switch (format.Trim().ToUpperInvariant())
            {
            case "G":
                return($"ISBN 13: {Isbn} {Author} {Name} {PublishingHouse} " +
                       $"{PublicationYear.ToString(formatProvider)} " +
                       $"{PageNumber.ToString(formatProvider)} " +
                       $"{string.Format(formatProvider, "{0:C0}", Price)}");

            case "AN":
                return($"{Author} {Name}");

            case "ANH":
                return($"{Author} {Name} {PublishingHouse}");

            case "IANHYP":
                return($"ISBN 13: {Isbn} {Author} {Name} {PublishingHouse} " +
                       $"{PublicationYear.ToString(formatProvider)} " +
                       $"{PageNumber.ToString(formatProvider)}");

            case "ANHY":
                return($"{Author} {Name} {PublishingHouse} " +
                       $"{PublicationYear.ToString(formatProvider)}");

            default:
                throw new FormatException($"The {format} format string is not supported.");
            }
        }
 public override string ToString()
 {
     return(BookName + ", " + WriterName + ", " + PublicationYear.ToString() + ", " + Price.ToString());
 }
Ejemplo n.º 4
0
 public override int GetHashCode()
 {
     return(Author.GetHashCode() + Title.GetHashCode() + CountPages.GetHashCode() + PublicationYear.GetHashCode());
 }
Ejemplo n.º 5
0
        /**
         * Load and parse data from dat_mes.csv
         */

        internal static void LoadData(StudyData studyData)
        {
            if (IsDataLoaded)
            {
                return;
            }

            List <string[]> rows = new List <string[]>();

            using (StreamReader reader = File.OpenText("Data/dat_mes.csv"))
            {
                while (reader.Peek() >= 0)
                {
                    string   line     = reader.ReadLine();
                    string[] rowArray = CSVRowToStringArray(line);
                    if (rowArray.Length > 0)
                    {
                        rows.Add(rowArray);
                    }
                }
            }

            string[] headers = rows[0];
            rows.Remove(headers);

            /**
             * Parse each row array into a Study object.
             * Assumes CSV column ordering:
             *     id,PublicationYear,n,r,VariablesControlled,StudyDesign,
             *     AdherenceMeasure,ConscientiousnessMeasure ,MeanAge,MethodologicalQuality
             */
            foreach (string[] row in rows)
            {
                PublicationYear          publicationYear          = studyData.PublicationYears.AddUnique(row[1]);
                CorrelationCoefficient   correlationCoefficient   = studyData.CorrelationCoefficients.AddUnique(row[2]);
                SampleSize               sampleSize               = studyData.SampleSizes.AddUnique(row[3]);
                VariablesControlled      variablesControlled      = studyData.VariablesControlled.AddUnique(row[4]);
                StudyDesign              studyDesign              = studyData.StudyDesigns.AddUnique(row[5]);
                AdherenceMeasure         adherenceMeasure         = studyData.AdherenceMeasures.AddUnique(row[6]);
                ConscientiousnessMeasure conscientiousnessMeasure = studyData.ConscientiousnessMeasures.AddUnique(row[7]);
                MeanAge meanAge = studyData.MeanAges.AddUnique(row[8]);
                MethodologicalQuality methodologicalQuality = studyData.MethodologicalQualities.AddUnique(row[9]);

                Study newStudy = new Study
                {
                    Id = row[0],
                    PublicationYear          = publicationYear,
                    CorrelationCoefficient   = correlationCoefficient,
                    SampleSize               = sampleSize,
                    VariablesControlled      = variablesControlled,
                    StudyDesign              = studyDesign,
                    AdherenceMeasure         = adherenceMeasure,
                    ConscientiousnessMeasure = conscientiousnessMeasure,
                    MeanAge = meanAge,
                    MethodologicalQuality = methodologicalQuality
                };
                studyData.Studies.Add(newStudy);
            }

            IsDataLoaded = true;
        }