2 * Copyright (c) 2017-2020. Developed by Hedgecode.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.hedgecode.snooker.api;
19 import java.io.Serializable;
20 import java.util.Calendar;
21 import java.util.LinkedHashMap;
27 * @author Dmitry Samoshin aka gotty
29 public class Season implements Serializable {
31 private static final long serialVersionUID = -4233073149675278053L;
33 private static final Calendar CURRENT_CALENDAR = Calendar.getInstance();
35 private static final int NEW_SEASON_MONTH = 5; /* June */
37 public static final int BEGIN_YEAR = 2005;
39 public static final int CURRENT_YEAR =
40 CURRENT_CALENDAR.get(Calendar.MONTH) >= NEW_SEASON_MONTH
41 ? CURRENT_CALENDAR.get(Calendar.YEAR)
42 : CURRENT_CALENDAR.get(Calendar.YEAR) - 1;
44 public static final int ALL_SEASONS = -1;
46 public static final Season ALL = new Season(ALL_SEASONS);
47 public static final Season CURRENT_SEASON = new Season(CURRENT_YEAR);
49 private static final Map<Integer, Season> SEASONS = new LinkedHashMap<>();
52 for (int year = BEGIN_YEAR; year < CURRENT_YEAR; ++year) {
53 SEASONS.put(year, new Season(year));
55 SEASONS.put(CURRENT_YEAR, CURRENT_SEASON);
56 SEASONS.put(ALL_SEASONS, ALL);
61 private Season(int year) {
65 public static Season getSeason(int year) {
66 return SEASONS.get(year);
69 public int getYear() {
74 public String toString() {
75 return year == ALL_SEASONS ? "All Seasons" : year + "/" + (year + 1);