[LIB-2] Add snooker-score-api source files
[snooker-score-api.git] / src / main / java / org / hedgecode / snooker / SnookerScoreApp.java
diff --git a/src/main/java/org/hedgecode/snooker/SnookerScoreApp.java b/src/main/java/org/hedgecode/snooker/SnookerScoreApp.java
new file mode 100644 (file)
index 0000000..e81bc6e
--- /dev/null
@@ -0,0 +1,97 @@
+/*
+ * Copyright (c) 2017. Developed by Hedgecode.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.hedgecode.snooker;
+
+import java.text.SimpleDateFormat;
+
+import org.hedgecode.snooker.api.APIException;
+import org.hedgecode.snooker.api.Event;
+import org.hedgecode.snooker.api.Events;
+import org.hedgecode.snooker.api.Season;
+
+/**
+ * Snooker Score Main Application.
+ *
+ * @author Dmitry Samoshin aka gotty
+ */
+public final class SnookerScoreApp {
+
+    private static final String EMPTY = "";
+    private static final String DELIMITER =
+            "********************************************************************************";
+    private static final String[] WELCOME = {
+            "                    Welcome to Hedgecode Snooker Score API!                     ",
+            "                -----------------------------------------------                 ",
+            "         It is an API library for portal snooker.org, which contains            ",
+            "      the results of snooker competitions and other snooker information.        ",
+            "    This library provides a set of entity objects that can be used in client    ",
+            "    applications (to inform about the results of snooker), developed in Java.   "
+    };
+    private static final String CURRENT_EVENTS = "  Current Snooker Events:  ";
+    private static final String UPCOMING_EVENTS = "  Upcoming Snooker Events:  ";
+    private static final String INDENT = "     ";
+
+    private static SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("dd.MM.yyyy");
+
+    private static final int UPCOMING_COUNT = 5;
+
+    public static void main(String[] args) throws APIException
+    {
+        System.out.println(EMPTY);
+        System.out.println(DELIMITER);
+        for (String line : WELCOME) {
+            System.out.println(line);
+        }
+
+        Events events = Snooker.uncachedAPI().getSeasonEvents(
+                Season.CURRENT_SEASON
+        );
+        events.sortByDate();
+
+        Events currentEvents = events.current();
+        if (!currentEvents.isEmpty()) {
+            System.out.println(DELIMITER);
+            System.out.println(CURRENT_EVENTS);
+        }
+        for (Event currentEvent : currentEvents) {
+            printEvent(currentEvent);
+        }
+
+        System.out.println(DELIMITER);
+        System.out.println(UPCOMING_EVENTS);
+
+        int count = 0;
+        Events upcomingEvents = events.upcoming();
+        for (Event upcomingEvent : upcomingEvents) {
+            printEvent(upcomingEvent);
+            ++count;
+            if (count >= UPCOMING_COUNT) break;
+        }
+        System.out.println(DELIMITER);
+        System.out.println(EMPTY);
+    }
+
+    private static void printEvent(Event event) {
+        System.out.println(
+                INDENT  + event.name()
+                        + " [" + DATE_FORMAT.format(event.startDate())
+                        + " - " + DATE_FORMAT.format(event.endDate()) + "]"
+                        + " (" + event.country() + ", " + event.city() + ")"
+        );
+    }
+
+}