2 * Copyright (c) 2017-2019. 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.util.Calendar;
22 * Snooker Score utility class for working with console.
24 * @author Dmitry Samoshin aka gotty
26 public final class SnookerScoreConsole {
28 private static final String[] ASCII_LOGO = {
30 " | | _|_ _| |___ ___ ___ ___ _| |___ ",
31 " | | -_| . | . | -_| _| . | . | -_| ",
32 " | |___|___|_ |___|___|___|___|___| ",
33 " |___|___| _ |___| ",
34 " ___ ___ ___ ___| |_ ___ ___ ___ ___ ___ ___ ___ ",
35 " |_ -| | . | . | '_| -_| _| |_ -| _| . | _| -_| ",
36 " |___|_|_|___|___|_,_|___|_| |___|___|___|_| |___| ",
43 private static final String COPYRIGHT = "Copyright (c) Hedgecode";
45 private static final String DELIMITER = "*";
47 private static final String[] WELCOME = {
48 " Welcome to Hedgecode Snooker Score API! ",
49 " ----------------------------------------------- ",
50 " It is an API library for portal snooker.org, which contains ",
51 " the results of snooker competitions and other snooker information. ",
52 " This library provides a set of entity objects that can be used in client ",
53 " applications (to inform about the results of snooker), developed in Java. "
56 public static final String ARG_QUIET = "quiet";
57 public static final String ARG_SERVER = "server";
58 public static final String ARG_PORT = "port";
59 public static final String ARG_HELP = "help";
61 private SnookerScoreConsole() {
64 public static void console(String message) {
66 message == null ? "" : message
70 public static void empty() {
74 public static void delimiter() {
79 ).replace(" ", DELIMITER)
83 public static void init() {
91 public static void welcome() {
92 for (String line : WELCOME) {
97 public static void help() {
100 "Usage: java -jar %s-%s.jar -[%s|%s|%s XXXX|%s]",
101 SnookerScoreProperties.get("snooker.name"),
102 SnookerScoreProperties.get("snooker.version"),
111 private static void asciiLogo() {
112 for (String line : ASCII_LOGO) {
117 private static void copyright() {
118 int inceptionYear = Integer.parseInt(
119 SnookerScoreProperties.get("snooker.inception.year")
121 int currentYear = Calendar.getInstance().get(Calendar.YEAR);
122 String copyright = currentYear > inceptionYear
123 ? String.format("%s-%s %s", inceptionYear, currentYear, COPYRIGHT)
124 : String.format("%s %s", currentYear, COPYRIGHT);
126 alignCenter(copyright)
130 private static void version() {
134 "v. %s", SnookerScoreProperties.get("snooker.version")
140 private static String alignCenter(String message) {
141 int indent = (length() + message.length()) / 2;
142 return String.format(
148 private static int length() {
149 return ASCII_LOGO[0].length();