summaryrefslogtreecommitdiff
path: root/src/main/java/com/p4square/grow/model/Chapters.java
diff options
context:
space:
mode:
authorJesse Morgan <jesse@jesterpm.net>2017-10-15 19:00:56 -0700
committerJesse Morgan <jesse@jesterpm.net>2017-10-15 19:00:56 -0700
commitb14ec9a9282cb49951b790ce1b48b1a078616926 (patch)
treedeada14d4a407de18812d0e72c32136a2de2caa5 /src/main/java/com/p4square/grow/model/Chapters.java
parent79b8aacbb7b347bba9d14b1332666e7263a3a058 (diff)
Refactor Chapter Ordering Logic20171015
The bug impacting the CCB integration was due to the "Introduction" chapter having a higher "score" than every other chapter. It was a mistake to use Score to compared chapter progress, particularly since there are more chapters than scores. This change gathers the chapter ordering logic, which was scattered throughout the code into a new Chapters enum. Playlist and Chapter now use Chapters as a key, instead of loose strings. Same for the ProgressReporter interface.
Diffstat (limited to 'src/main/java/com/p4square/grow/model/Chapters.java')
-rw-r--r--src/main/java/com/p4square/grow/model/Chapters.java46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/main/java/com/p4square/grow/model/Chapters.java b/src/main/java/com/p4square/grow/model/Chapters.java
new file mode 100644
index 0000000..175b6fb
--- /dev/null
+++ b/src/main/java/com/p4square/grow/model/Chapters.java
@@ -0,0 +1,46 @@
+package com.p4square.grow.model;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonValue;
+
+import java.util.Optional;
+
+/**
+ * The chapters of the training section.
+ */
+public enum Chapters {
+ INTRODUCTION,
+ SEEKER,
+ BELIEVER,
+ DISCIPLE,
+ TEACHER,
+ LEADER;
+
+ /**
+ * A case-insensitive version of Chapters.valueOf().
+ */
+ @JsonCreator
+ public static Chapters fromString(String s) {
+ return valueOf(s.toUpperCase());
+ }
+
+ @JsonValue
+ public String identifier() {
+ return toString().toLowerCase();
+ }
+
+ /**
+ * Convert the Chapter to a score, if possible.
+ */
+ public Optional<Double> toScore() {
+ switch (this) {
+ case SEEKER:
+ case BELIEVER:
+ case DISCIPLE:
+ case TEACHER:
+ return Optional.of(Score.numericScore(this.toString()));
+ default:
+ return Optional.empty();
+ }
+ }
+}