001package net.filebot.web;
002
003import static java.util.Arrays.*;
004import static java.util.stream.Collectors.*;
005
006import java.util.List;
007
008public enum SortOrder {
009
010        Airdate, DVD, Absolute, Digital, Story, Production, Official, Date;
011
012        @Override
013        public String toString() {
014                switch (this) {
015                        case Airdate:
016                                return "Airdate";
017                        case DVD:
018                                return "DVD";
019                        case Absolute:
020                                return "Absolute";
021                        case Digital:
022                                return "Digital";
023                        case Story:
024                                return "Story Arc";
025                        case Production:
026                                return "Production";
027                        case Official:
028                                return "Official";
029                        default:
030                                return "Date and Title";
031                }
032        }
033
034        public String getDescription() {
035                switch (this) {
036                        case Airdate:
037                                return "Default Order";
038                        case DVD:
039                                return "DVD Order";
040                        case Absolute:
041                                return "Absolute Order";
042                        case Digital:
043                                return "Digital / Alternate Order";
044                        case Story:
045                                return "Story Arc / Alternate DVD Order";
046                        case Production:
047                                return "Production / Regional Order";
048                        case Official:
049                                return "Official Order";
050                        default:
051                                return "Absolute Airdate Order";
052                }
053        }
054
055        public List<String> keys() {
056                switch (this) {
057                        case Airdate:
058                                return asList("Default", "Airdate");
059                        case DVD:
060                                return asList("DVD");
061                        case Absolute:
062                                return asList("Absolute");
063                        case Digital:
064                                return asList("Digital", "Alternate");
065                        case Story:
066                                return asList("Story", "Story Arc", "Alternate DVD");
067                        case Production:
068                                return asList("Production", "Regional");
069                        case Official:
070                                return asList("Official");
071                        default:
072                                return asList("Date", "Date and Title", "Absolute Airdate");
073                }
074        }
075
076        public boolean equals(String name) {
077                return name().equals(name);
078        }
079
080        public boolean matches(String name) {
081                for (String key : keys()) {
082                        if (key.equalsIgnoreCase(name)) {
083                                return true;
084                        }
085                }
086                return false;
087        }
088
089        public static List<String> names() {
090                return stream(values()).map(SortOrder::keys).flatMap(List::stream).collect(toList());
091        }
092
093        public static SortOrder forName(String name) {
094                for (SortOrder order : values()) {
095                        if (order.matches(name)) {
096                                return order;
097                        }
098                }
099                throw new IllegalArgumentException(name + " not in " + names());
100        }
101
102}