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 boolean equals(String name) { 035 return name().equals(name); 036 } 037 038 public static List<String> names() { 039 return stream(values()).map(Enum::name).collect(toList()); 040 } 041 042 public static SortOrder forName(String name) { 043 for (SortOrder order : values()) { 044 if (order.name().equalsIgnoreCase(name) || order.toString().equalsIgnoreCase(name)) { 045 return order; 046 } 047 } 048 049 if ("Default".equalsIgnoreCase(name)) { 050 return Airdate; 051 } 052 053 if ("AbsoluteAirdate".equalsIgnoreCase(name)) { 054 return Date; 055 } 056 057 throw new IllegalArgumentException(name + " not in " + names()); 058 } 059 060}