Class Command<Receiver>

java.lang.Object
pt.tecnico.uilib.menus.Command<Receiver>
Type Parameters:
Receiver - the entity providing the command's context.
Direct Known Subclasses:
DoOpenMenu

public abstract class Command<Receiver> extends Object
Command represents an operation that can be carried out by or over an entity.
  • Field Details

    • _receiver

      protected final Receiver _receiver
      The entity providing the command's context.
    • _valid

      protected Predicate<Receiver> _valid
      The validity predicate: is the command available/visible?
    • _display

      protected final Display _display
      This command's display.
  • Constructor Details

    • Command

      public Command(boolean last, String title)
      Parameters:
      last - indicates whether, in a menu, this is the last command.
      title - the command label in a menu.
    • Command

      public Command(boolean last, String title, Receiver receiver)
      Parameters:
      last - indicates whether, in a menu, this is the last command.
      title - the command label in a menu.
      receiver - the entity providing the command's context.
    • Command

      public Command(boolean last, String title, Receiver receiver, Predicate<Receiver> valid)
      Parameters:
      last - indicates whether, in a menu, this is the last command.
      title - the command label in a menu.
      receiver - the entity providing the command's context.
      valid - custom validity predicate
    • Command

      public Command(String title, Receiver receiver)
      Parameters:
      title - the command label in a menu.
      receiver - the entity providing the command's context.
    • Command

      public Command(String title, Receiver receiver, Predicate<Receiver> valid)
      Parameters:
      title - the command label in a menu.
      receiver - the entity providing the command's context.
      valid - custom validity predicate
  • Method Details

    • title

      public final String title()
      Returns:
      the command's title.
    • isLast

      public boolean isLast()
      Indicates whether, in a menu, this is the last command.
      Returns:
      true if, in a menu, this is the last command.
    • isValid

      public boolean isValid()
      Returns:
      whether the command is valid for the given receiver.
    • addBooleanField

      public void addBooleanField(String key, String prompt)
    • addRealField

      public void addRealField(String key, String prompt)
    • addIntegerField

      public void addIntegerField(String key, String prompt)
    • addStringField

      public void addStringField(String key, String prompt)
    • addOptionField

      public void addOptionField(String key, String prompt, String... options)
    • booleanField

      public Boolean booleanField(String key)
    • realField

      public Double realField(String key)
    • integerField

      public Integer integerField(String key)
    • stringField

      public String stringField(String key)
    • optionField

      public String optionField(String key)
    • performCommand

      public final void performCommand() throws CommandException
      Throws:
      CommandException
    • execute

      protected abstract void execute() throws CommandException
      Executes the command: as defined in the Command pattern, the command's execution should eventually invoke the receiver's action.
      Throws:
      CommandException - if something wrong or unexpected occurs.