summaryrefslogtreecommitdiff
path: root/src/com/p4square/grow/model/Chapter.java
diff options
context:
space:
mode:
authorJesse Morgan <jesse@jesterpm.net>2013-11-09 15:24:56 -0800
committerJesse Morgan <jesse@jesterpm.net>2013-11-09 15:24:56 -0800
commit0d90da39f77ac3cfa607a68bc59336bf0bdff240 (patch)
tree1a2133dea8035004052e1fddf9b4c022fb8e21e1 /src/com/p4square/grow/model/Chapter.java
parentebbfb39ca9b63c170ca7b609dd07d234d89ab23a (diff)
Refactored TrainingResource to use the Provider interface.
Playlists are now generated from a default playlist and regularly merged with the default playlist to get updates. Also adding the Question tests that got left out of a previous commit.
Diffstat (limited to 'src/com/p4square/grow/model/Chapter.java')
-rw-r--r--src/com/p4square/grow/model/Chapter.java79
1 files changed, 79 insertions, 0 deletions
diff --git a/src/com/p4square/grow/model/Chapter.java b/src/com/p4square/grow/model/Chapter.java
new file mode 100644
index 0000000..4d59983
--- /dev/null
+++ b/src/com/p4square/grow/model/Chapter.java
@@ -0,0 +1,79 @@
+/*
+ * Copyright 2013 Jesse Morgan
+ */
+
+package com.p4square.grow.model;
+
+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 Map<String, VideoRecord> mVideos;
+
+ public Chapter() {
+ mVideos = new HashMap<String, VideoRecord>();
+ }
+
+ /**
+ * @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);
+ }
+
+ /**
+ * @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;
+ }
+
+ /**
+ * Deeply clone a chapter.
+ *
+ * @return a new Chapter object identical but independent of this one.
+ */
+ public Chapter clone() throws CloneNotSupportedException {
+ Chapter c = new Chapter();
+ for (Map.Entry<String, VideoRecord> videoEntry : mVideos.entrySet()) {
+ c.setVideoRecord(videoEntry.getKey(), videoEntry.getValue().clone());
+ }
+ return c;
+ }
+}