2 * Copyright (c) 2017. 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;
19 import java.text.SimpleDateFormat;
21 import org.hedgecode.snooker.api.APIException;
22 import org.hedgecode.snooker.api.Event;
23 import org.hedgecode.snooker.api.Events;
24 import org.hedgecode.snooker.api.Season;
27 * Snooker Score Main Application.
29 * @author Dmitry Samoshin aka gotty
31 public final class SnookerScoreApp {
33 private static final String EMPTY = "";
34 private static final String DELIMITER =
35 "********************************************************************************";
36 private static final String[] WELCOME = {
37 " Welcome to Hedgecode Snooker Score API! ",
38 " ----------------------------------------------- ",
39 " It is an API library for portal snooker.org, which contains ",
40 " the results of snooker competitions and other snooker information. ",
41 " This library provides a set of entity objects that can be used in client ",
42 " applications (to inform about the results of snooker), developed in Java. "
44 private static final String CURRENT_EVENTS = " Current Snooker Events: ";
45 private static final String UPCOMING_EVENTS = " Upcoming Snooker Events: ";
46 private static final String INDENT = " ";
48 private static SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("dd.MM.yyyy");
50 private static final int UPCOMING_COUNT = 5;
52 public static void main(String[] args) throws APIException
54 System.out.println(EMPTY);
55 System.out.println(DELIMITER);
56 for (String line : WELCOME) {
57 System.out.println(line);
60 Events events = Snooker.uncachedAPI().getSeasonEvents(
65 Events currentEvents = events.current();
66 if (!currentEvents.isEmpty()) {
67 System.out.println(DELIMITER);
68 System.out.println(CURRENT_EVENTS);
70 for (Event currentEvent : currentEvents) {
71 printEvent(currentEvent);
74 System.out.println(DELIMITER);
75 System.out.println(UPCOMING_EVENTS);
78 Events upcomingEvents = events.upcoming();
79 for (Event upcomingEvent : upcomingEvents) {
80 printEvent(upcomingEvent);
82 if (count >= UPCOMING_COUNT) break;
84 System.out.println(DELIMITER);
85 System.out.println(EMPTY);
88 private static void printEvent(Event event) {
91 + " [" + DATE_FORMAT.format(event.startDate())
92 + " - " + DATE_FORMAT.format(event.endDate()) + "]"
93 + " (" + event.country() + ", " + event.city() + ")"