Class InputHelper


  • public class InputHelper
    extends java.lang.Object
    Provides a command line input helper for setting arguments interactively and storing them in the users preferences.
    Author:
    Joel HÃ¥kansson
    • Constructor Summary

      Constructors 
      Constructor Description
      InputHelper()
      Creates a new InputHelper with the default storage location (determined by the calling class's package name)
      InputHelper​(java.lang.Class c)
      Creates a new InputHelper for the specified class.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void clearSettings()
      Clears the settings associated with this object from storage.
      boolean getBoolean​(java.lang.String msg, java.lang.String key, boolean verify)  
      double getDouble​(java.lang.String msg, java.lang.String key, boolean verify)  
      int getInput​(boolean allowEnter)
      Gets a integer from user.
      java.lang.String getKey​(java.lang.String key)
      Gets the value for a key.
      java.lang.String select​(java.lang.String key, java.lang.String[] select, java.lang.String name, boolean verify)
      Selects the value for a key.
      java.lang.String select​(java.lang.String key, java.util.List<Factory> select, java.lang.String name, boolean verify)
      Selects the value for a key.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • InputHelper

        public InputHelper​(java.lang.Class c)
        Creates a new InputHelper for the specified class. The package name for the specified class will be used to locate an appropriate storage location in the user preferences.
        Parameters:
        c - the class to create a InputHelper for
      • InputHelper

        public InputHelper()
        Creates a new InputHelper with the default storage location (determined by the calling class's package name)
    • Method Detail

      • select

        public java.lang.String select​(java.lang.String key,
                                       java.lang.String[] select,
                                       java.lang.String name,
                                       boolean verify)
        Selects the value for a key.
        Parameters:
        key - the key to select a value for
        select - the list of available values
        name - a display name for the key
        verify - if true, and no value is found, lets user select a value
        Returns:
        returns the value for the key.
      • select

        public java.lang.String select​(java.lang.String key,
                                       java.util.List<Factory> select,
                                       java.lang.String name,
                                       boolean verify)
        Selects the value for a key.
        Parameters:
        key - the key to get a value for
        select - the list of available values
        name - the display name for the key
        verify - if true, and no value is found, lets user select a value
        Returns:
        returns the value for the key.
      • getKey

        public java.lang.String getKey​(java.lang.String key)
        Gets the value for a key.
        Parameters:
        key - the key to get a value for
        Returns:
        returns the value for the key
      • getInput

        public int getInput​(boolean allowEnter)
                     throws java.io.IOException
        Gets a integer from user. The assumption is that this value should be a non-zero positive integer, that is the user selects a value from a list starting with one. If the input is an empty string, 0 is returned. If an IO error occurs, -1 is returned.
        Returns:
        returns the integer value suppled by the user on the command line.
        Throws:
        java.io.IOException - if IO fails.
      • getDouble

        public double getDouble​(java.lang.String msg,
                                java.lang.String key,
                                boolean verify)
                         throws java.io.IOException
        Throws:
        java.io.IOException
      • getBoolean

        public boolean getBoolean​(java.lang.String msg,
                                  java.lang.String key,
                                  boolean verify)
                           throws java.io.IOException
        Throws:
        java.io.IOException
      • clearSettings

        public void clearSettings()
                           throws java.util.prefs.BackingStoreException
        Clears the settings associated with this object from storage.
        Throws:
        java.util.prefs.BackingStoreException - if this operation cannot be completed due to a failure in the backing store, or inability to communicate with it.
        java.lang.IllegalStateException - if the associated node (or an ancestor) has been removed with the removeNode() method.