-
Notifications
You must be signed in to change notification settings - Fork 0
/
Song.java
108 lines (90 loc) · 2.7 KB
/
Song.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import java.util.ArrayList;
public class Song{
private String name;
private ArrayList<Artist> artists;
private Album album;
private ArrayList<Genre> genres;
private Date date;
private int duration;
private boolean explicit;
private int popularity;
private Lyrics lyrics;
private static ArrayList<Song> songs = new ArrayList<Song>();
public Song(String n, ArrayList<Artist> ar, Album al, ArrayList<Genre> g, Date da, int du, boolean e, int p){
name = n;
artists = ar;
album = al;
genres = g;
date = da;
duration = du;
explicit = e;
popularity = p;
songs.add(this);
al.addSong(this);
}
public static Song getSong(String n){
for (int i=0; i<songs.size(); i++){
if (songs.get(i).name.toLowerCase().equals(n.toLowerCase())) return songs.get(i);
}
return null;
}
public static ArrayList<Song> getAllSongs(){
return songs;
}
public String getName(){
return name;
}
public ArrayList<Artist> getArtists(){
return artists;
}
public Album getAlbum(){
return album;
}
public ArrayList<Genre> getGenres(){
return genres;
}
public Date getDate(){
return date;
}
public String getFormattedDuration(){
int totalSeconds = duration/1000;
int min = totalSeconds/60;
int sec = totalSeconds%60;
return min + " minutes and " + sec + " seconds";
}
public double getDuration(){
return duration;
}
public boolean getExplicitRating(){
return explicit;
}
public String getFormattedExplicitRating(){
if (explicit) return "Yes";
return "No";
}
public double getPopularity(){
return popularity;
}
public String toString(){
return name;
}
public static ArrayList<Song> sortSongsAlphabetically(ArrayList<Song> songs){
int songCount = songs.size();
for (int i=0; i<songCount-1; i++){
int maxIndex = i;
for (int j=i+1; j < songCount; j++){
String maxString = songs.get(maxIndex).getName().toLowerCase();
String indexString = songs.get(j).getName().toLowerCase();
if(indexString.compareTo(maxString)<0) maxIndex = j;
}
Song temp = songs.get(maxIndex);
songs.set(maxIndex, songs.get(i));
songs.set(i, temp);
}
return songs;
}
//public getSongs{
//for(int i;song.length>i;i++){
//System.out.println(songs.get(i));
//}
}