From 3102d8bce3426d9cf41aeaf201c360d342677770 Mon Sep 17 00:00:00 2001 From: Jesse Morgan Date: Sat, 9 Apr 2016 14:22:20 -0700 Subject: Switching from Ivy+Ant to Maven. --- src/main/java/com/p4square/grow/model/Chapter.java | 112 +++++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 src/main/java/com/p4square/grow/model/Chapter.java (limited to 'src/main/java/com/p4square/grow/model/Chapter.java') diff --git a/src/main/java/com/p4square/grow/model/Chapter.java b/src/main/java/com/p4square/grow/model/Chapter.java new file mode 100644 index 0000000..3a08e4c --- /dev/null +++ b/src/main/java/com/p4square/grow/model/Chapter.java @@ -0,0 +1,112 @@ +/* + * 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 + */ +public class Chapter implements Cloneable { + private String mName; + private Map mVideos; + + public Chapter(String name) { + mName = name; + mVideos = new HashMap(); + } + + /** + * 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 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; + } + + /** + * 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 videoEntry : mVideos.entrySet()) { + c.setVideoRecord(videoEntry.getKey(), videoEntry.getValue().clone()); + } + return c; + } +} -- cgit v1.2.3