summaryrefslogtreecommitdiff
path: root/src/main/java/com/p4square/grow/model/Chapters.java
blob: 175b6fbc670f42dd4c6f35f3935a62596ae7780d (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
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();
        }
    }
}