Code cleanup and formatting. Migrated to java 1.8.
[svjatoslav_commons.git] / src / main / java / eu / svjatoslav / commons / commandline / CLIHelper.java
index 5a774e2..be7e525 100755 (executable)
@@ -18,94 +18,92 @@ import java.io.InputStreamReader;
  */
 public class CLIHelper {
 
-       /**
-        * Ask boolean value from user on command-line.
-        *
-        * @param prompt
-        *            to show to the user
-        * @return <code>true</code> is user answered affirmative.
-        */
-       public static boolean askBoolean(final String prompt) {
-
-               final BufferedReader br = new BufferedReader(new InputStreamReader(
-                               System.in));
-
-               while (true)
-                       try {
-                               System.out.print(prompt);
-
-                               final String userInput = br.readLine().toLowerCase();
-
-                               if ("y".equals(userInput) || "yes".equals(userInput)
-                                               || "true".equals(userInput))
-                                       return true;
-
-                               if ("n".equals(userInput) || "no".equals(userInput)
-                                               || "false".equals(userInput))
-                                       return false;
-
-                               System.out
-                                               .println("Invalid input. You shall enter y/yes/true or n/no/false.");
-                       } catch (final IOException ioe) {
-                               ioe.printStackTrace();
-                       }
-       }
-
-       /**
-        * Ask numerical long value from user on command-line.
-        *
-        * @param prompt
-        *            to show to the user
-        * @return value given by user
-        */
-       public static long askLong(final String prompt) {
-
-               final BufferedReader br = new BufferedReader(new InputStreamReader(
-                               System.in));
-
-               while (true) {
-                       System.out.print(prompt);
-
-                       try {
-                               final String userInput = br.readLine();
-
-                               try {
-                                       final long result = Long.parseLong(userInput);
-                                       return result;
-                               } catch (final NumberFormatException e) {
-                                       System.out.println("\nError: You shall enter an integer.");
-                               }
-                       } catch (final IOException ioe) {
-                               ioe.printStackTrace();
-                       }
-
-               }
-       }
-
-       /**
-        * Ask string value from user on command-line.
-        * 
-        * @param prompt
-        *            to show to the user
-        * @return value given by the user
-        */
-       public static String askString(final String prompt) {
-
-               final BufferedReader br = new BufferedReader(new InputStreamReader(
-                               System.in));
-
-               while (true) {
-                       System.out.print(prompt);
-
-                       try {
-                               final String userInput = br.readLine();
-
-                               return userInput;
-                       } catch (final IOException ioe) {
-                               ioe.printStackTrace();
-                       }
-
-               }
-       }
+    /**
+     * Ask boolean value from user on command-line.
+     *
+     * @param prompt to show to the user
+     * @return <code>true</code> is user answered affirmative.
+     */
+    public static boolean askBoolean(final String prompt) {
+
+        final BufferedReader br = new BufferedReader(new InputStreamReader(
+                System.in));
+
+        while (true)
+            try {
+                System.out.print(prompt);
+
+                String line = br.readLine();
+                if (line != null) {
+                    final String userInput = line.toLowerCase();
+
+                    if ("y".equals(userInput) || "yes".equals(userInput)
+                            || "true".equals(userInput))
+                        return true;
+
+                    if ("n".equals(userInput) || "no".equals(userInput)
+                            || "false".equals(userInput))
+                        return false;
+                }
+                System.out
+                        .println("Invalid input. You shall enter y/yes/true or n/no/false.");
+            } catch (final IOException ioe) {
+                ioe.printStackTrace();
+            }
+    }
+
+    /**
+     * Ask numerical long value from user on command-line.
+     *
+     * @param prompt to show to the user
+     * @return value given by user
+     */
+    public static long askLong(final String prompt) {
+
+        final BufferedReader br = new BufferedReader(new InputStreamReader(
+                System.in));
+
+        while (true) {
+            System.out.print(prompt);
+
+            try {
+                final String userInput = br.readLine();
+
+                try {
+                    return Long.parseLong(userInput);
+                } catch (final NumberFormatException e) {
+                    System.out.println("\nError: You shall enter an integer.");
+                }
+            } catch (final IOException ioe) {
+                ioe.printStackTrace();
+            }
+
+        }
+    }
+
+    /**
+     * Ask string value from user on command-line.
+     *
+     * @param prompt to show to the user
+     * @return value given by the user
+     */
+    public static String askString(final String prompt) {
+
+        final BufferedReader br = new BufferedReader(new InputStreamReader(
+                System.in));
+
+        while (true) {
+            System.out.print(prompt);
+
+            try {
+                final String userInput = br.readLine();
+
+                return userInput;
+            } catch (final IOException ioe) {
+                ioe.printStackTrace();
+            }
+
+        }
+    }
 
 }