[LIB-9] Console output: stylistic changes
authorgotty <gotty@hedgecode.org>
Thu, 16 May 2019 10:33:30 +0000 (13:33 +0300)
committergotty <gotty@hedgecode.org>
Thu, 16 May 2019 10:33:30 +0000 (13:33 +0300)
chesshog-core/src/main/java/org/hedgecode/chess/ChessHogConsole.java
chesshog-core/src/main/resources/chesshog.properties

index 32da115..52a2802 100644 (file)
 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 = {
             "  _______     _                   _                  ",
             " |   |  _|_ _| |___ ___ ___ ___ _| |___              ",
@@ -44,9 +40,6 @@ public class ChessHogConsole {
 
     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() {
@@ -57,37 +50,26 @@ public class 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() {
@@ -101,46 +83,59 @@ public class ChessHogConsole {
                 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
+        );
     }
 
 }
index 3947321..b5152fc 100644 (file)
@@ -1,4 +1,3 @@
-#
 # Copyright (c) 2018-2019. Developed by Hedgecode.
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # 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.
-#
 
 chesshog.version=0.1-SNAPSHOT
 chesshog.build=0
 chesshog.revision=DEV
 chesshog.inception.year=2018
-
-