package org.hedgecode.chess;
import java.time.LocalDateTime;
-import java.time.format.DateTimeFormatter;
import java.util.Calendar;
/**
- *
+ * ChessHog utility class for working with console.
*
* @author Dmitry Samoshin aka gotty
*/
public class ChessHogConsole {
- private static final String EMPTY = "";
- private static final String SPACE = " ";
-
private static final String[] ASCII_LOGO = {
" _______ _ _ ",
" | | _|_ _| |___ ___ ___ ___ _| |___ ",
private static final String COPYRIGHT = "Copyright (c) Hedgecode";
- private static final DateTimeFormatter TIME_FORMAT = DateTimeFormatter.ofPattern("HH:mm:ss");
- private static final DateTimeFormatter DATETIME_FORMAT = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss");
-
private static boolean logMode = false;
private ChessHogConsole() {
}
public static void console(String message) {
- if (logMode) {
- log(message);
- } else {
- output(message);
- }
- }
-
- public static void output(String message) {
System.out.println(
- message
+ String.format(
+ logMode ? "[%1$tT] %2$s" : "%2$s",
+ LocalDateTime.now(),
+ message == null ? "" : message
+ )
);
}
- public static void log(String message) {
- System.out.println(
- logTime() + message
- );
+ public static void empty() {
+ console(null);
}
public static void init() {
asciiLogo();
copyright();
version();
- console(EMPTY);
+ empty();
os();
- jave();
- }
-
-
- private static String logTime() {
- return "[" + TIME_FORMAT.format(LocalDateTime.now()) + "]" + SPACE;
+ java();
}
private static void asciiLogo() {
ChessHogProperties.get("chesshog.inception.year")
);
int currentYear = Calendar.getInstance().get(Calendar.YEAR);
- String years = currentYear > inceptionYear
- ? inceptionYear + "-" + currentYear + SPACE
- : inceptionYear + SPACE;
+ String copyright = currentYear > inceptionYear
+ ? String.format("%s-%s %s", inceptionYear, currentYear, COPYRIGHT)
+ : String.format("%s %s", currentYear, COPYRIGHT);
console(
- alignCenter(years + COPYRIGHT)
+ alignCenter(copyright)
);
}
private static void version() {
console(
- alignCenter("v. " + ChessHogProperties.get("chesshog.version"))
+ alignCenter(
+ String.format(
+ "v. %s", ChessHogProperties.get("chesshog.version")
+ )
+ )
);
}
private static void os() {
console(
- "OS:" +
- SPACE + System.getProperty("os.name") +
- SPACE + System.getProperty("os.version") +
- SPACE + System.getProperty("os.arch")
+ String.format(
+ "OS: %s %s %s",
+ System.getProperty("os.name"),
+ System.getProperty("os.version"),
+ System.getProperty("os.arch")
+ )
);
}
- private static void jave() {
+ private static void java() {
console(
- "JRE:" +
- SPACE + System.getProperty("java.runtime.name") +
- SPACE + System.getProperty("java.runtime.version")
+ String.format(
+ "JRE: %s %s",
+ System.getProperty("java.runtime.name"),
+ System.getProperty("java.runtime.version")
+ )
);
console(
- "JVM:" +
- SPACE + System.getProperty("java.vm.vendor") +
- SPACE + System.getProperty("java.vm.name") +
- SPACE + System.getProperty("java.vm.version")
+ String.format(
+ "JVM: %s %s %s",
+ System.getProperty("java.vm.vendor"),
+ System.getProperty("java.vm.name"),
+ System.getProperty("java.vm.version")
+ )
);
}
private static String alignCenter(String message) {
int indent = (ASCII_LOGO[0].length() + message.length()) / 2;
- return String.format("%" + indent + "s", message);
+ return String.format(
+ "%" + indent + "s",
+ message
+ );
}
}