From 0e9aa1700b740504689f7a0feb1eb3de1a32ef22 Mon Sep 17 00:00:00 2001 From: Ryuu Mitsuki <117973493+mitsuki31@users.noreply.github.com> Date: Tue, 20 Jun 2023 21:19:34 +0700 Subject: [PATCH] Improve the `Main` class --- src/main/java/com/mitsuki/jmatrix/Main.java | 70 ++++++++++++++------- 1 file changed, 46 insertions(+), 24 deletions(-) diff --git a/src/main/java/com/mitsuki/jmatrix/Main.java b/src/main/java/com/mitsuki/jmatrix/Main.java index 77f8f07..19125dc 100644 --- a/src/main/java/com/mitsuki/jmatrix/Main.java +++ b/src/main/java/com/mitsuki/jmatrix/Main.java @@ -3,25 +3,39 @@ import com.mitsuki.jmatrix.util.Options; import com.mitsuki.jmatrix.util.XMLParser; +/** + * Main class for JMatrix library that provides some information such as JMatrix version. + * + *

This class does not provides API for build the matrix, + * it's just useless class if get imported. + * + *

Usage:

+ * + *
 
+ *   java -jar path/to/jmatrix.jar [-h|-V|-cr]
+ * 
+ * + * @author + * Ryuu Mitsuki + * @version 1.2, 20 June 2023 + * @since 1.0.0 + * @see com.mitsuki.jmatrix.Matrix + */ public class Main { + private static XMLParser XML = new XMLParser(XMLParser.XMLType.CONFIG); + private static String programVersion = XML.getProperty("programName") + " " + getVersion(); + public static void main(String[ ] args) { String arg1 = null; - String arg2 = null; - - XMLParser XML = new XMLParser(XMLParser.XMLType.CONFIG); if (args.length >= 1 && args.length < 2) { arg1 = args[0]; - if (args.length == 2) { - arg2 = args[1]; - } - } - else if (args.length > 1) { + } else if (args.length > 1) { try { throw new IllegalArgumentException("Too much arguments"); - } catch (final Exception e) { - Options.raiseErrorMsg(e, 0); + } catch (final IllegalArgumentException iae) { + Options.raiseErrorMsg(iae, 0); System.out.println(Options.getHelpMsg()[0]); System.out.println(" " + "java -jar [-h|-V|-cr]"); @@ -46,25 +60,16 @@ else if (args.length > 1) { switch (Options.getOptions(arg1)) { case VERSION: - System.out.print(XML.getProperty("programName") + " " + - XML.getProperty("version") + "-"); - System.out.print(XML.getProperty("releaseType")); + String pkgName = String.format(" <%s>", XML.getProperty("packageName")); - if (!XML.getProperty("releaseType").equals("release")) - System.out.print("." + XML.getProperty("betaNum")); - - System.out.printf(" <%s>%s", XML.getProperty("packageName"), System.lineSeparator()); + System.out.println(programVersion + pkgName); break; case HELP: - System.out.print(XML.getProperty("programName") + " " + XML.getProperty("version")); - - if (!XML.getProperty("releaseType").equals("release")) { - System.out.println("-" + XML.getProperty("releaseType") + "." + XML.getProperty("betaNum")); - } else { - System.out.print(System.lineSeparator()); - } + String lines = System.lineSeparator(); + for (byte i = 0; i < (byte) programVersion.length(); i++) lines += "-"; + System.out.println(programVersion + lines + System.lineSeparator()); for (String s : Options.getHelpMsg()) System.out.println(s); break; @@ -73,4 +78,21 @@ else if (args.length > 1) { break; } } + + private static String getVersion() { + String ver = XML.getProperty("version"); + + // Only retrieve the release type if not release and stable release + if (!XML.getProperty("releaseType").equals("release") || + !XML.getProperty("releaseType").equals("stable")) { + ver += "-" + XML.getProperty("releaseType"); + + // This will only retrieve a non-zero beta number + if (XML.getProperty("betaNum").equals("0")) { + ver += "." + XML.getProperty("betaNum"); + } + } + + return ver; + } }