com.cedarsoft.utils
Class AbstractCmdLine

java.lang.Object
  extended by com.cedarsoft.utils.AbstractCmdLine
All Implemented Interfaces:
CmdLine
Direct Known Subclasses:
DefaultCmdLine, DummyCmdLine, StringCmdLine

public abstract class AbstractCmdLine
extends java.lang.Object
implements CmdLine

Base class that delegates all methods to the a few core methods.


Constructor Summary
AbstractCmdLine()
           
 
Method Summary
 void error(java.lang.String message, java.lang.Object... objects)
          Prints an error on the console
protected abstract  ConsolePrinter getConsolePrinter()
           
abstract  java.io.PrintStream getOut()
           
 void out(java.lang.Process process)
          Redirect the output of the given process
 void out(java.lang.String message, java.lang.Object... objects)
          Prints a message
 void outNl()
          Prints out a new line
protected
<T> void
printPossibleElements(java.util.List<? extends T> elements, Renderer<? super T,java.lang.Object> presenter)
           
<T> T
read(java.lang.String message, java.util.List<? extends T> elements, Renderer<T,java.lang.Object> presenter, ObjectFactory<T> objectFactory)
          Reads a string from the console
 java.lang.String read(java.lang.String message, java.util.List<java.lang.String> elements)
          Reads a string
 java.lang.String read(java.lang.String message, java.util.List<java.lang.String> elements, java.lang.String preselected)
          Reads a string from the console
<T> T
readSelection(java.lang.String message, java.util.List<? extends T> elements)
          Selects an element
<T> T
readSelection(java.lang.String message, java.util.List<? extends T> elements, Renderer<? super T,java.lang.Object> presenter)
          Select an element from the list
 void success(java.lang.String message, java.lang.Object... objects)
          Prints a success message
 void warning(java.lang.String message, java.lang.Object... objects)
          Prints a warning
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.cedarsoft.utils.CmdLine
pause, read, read, readBoolean, readInt, readInt
 

Constructor Detail

AbstractCmdLine

public AbstractCmdLine()
Method Detail

warning

public void warning(@NotNull
                    java.lang.String message,
                    @NotNull
                    java.lang.Object... objects)
Description copied from interface: CmdLine
Prints a warning

Specified by:
warning in interface CmdLine
Parameters:
message - the message
objects - the objects

error

public void error(@NotNull
                  java.lang.String message,
                  @NotNull
                  java.lang.Object... objects)
Description copied from interface: CmdLine
Prints an error on the console

Specified by:
error in interface CmdLine
Parameters:
message - the error message
objects - the objects

success

public void success(@NotNull
                    java.lang.String message,
                    @NotNull
                    java.lang.Object... objects)
Description copied from interface: CmdLine
Prints a success message

Specified by:
success in interface CmdLine
Parameters:
message - the message
objects - the objects

outNl

public void outNl()
Description copied from interface: CmdLine
Prints out a new line

Specified by:
outNl in interface CmdLine

out

public void out(@NotNull
                java.lang.String message,
                @NotNull
                java.lang.Object... objects)
Description copied from interface: CmdLine
Prints a message

Specified by:
out in interface CmdLine
Parameters:
message - the message
objects - the objects

out

public void out(@NotNull
                java.lang.Process process)
Description copied from interface: CmdLine
Redirect the output of the given process

Specified by:
out in interface CmdLine
Parameters:
process - the process the output for is redirected

readSelection

@NotNull
public <T> T readSelection(@NotNull
                                   java.lang.String message,
                                   @NotNull
                                   java.util.List<? extends T> elements)
Description copied from interface: CmdLine
Selects an element

Specified by:
readSelection in interface CmdLine
Parameters:
message - the message
elements - the elements
Returns:
the selected element

printPossibleElements

protected <T> void printPossibleElements(@NotNull
                                         java.util.List<? extends T> elements,
                                         @Nullable
                                         Renderer<? super T,java.lang.Object> presenter)

readSelection

@NotNull
public <T> T readSelection(@NotNull
                                   java.lang.String message,
                                   @NotNull
                                   java.util.List<? extends T> elements,
                                   @Nullable
                                   Renderer<? super T,java.lang.Object> presenter)
Description copied from interface: CmdLine
Select an element from the list

Specified by:
readSelection in interface CmdLine
Parameters:
message - the message
elements - the elements that may be choosen @return the selected element
presenter - an optional presenter that creates a string representation for the elements
Returns:
the selected element

read

@NotNull
public java.lang.String read(@NotNull
                                     java.lang.String message,
                                     @NotNull
                                     java.util.List<java.lang.String> elements)
Description copied from interface: CmdLine
Reads a string

Specified by:
read in interface CmdLine
Parameters:
message - the message
elements - the elements that may be selected
Returns:
the entered value (a free value or one of the elements)

read

@NotNull
public java.lang.String read(@NotNull
                                     java.lang.String message,
                                     @NotNull
                                     java.util.List<java.lang.String> elements,
                                     @NotNull
                                     java.lang.String preselected)
Description copied from interface: CmdLine
Reads a string from the console

Specified by:
read in interface CmdLine
Parameters:
message - the message
elements - the elements
preselected - the preselected string
Returns:
the read string from the console (one of the elements, the preselected value or a newly entered value)

read

@NotNull
public <T> T read(@NotNull
                          java.lang.String message,
                          @NotNull
                          java.util.List<? extends T> elements,
                          @Nullable
                          Renderer<T,java.lang.Object> presenter,
                          @NotNull
                          ObjectFactory<T> objectFactory)
Description copied from interface: CmdLine
Reads a string from the console

Specified by:
read in interface CmdLine
Parameters:
message - the message
elements - the elements (the user may select one of them)
presenter - the presenter
Returns:
the string that has been entered manually or the object that has been selected (String or T)

getOut

@NotNull
public abstract java.io.PrintStream getOut()

getConsolePrinter

@NotNull
protected abstract ConsolePrinter getConsolePrinter()


Copyright © 2009 cedarsoft GmbH. All Rights Reserved.