--- /dev/null
+/*
+ * Copyright (c) 2017-2019. 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.util.Calendar;
+
+/**
+ * Snooker Score utility class for working with console.
+ *
+ * @author Dmitry Samoshin aka gotty
+ */
+public final class SnookerScoreConsole {
+
+ private static final String[] ASCII_LOGO = {
+ " _______ _ _ ",
+ " | | _|_ _| |___ ___ ___ ___ _| |___ ",
+ " | | -_| . | . | -_| _| . | . | -_| ",
+ " | |___|___|_ |___|___|___|___|___| ",
+ " |___|___| _ |___| ",
+ " ___ ___ ___ ___| |_ ___ ___ ___ ___ ___ ___ ___ ",
+ " |_ -| | . | . | '_| -_| _| |_ -| _| . | _| -_| ",
+ " |___|_|_|___|___|_,_|___|_| |___|___|___|_| |___| ",
+ " _____ _____ _ ",
+ " | _ | _ |_| ",
+ " | | __| | ",
+ " |__|__|__| |_| "
+ };
+
+ private static final String COPYRIGHT = "Copyright (c) Hedgecode";
+
+ 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. "
+ };
+
+ public static final String ARG_QUIET = "quiet";
+ public static final String ARG_SERVER = "server";
+ public static final String ARG_PORT = "port";
+ public static final String ARG_HELP = "help";
+
+ private SnookerScoreConsole() {
+ }
+
+ public static void console(String message) {
+ System.out.println(
+ message == null ? "" : message
+ );
+ }
+
+ public static void empty() {
+ console(null);
+ }
+
+ public static void delimiter() {
+ console(
+ String.format(
+ "%" + length() + "s",
+ DELIMITER
+ ).replace(" ", DELIMITER)
+ );
+ }
+
+ public static void init() {
+ asciiLogo();
+ empty();
+ copyright();
+ version();
+ empty();
+ }
+
+ public static void welcome() {
+ for (String line : WELCOME) {
+ console(line);
+ }
+ }
+
+ public static void help() {
+ console(
+ String.format(
+ "Usage: java -jar %s-%s.jar -[%s|%s|%s XXXX|%s]",
+ SnookerScoreProperties.get("snooker.name"),
+ SnookerScoreProperties.get("snooker.version"),
+ ARG_QUIET,
+ ARG_SERVER,
+ ARG_PORT,
+ ARG_HELP
+ )
+ );
+ }
+
+ private static void asciiLogo() {
+ for (String line : ASCII_LOGO) {
+ console(line);
+ }
+ }
+
+ private static void copyright() {
+ int inceptionYear = Integer.parseInt(
+ SnookerScoreProperties.get("snooker.inception.year")
+ );
+ int currentYear = Calendar.getInstance().get(Calendar.YEAR);
+ String copyright = currentYear > inceptionYear
+ ? String.format("%s-%s %s", inceptionYear, currentYear, COPYRIGHT)
+ : String.format("%s %s", currentYear, COPYRIGHT);
+ console(
+ alignCenter(copyright)
+ );
+ }
+
+ private static void version() {
+ console(
+ alignCenter(
+ String.format(
+ "v. %s", SnookerScoreProperties.get("snooker.version")
+ )
+ )
+ );
+ }
+
+ private static String alignCenter(String message) {
+ int indent = (length() + message.length()) / 2;
+ return String.format(
+ "%" + indent + "s",
+ message
+ );
+ }
+
+ private static int length() {
+ return ASCII_LOGO[0].length();
+ }
+
+}