-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSong.java
More file actions
189 lines (167 loc) · 4.08 KB
/
Song.java
File metadata and controls
189 lines (167 loc) · 4.08 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
import java.util.Comparator;
import java.io.Serializable;
public class Song implements Comparable<Song>, Serializable
{
//fields
private String title;
private String artist;
private String album;
private int length; //length in milliseconds
private String path;
//constructors
public Song()
{
title = null;
artist = null;
album = null;
length = 0;
path = null;
}
public Song(String parTitle, String parArtist, String parAlbum, int parLength)
{
title = parTitle;
artist = parArtist;
album = parAlbum;
length = parLength;
path = "C:\\music\\" + parArtist + "\\" + parTitle + ".mp4";
}
//setters
public void setTitle(String parTitle)
{
title = parTitle;
}
public void setArtist(String parArtist)
{
artist = parArtist;
}
public void setAlbum(String parAlbum)
{
album = parAlbum;
}
public void setLength(int parLength)
{
length = parLength;
}
public void setPath(String parPath)
{
path = parPath;
}
//getter methods
public String getTitle()
{
return title;
}
public String getArtist()
{
return artist;
}
public String getAlbum()
{
return album;
}
public int getLength()
{
return length;
}
public String getPath()
{
return path;
}
public String toString()
{
String retString;
retString = "\nTitle: " + title + ", Artist: " + artist
+ "\nAlbum: " + album + ", Length: " + length/1000 + " seconds"
+ "\nPath: " + path;
return retString;
}
@Override
public boolean equals(Object obj)
// Returns true if 'obj' is a Song with the same title, artist, and album
// otherwise returns false. Note that it does not compare song length.
{
if (obj == this)
return true;
else
if (obj == null || obj.getClass() != this.getClass())
return false;
else
{
Song fp = (Song) obj;
return (this.title.equals(fp.title) && this.artist.equals(fp.artist)
&& this.album.equals(fp.album) && this.length == fp.length);
}
}
public int compareTo (Song other)
// Precondition: 'other' is not null
// Compares this Song with 'other' for order. Returns a positive integer, zero, or a negative integer
// as this object is less than, equal to, or greater than 'other'.
{
if (this.equals(other) == true)
{
return 0;
} else
{
if (!this.title.equals(other.title))
{
return this.title.compareTo(other.title);
} else if (!this.artist.equals(other.artist))
{
return this.artist.compareTo(other.artist);
} else
{
return this.album.compareTo(other.album);
}
}
}
public static Comparator<Song> lengthAscComparator()
{
return new Comparator<Song>()
{
public int compare(Song element1, Song element2)
{
return (element1.length - element2.length);
}
};
}
public static Comparator<Song> lengthDescComparator()
{
return new Comparator<Song>()
{
public int compare(Song element1, Song element2)
{
return (element2.length - element1.length);
}
};
}
public static Comparator<Song> titleDescComparator()
{
return new Comparator<Song>()
{
public int compare(Song element1, Song element2)
{
return element2.title.compareTo(element1.title);
}
};
}
public static Comparator<Song> artistComparator()
{
return new Comparator<Song>()
{
public int compare(Song element1, Song element2)
{
return element2.artist.compareTo(element1.artist);
}
};
}
public static Comparator<Song> albumComparator()
{
return new Comparator<Song>()
{
public int compare(Song element1, Song element2)
{
return element2.album.compareTo(element1.album);
}
};
}
}