generated from ohjelmointi2/gradle-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAlbum.java
More file actions
59 lines (50 loc) · 1.54 KB
/
Album.java
File metadata and controls
59 lines (50 loc) · 1.54 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
package databases.part03;
/**
* Represents an album in the Chinook database. You don't need to modify this
* class in this exercise.
*/
public class Album {
private long id;
private String title;
private long artistId;
/**
* Creates a new album with the specified title and artist id. This constructor
* is used when adding a new album to the database, as the database will
* automatically generate an id for the album.
*/
public Album(String title, long artistId) {
// Call the other constructor with -1 as the id. -1 is used to indicate that
// the id is not yet known.
this(-1, title, artistId);
}
/**
* Creates a new album with the specified id, title, and artist id. This
* constructor is used when retrieving an album from the database, as the
* database will provide the id.
*/
public Album(long id, String title, long artistId) {
this.id = id;
this.title = title;
this.artistId = artistId;
}
public long getId() {
return id;
}
public String getTitle() {
return title;
}
public long getArtistId() {
return artistId;
}
@Override
public String toString() {
return "Album [id=" + id + ", title=" + title + ", artistId=" + artistId + "]";
}
@Override
public boolean equals(Object obj) {
if (obj instanceof Album other) {
return id == other.id && title.equals(other.title) && artistId == other.artistId;
}
return false;
}
}