001package net.filebot.web;
002
003import static java.util.Arrays.*;
004import static java.util.Collections.*;
005
006import java.io.Serializable;
007import java.util.List;
008import java.util.Locale;
009import java.util.Objects;
010
011public class SeriesInfo implements Serializable {
012
013        public static final String TYPE_SERIES = "TV Series";
014        public static final String TYPE_ANIME = "Anime";
015
016        // request parameters
017        protected String database;
018        protected String order;
019        protected String language;
020
021        // series classification
022        protected String type;
023
024        // series parameters
025        protected Integer id;
026        protected String name;
027        protected String[] aliasNames;
028        protected String certification;
029        protected SimpleDate startDate;
030        protected String[] genres;
031        protected String[] spokenLanguages;
032        protected String network;
033        protected Double rating;
034        protected Integer ratingCount;
035        protected Integer runtime;
036        protected String status;
037
038        public SeriesInfo() {
039                // used by deserializer
040        }
041
042        public SeriesInfo(SeriesInfo other) {
043                this.database = other.database;
044                this.order = other.order;
045                this.language = other.language;
046                this.type = other.type;
047                this.id = other.id;
048                this.name = other.name;
049                this.aliasNames = other.aliasNames == null ? null : other.aliasNames.clone();
050                this.certification = other.certification;
051                this.startDate = other.startDate == null ? null : other.startDate.clone();
052                this.genres = other.genres == null ? null : other.genres.clone();
053                this.spokenLanguages = other.spokenLanguages == null ? null : other.spokenLanguages.clone();
054                this.network = other.network;
055                this.rating = other.rating;
056                this.ratingCount = other.ratingCount;
057                this.runtime = other.runtime;
058                this.status = other.status;
059        }
060
061        public SeriesInfo(Datasource database, SortOrder order, Locale language, Integer id, String type) {
062                this.database = database == null ? null : database.getIdentifier();
063                this.order = order == null ? null : order.name();
064                this.language = language == null ? null : language.toLanguageTag();
065
066                this.id = id;
067                this.type = type;
068        }
069
070        public void setDatabase(String database) {
071                this.database = database;
072        }
073
074        public String getDatabase() {
075                return database;
076        }
077
078        public void setOrder(String order) {
079                this.order = order;
080        }
081
082        public String getOrder() {
083                return order;
084        }
085
086        public Locale getLanguage() {
087                return language == null ? null : Locale.forLanguageTag(language);
088        }
089
090        public void setLanguage(String language) {
091                this.language = language;
092        }
093
094        public String getType() {
095                return type;
096        }
097
098        public void setType(String type) {
099                this.type = type;
100        }
101
102        public Integer getId() {
103                return id;
104        }
105
106        public void setId(Integer id) {
107                this.id = id;
108        }
109
110        public String getName() {
111                return name;
112        }
113
114        public void setName(String name) {
115                this.name = name;
116        }
117
118        public List<String> getAliasNames() {
119                return aliasNames == null ? emptyList() : unmodifiableList(asList(aliasNames));
120        }
121
122        public void setAliasNames(String... aliasNames) {
123                this.aliasNames = aliasNames.clone();
124        }
125
126        public String getCertification() {
127                return certification;
128        }
129
130        public void setCertification(String certification) {
131                this.certification = certification;
132        }
133
134        public SimpleDate getStartDate() {
135                return startDate;
136        }
137
138        public void setStartDate(SimpleDate startDate) {
139                this.startDate = startDate;
140        }
141
142        public List<String> getGenres() {
143                return genres == null ? emptyList() : unmodifiableList(asList(genres));
144        }
145
146        public void setGenres(String... genres) {
147                this.genres = genres.clone();
148        }
149
150        public List<String> getSpokenLanguages() {
151                return spokenLanguages == null ? emptyList() : unmodifiableList(asList(spokenLanguages));
152        }
153
154        public void setSpokenLanguages(String... spokenLanguages) {
155                this.spokenLanguages = spokenLanguages.clone();
156        }
157
158        public String getNetwork() {
159                return network;
160        }
161
162        public void setNetwork(String network) {
163                this.network = network;
164        }
165
166        public Double getRating() {
167                return rating;
168        }
169
170        public void setRating(Double rating) {
171                this.rating = rating;
172        }
173
174        public Integer getRatingCount() {
175                return ratingCount;
176        }
177
178        public void setRatingCount(Integer ratingCount) {
179                this.ratingCount = ratingCount;
180        }
181
182        public Integer getRuntime() {
183                return runtime;
184        }
185
186        public void setRuntime(Integer runtime) {
187                this.runtime = runtime;
188        }
189
190        public String getStatus() {
191                return status;
192        }
193
194        public void setStatus(String status) {
195                this.status = status;
196        }
197
198        @Override
199        public int hashCode() {
200                return id == null ? 0 : id;
201        }
202
203        @Override
204        public boolean equals(Object object) {
205                if (object instanceof SeriesInfo) {
206                        SeriesInfo other = (SeriesInfo) object;
207                        return Objects.equals(id, other.id) && Objects.equals(database, other.database);
208                }
209                return false;
210        }
211
212        @Override
213        public SeriesInfo clone() {
214                return new SeriesInfo(this);
215        }
216
217        @Override
218        public String toString() {
219                return database + "::" + id;
220        }
221
222}