Esempio n. 1
0
  /**
   * Determine if the item given is already in cart. An item is in the cart if there appears to have
   * an item with the same name or item is a song and the album which the song belongs to is already
   * in the card, or the album about to be added already have a song added in the cart.
   *
   * @param item The item to be added to the cart.
   * @param cart The user's cart.
   * @return True if the item is already in the cart. False otherwise.
   */
  public LinkedList<Stock> itemIsInCart(String item, LinkedList<Stock> cart) {
    if (cart.size() == 0) {
      System.out.println("Cart is empty");
      return null;
    }
    LinkedList<Stock> duplicated = new LinkedList<Stock>();

    for (Stock s : cart) {
      // If the same song is found in cart.
      if (item.equalsIgnoreCase(s.getTitle())) duplicated.add(s);

      // Find in cart to see if the songs in this album
      // is already added.
      else if (s.getType() == StockType.ALBUM) {
        Album album = (Album) s;
        for (Song song : album.getSongs()) {
          if (song.getTitle().equalsIgnoreCase(item)) duplicated.add(s);
        }
      } else if (s.getType() == StockType.SONG) {
        Song song = (Song) s;
        if (getSongAlbum(song).getTitle().equalsIgnoreCase(item)) {
          System.out.println(item);
          duplicated.add(s);
        }
      }
    }
    return duplicated;
  }
Esempio n. 2
0
 /**
  * Given the title of the item, get the Stock object of the item.
  *
  * @param item The title of the item.
  * @return The Stock object of the item.
  */
 public Stock getItem(String item) {
   for (Album a : musicDb) {
     if (a.getTitle().equalsIgnoreCase(item)) return a;
     for (Song s : a.getSongs()) {
       if (s.getTitle().equalsIgnoreCase(item)) return s;
     }
   }
   return null;
 }
Esempio n. 3
0
 /**
  * Check if a given song belongs to the given album.
  *
  * @param song The name of the song.
  * @param album The title of the album.
  * @return True if the song belongs to the album. False otherwise.
  */
 public boolean songBelongsToAlbum(String song, String album) {
   for (Album a : musicDb) {
     if (a.getTitle().equalsIgnoreCase(album)) {
       for (Song s : a.getSongs()) {
         if (s.getTitle().equalsIgnoreCase(song)) return true;
       }
     }
   }
   return false;
 }
Esempio n. 4
0
  // pokazuje piosenki wybranego albumu
  private void showCurrentAlbum(Album album) {
    flowPane.getChildren().clear();

    Song tempSong = album.getSongs().get(0);
    // ok³adka albumu
    ImageView albumCover = new ImageView(tempSong.getAlbumCover());
    albumCover.imageProperty().bind(tempSong.albumCoverProperty());
    albumCover.setFitWidth(200);
    albumCover.setPreserveRatio(true);
    // tytu³ albumu
    Text albumTitle = new Text(tempSong.getAlbum());
    albumTitle.textProperty().bind(tempSong.albumProperty());
    albumTitle.setFont(new Font("Segoe UI Light", 20));
    albumTitle.setFill(Paint.valueOf("WHITE"));
    // VBox zawieraj¹cy ok³adkê i tytu³
    VBox albumData = new VBox(albumCover, albumTitle);
    flowPane.getChildren().addAll(albumData);

    loadSongs(album.getSongs());
  }
Esempio n. 5
0
  /**
   * Search for the list of songs that matches the searchString.
   *
   * @param searchString The searchString that is typed into the text box in the page.
   * @return The list of songs grouped into Hash Table for easy access.
   */
  public HashMap<Album, LinkedList<Song>> searchForSong(String searchString) {
    HashMap<Album, LinkedList<Song>> results = new HashMap<Album, LinkedList<Song>>();

    // Traverse the database, inside each album, looks for the song
    // that contains the search string.
    for (Album a : musicDb) {
      LinkedList<Song> songs = new LinkedList<Song>();
      for (Song s : a.getSongs()) {
        if (s.getTitle().contains(searchString)) {
          songs.add(s);
        }
      }
      results.put(a, songs);
    }

    return results;
  }