blob: ac27de67ac18f414ffd21af48bd92be96efe02e4 (
plain)
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
|
/*
* Copyright 2013 Jesse Morgan
*/
package com.p4square.grow.model;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import com.fasterxml.jackson.annotation.JsonAnyGetter;
import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonIgnore;
/**
* Chapter is a list of VideoRecords in a Playlist.
*
* @author Jesse Morgan <jesse@jesterpm.net>
*/
public class Chapter implements Cloneable {
private String mName;
private Map<String, VideoRecord> mVideos;
public Chapter(String name) {
mName = name;
mVideos = new HashMap<String, VideoRecord>();
}
/**
* Private constructor for JSON decoding.
*/
private Chapter() {
this(null);
}
/**
* @return The Chapter name.
*/
public String getName() {
return mName;
}
/**
* Set the chapter name.
*
* @param name The name of the chapter.
*/
public void setName(final String name) {
mName = name;
}
/**
* @return The VideoRecord for videoid or null if videoid is not in the chapter.
*/
public VideoRecord getVideoRecord(String videoid) {
return mVideos.get(videoid);
}
/**
* @return A map of video ids to VideoRecords.
*/
@JsonAnyGetter
public Map<String, VideoRecord> getVideos() {
return mVideos;
}
/**
* Set the VideoRecord for a video id.
* @param videoId the video id.
* @param video the VideoRecord.
*/
@JsonAnySetter
public void setVideoRecord(String videoId, VideoRecord video) {
mVideos.put(videoId, video);
}
/**
* Remove the VideoRecord for a video id.
* @param videoId The id to remove.
*/
public void removeVideoRecord(String videoId) {
mVideos.remove(videoId);
}
/**
* @return true if every required video has been completed.
*/
@JsonIgnore
public boolean isComplete() {
boolean complete = true;
for (VideoRecord r : mVideos.values()) {
if (r.getRequired() && !r.getComplete()) {
return false;
}
}
return complete;
}
/**
* @return the completion date for the chapter, or null if it has not been completed.
*/
@JsonIgnore
public Date getCompletionDate() {
Date latest = new Date(0);
for (VideoRecord video : mVideos.values()) {
if (video.getRequired() && !video.getComplete()) {
// Hey, this chapter isn't complete!
return null;
}
Date completionDate = video.getCompletionDate();
if (completionDate.after(latest)) {
latest = completionDate;
}
}
return latest;
}
/**
* Deeply clone a chapter.
*
* @return a new Chapter object identical but independent of this one.
*/
public Chapter clone() throws CloneNotSupportedException {
Chapter c = new Chapter(mName);
for (Map.Entry<String, VideoRecord> videoEntry : mVideos.entrySet()) {
c.setVideoRecord(videoEntry.getKey(), videoEntry.getValue().clone());
}
return c;
}
}
|