Пример #1
0
  /*
   * Search and insert a range of songs
   * @param: option: title or artist
   * @param: string of words to search
   */
  private void insert_search(String option, String words) {

    if (option.equals("artist")) {
      for (SongFile sf : this.centralStore.songs) {
        if (!this.indexMap.containsKey(sf.getID())
            && sf.getArtist().toLowerCase().contains(words)) {
          this.indexMap.put(sf.getID(), this.songs.size());
          this.songs.add(sf);
        }
      }

    } else if (option.equals("title")) {

      for (SongFile sf : this.centralStore.songs) {
        if (!this.indexMap.containsKey(sf.getID()) && sf.getTitle().toLowerCase().contains(words)) {
          this.indexMap.put(sf.getID(), this.songs.size());
          this.songs.add(sf);
        }
      }

    } else {

      System.out.println("Error: wrong option for command insert_search!");
    }
  }
Пример #2
0
  /*
   * Search songs in the playlist
   * @param: option: title or artist
   * @param: string of words
   */
  private void search(String option, String words) {
    if (option.equals("title")) {
      for (SongFile sf : this.songs) {
        if (sf.getTitle().toLowerCase().contains(words)) {
          sf.printSong();
        }
      }

    } else if (option.equals("artist")) {
      for (SongFile sf : this.songs) {
        if (sf.getArtist().toLowerCase().contains(words)) {
          sf.printSong();
        }
      }

    } else {
      System.out.println("Error: wrong option for search.");
    }
  }