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.DateFormat;
20 import java.text.SimpleDateFormat;
22 import org.hedgecode.snooker.api.APIException;
23 import org.hedgecode.snooker.api.Event;
24 import org.hedgecode.snooker.api.Events;
25 import org.hedgecode.snooker.api.Season;
28 * Snooker Score Main Application.
30 * @author Dmitry Samoshin aka gotty
32 public final class SnookerScoreApp {
34 private static final String EMPTY = "";
35 private static final String DELIMITER =
36 "********************************************************************************";
37 private static final String[] WELCOME = {
38 " Welcome to Hedgecode Snooker Score API! ",
39 " ----------------------------------------------- ",
40 " It is an API library for portal snooker.org, which contains ",
41 " the results of snooker competitions and other snooker information. ",
42 " This library provides a set of entity objects that can be used in client ",
43 " applications (to inform about the results of snooker), developed in Java. "
45 private static final String CURRENT_EVENTS = " Current Snooker Events: ";
46 private static final String UPCOMING_EVENTS = " Upcoming Snooker Events: ";
47 private static final String INDENT = " ";
49 private static final String DATE_FORMAT = "dd.MM.yyyy";
51 private static final int UPCOMING_COUNT = 5;
53 public static void main(String[] args) throws APIException
55 System.out.println(EMPTY);
56 System.out.println(DELIMITER);
57 for (String line : WELCOME) {
58 System.out.println(line);
61 Events events = Snooker.uncachedAPI().getSeasonEvents(
66 Events currentEvents = events.current();
67 if (!currentEvents.isEmpty()) {
68 System.out.println(DELIMITER);
69 System.out.println(CURRENT_EVENTS);
71 for (Event currentEvent : currentEvents) {
72 printEvent(currentEvent);
75 System.out.println(DELIMITER);
76 System.out.println(UPCOMING_EVENTS);
79 Events upcomingEvents = events.upcoming();
80 for (Event upcomingEvent : upcomingEvents) {
81 printEvent(upcomingEvent);
83 if (count >= UPCOMING_COUNT) break;
85 System.out.println(DELIMITER);
86 System.out.println(EMPTY);
89 private static void printEvent(Event event) {
90 final DateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT);
93 + " [" + dateFormat.format(event.startDate())
94 + " - " + dateFormat.format(event.endDate()) + "]"
95 + " (" + event.country() + ", " + event.city() + ")"