Example #1
0
 /*
  * Print playlist based on option
  * @param: option: title or artist
  *
  * Default order is the inserted order.
  * If the option is not title nor artist, using the default order.
  */
 private void print() {
   ArrayList<SongFile> tmp = new ArrayList<SongFile>(this.songs);
   if (currentOrder.equals("title")) {
     Collections.sort(tmp, new CompareByTitle());
   } else if (currentOrder.equals("artist")) {
     Collections.sort(tmp, new CompareByArtist());
   }
   for (SongFile sf : tmp) {
     sf.printSong();
   }
 }
Example #2
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!");
    }
  }
Example #3
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.");
    }
  }