package net.squanchy.eventdetails.domain.view;

import android.support.annotation.StringRes;

import net.squanchy.R;
import net.squanchy.support.lang.Optional;

public enum ExperienceLevel {
    BEGINNER("beginner", R.string.experience_level_beginner),
    INTERMEDIATE("intermediate", R.string.experience_level_intermediate),
    ADVANCED("advanced", R.string.experience_level_advanced);

    private final String rawLevel;

    private final int labelStringResId;
    ExperienceLevel(String rawLevel, @StringRes int labelStringResId) {

        this.rawLevel = rawLevel;
        this.labelStringResId = labelStringResId;
    }

    public String rawLevel() {
        return rawLevel;
    }

    @StringRes
    public int labelStringResId() {
        return labelStringResId;
    }

    public static Optional<ExperienceLevel> fromNullableRawLevel(String rawLevel) {
        return Optional.fromNullable(rawLevel).map(ExperienceLevel::fromRawLevel);
    }

    public static ExperienceLevel fromRawLevel(String rawLevel) {
        switch (rawLevel.toLowerCase()) {
            case "beginner":
                return ExperienceLevel.BEGINNER;
            case "intermediate":
                return ExperienceLevel.INTERMEDIATE;
            case "advanced":
                return ExperienceLevel.ADVANCED;
            default:
                throw new IllegalArgumentException("Invalid raw level description: " + rawLevel);
        }
    }
}

@@ -154,16 +154,43 @@
 ional;%0A%0A
+import timber.log.Timber;%0A%0A
 public e
@@ -880,32 +880,50 @@
 ing rawLevel) %7B%0A
+        try %7B%0A    
         return O
@@ -985,24 +985,144 @@
 mRawLevel);%0A
+        %7D catch (IllegalArgumentException e) %7B%0A            Timber.d(e);%0A            return Optional.absent();%0A        %7D%0A
     %7D%0A%0A    p

Improve ExperienceLevel#fromNullableRawValue()