DynamicVector<Movie> Controller::findMoviesOfYear(int year) { DynamicVector<Movie> list; for (int i = 0; i < this->repository.movies.size(); i++) { if (this->repository.movies[i].year == year) { list.add(this->repository.movies[i]); } } return list; }
DynamicVector<Movie> Controller::findMoviesOfTitle(string title) { DynamicVector<Movie> list; for (int i = 0; i < this->repository.movies.size(); i++) { if (this->repository.movies[i].title == title) { list.add(this->repository.movies[i]); } } return list; }
/* returns a list of random movies from repo, throws OutOfRangeException */ DynamicVector<Movie> Controller::getRandomMovies(int howMany) { if (howMany<0 || howMany > this->repository.movies.size()) { throw OutOfRangeException("Size is " + this->repository.movies.size()); } DynamicVector<Movie> list; DynamicVector<Movie> shuffledOriginalList = this->repository.movies.clone(); shuffledOriginalList.shuffle(); for (int i = 0; i < howMany; i++) { list.add(shuffledOriginalList[i]); } return list; }
DynamicVector<string> AnagramController::anagramsForWord(string word) { //add the word as the key and the sorted word as value in the dictionary for (int i = 0; i<repo->getAll().getSize(); i++){ string key = repo->getAll().elementAtIndex(i); map.addValueAndKey(key, sortWord(key)); } word = sortWord(word); DynamicVector<string> elements = DynamicVector<string>(); Node<string, string> *first = map.getNodeForValue(word); //find the first node that has as value, the desired sorted word and //add the key to the elements while (first != NULL && first->getData()->getValue() == word) { elements.add(first->getData()->getKey()); first = first->getNext(); } return elements; }