-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSong.java
More file actions
88 lines (78 loc) · 2 KB
/
Song.java
File metadata and controls
88 lines (78 loc) · 2 KB
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
import java.util.Comparator;
/**
* This class represents the data contained within a single song.
* A comparator can be provided to each Song as the basis for it's compareTo,
* otherwise songs will be ordered by their title.
*/
public class Song implements Comparable<Song> {
// fields
private String title;
private String artist;
private String genres;
private int year;
private int bpm;
private int energy;
private int danceability;
private int loudness;
private int liveness;
private Comparator<Song> comparator;
// constructors
public Song(String title,
String artist,
String genre,
int year,
int bpm,
int energy,
int danceability,
int loudness,
int liveness,
Comparator<Song> comparator) {
this.title = title;
this.artist = artist;
this.genres = genres;
this.year = year;
this.bpm = bpm;
this.energy = energy;
this.danceability = danceability;
this.loudness = loudness;
this.liveness = liveness;
this.comparator = comparator;
}
public Song(String title,
String artist,
String genre,
int year,
int bpm,
int energy,
int danceability,
int loudness,
int liveness) { // no comparator, defaults to null
this(title,
artist,
genre,
year,
bpm,
energy,
danceability,
loudness,
liveness,
null);
}
// accessors
public String getTitle() { return title; }
public String getArtist() { return artist; }
public String getGenres() { return genres; }
public int getYear() { return year; }
public int getBPM() { return bpm; }
public int getEnergy() { return energy; }
public int getDanceability() { return danceability; }
public int getLoudness() { return loudness; }
public int getLiveness() { return liveness; }
// comparisons
public int compareTo(Song other) {
if(this.comparator != null)
return this.comparator.compare(this,other);
else
return this.title.compareTo(other.title);
}
}