forked from mvolkmann/mvolkmann.github.com
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRecording.java.html
More file actions
89 lines (73 loc) · 2.4 KB
/
Copy pathRecording.java.html
File metadata and controls
89 lines (73 loc) · 2.4 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
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR.html1/DTD.html1-transitional.dtd">
<html xmlns="http://www.w3.org/1999.html">
<head>
<title>Recording.java</title>
<link rel="stylesheet" type="text/css" href="../../common.css"/>
</head>
<body>
<h2>Recording.java</h2>
<pre><div class="code">package com.ociweb.demo;
import com.ociweb.lang.ObjectUtil;
import java.util.*;
/**
* This is just a Java Bean.
*/
public class Recording {
private Artist artist;
private List<Track> tracks = new ArrayList<Track>();
private String title;
private int year;
public Recording() {}
public Recording(Artist artist, String title, int year) {
// Note that JSON-lib can't handle circular dependencies
// so the Recording objects can't hold a reference to their Artist
// because the Artist holds a reference to them.
// This is why we're not holding onto the Artist here.
//this.artist = artist;
this.title = title;
this.year = year;
}
public void addTrack(Track track) {
tracks.add(track);
}
public Track addTrack(String name, int rating) {
Track t = new Track(this, name, rating);
addTrack(t);
return t;
}
public boolean equals(Object obj) {
if (obj == null) return false;
if (obj == this) return true;
if (!(obj instanceof Recording)) return false;
Recording r = (Recording) obj;
boolean sameArtist =
artist == null ? r.artist == null :
ObjectUtil.equals(artist.getName(), r.artist.getName());
return sameArtist &&
ObjectUtil.equals(title, r.title) &&
year == r.year;
}
public Artist getArtist() { return artist; }
public void setArtist(Artist artist) { this.artist = artist; }
public String getTitle() { return title; }
public void setTitle(String title) { this.title = title; }
public List<Track> getTracks() { return tracks; }
public void setTracks(List<Track> tracks) {
this.tracks = tracks;
}
public int getYear() { return year; }
public void setYear(int year) { this.year = year; }
public String toString() {
return "Recording: " + title +
" by " + (artist == null ? "null" : artist.getName()) +
" from " + year;
}
}</div></pre>
<hr/>
<p style="text-align:center">
Copyright © 2007 Object Computing, Inc. All rights reserved.
</p>
</body>
</html>