Advertisement
lllincolncunha

Playlist

Jul 30th, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.23 KB | None | 0 0
  1. package sp2fy;
  2.  
  3. import java.util.ArrayList;
  4.  
  5. public class Playlist {
  6.     //atributos
  7.     private String nomePlaylist;
  8.     private ArrayList<Musica> playlist;
  9.    
  10.     //construtor
  11.     public Playlist(String nomePlaylist){
  12.         this.nomePlaylist = nomePlaylist;
  13.         playlist = new ArrayList<Musica>();
  14.     }
  15.  
  16.    
  17.    
  18.     public String getNomePlaylist() {
  19.         return this.nomePlaylist;
  20.     }
  21.  
  22.     public void setNomePlaylist(String nomePlaylist) {
  23.         this.nomePlaylist = nomePlaylist;
  24.     }
  25.  
  26.     public boolean removeMusicaDaPlaylist(String nomeMusica) {
  27.         return this.playlist.remove(nomeMusica);
  28.     }
  29.  
  30.     public Object getMusicaDaPlaylist(String musica) throws Exception {
  31.         for (int i = 0; i < this.playlist.size(); i += 1) {
  32.             if (musica.equals(this.playlist.get(i))) {
  33.                 return this.playlist.get(i);
  34.             }
  35.         }
  36.         return false;
  37.     }
  38.    
  39.    
  40.    
  41.     public int hashCode() {
  42.         final int prime = 31;
  43.         int result = 1;
  44.         result = prime * result + ((this.nomePlaylist == null) ? 0 : this.nomePlaylist.hashCode());
  45.         return result;
  46.     }
  47.    
  48.     public boolean equals(Object obj) {
  49.         if (obj instanceof Playlist) {
  50.             Playlist outraPlaylist = (Playlist) obj;
  51.             if (this.getNomePlaylist().equals(outraPlaylist.getNomePlaylist())) {
  52.                 return true;
  53.             }
  54.         }
  55.         return false;
  56.     }
  57.  
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement