blob: d6fd6cda265e87c66bee5eb06dd9b5ed21cfdf71 (
plain) (
blame)
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
|
package com.camilstaps.taize;
import com.camilstaps.common.Date;
import com.camilstaps.common.DatedString;
import org.json.JSONException;
import org.json.JSONObject;
/**
* A Podcast is linked to a Date and has a title and a URL
* The title and the URL are held together in a JSON-encoded string, so that this class can extend DatedString
* @author Camil Staps
*/
public class Podcast extends DatedString implements Comparable<Podcast> {
public Podcast(Date date, String title, String url) throws JSONException {
super(date, (new JSONObject()).put("title", title).put("url", url).toString());
}
/**
* Get the JSON object from the string
* @return
*/
private JSONObject getJSONObject() {
try {
return new JSONObject(getString());
} catch (JSONException e) {
return null;
}
}
/**
* Get the title of the podcast
* @return
*/
public String getTitle() {
try {
return getJSONObject().getString("title");
} catch (JSONException e) {
return "";
}
}
/**
* Get the URL of the podcast
* @return
*/
public String getUrl() {
try {
return getJSONObject().getString("url");
} catch (JSONException e) {
return "";
}
}
/**
* Compare with another podcast by date
* @param another
* @return
*/
@Override
public int compareTo(Podcast another) {
return getDate().compareTo(another.getDate());
}
}
|