/// <summary>
        /// Sorts books by condition that is provided by comparer.
        /// </summary>
        /// <param name="comparer">Comparer that will be used for sorting.</param>
        public IEnumerable <Book> SortBy(IComparer <Book> comparer)
        {
            BookValidator.CheckOnNull(comparer);
            var booksToSort = books.ToList();

            booksToSort.Sort(comparer);
            return(booksToSort);
        }
        /// <summary>
        /// Removes book from books.
        /// </summary>
        /// <param name="book">Book to add.</param>
        /// <exception cref="ItemIsNotFoundException">When book to remove doesn't exist.</exception>
        /// <exception cref="ArgumentNullException">Thrown when book is null.</exception>
        public void Remove(Book book)
        {
            BookValidator.CheckOnNull(book);
            if (!this.books.Contains(book))
            {
                throw new BookIsNotFoundException($"{nameof(book)} isn't found in list.");
            }

            books.Remove(book);
        }
        /// <summary>
        /// Adds book to books.
        /// </summary>
        /// <param name="book">Book to add.</param>
        /// <exception cref="DuplicateItemException">Thrown when there is a try to add already existing book.</exception>
        /// <exception cref="ArgumentNullException">Thrown when book is null.</exception>
        public void Add(Book book)
        {
            BookValidator.CheckOnNull(book);
            if (this.books.Contains(book))
            {
                throw new DuplicateBookException($"{nameof(book)} is already in list.");
            }

            books.Add(book);
        }
Exemplo n.º 4
0
 /// <summary>
 /// Compares this book instance with given.
 /// </summary>
 /// <param name="other">Other book.</param>
 /// <returns>Result of comparison.</returns>
 public int CompareTo(Book other)
 {
     BookValidator.CheckOnNull(other);
     return(other.isbn.CompareTo(this.isbn));
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="BookListService"/> class.
 /// </summary>
 /// <param name="storage">Storage for books.</param>
 public BookListService(IBookListStorage storage)
 {
     BookValidator.CheckOnNull(storage);
     this.bookListStorage = storage;
 }
 /// <summary>
 /// Finds books that satisfy some criteria.
 /// </summary>
 /// <param name="searchCriteria">Search criteria.</param>
 /// <returns>Found books.</returns>
 public IEnumerable <Book> FindByTag(ISearchCriteria <Book> searchCriteria)
 {
     BookValidator.CheckOnNull(searchCriteria);
     return(GetMatchedBooks(searchCriteria));
 }