de.caff.util.args

## Class SimpleOnOffSwitch

- java.lang.Object
- - de.caff.util.args.AbstractSwitch
  - - de.caff.util.args.SimpleOnOffSwitch

- All Implemented Interfaces:
    Switch, SwitchOrArgument

      public class SimpleOnOffSwitch
      extends AbstractSwitch

  A boolean switch is for a property that can be switched on or off.
  Since:
    January 27, 2019
  Author:
    Rammi

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static java.lang.String` | `LONG_PREFIX_NO`
    `static java.lang.String` | `LONG_PREFIX_WITH`
    `static java.lang.String` | `LONG_PREFIX_WITHOUT`

    - ### Fields inherited from class de.caff.util.args.AbstractSwitch

      `description, longForm, shortForm`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `SimpleOnOffSwitch(java.lang.Character shortOn, java.lang.String longOn, boolean defaultValue, java.lang.String description)` Constructor.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `found(char shortSwitch)` This switch appears in the command line in the given short form.
    `void` | `found(java.lang.String longSwitch)` This switch appears in the command line in the given long form.
    `java.lang.String` | `getAppearance()` Get the appearance of this switch or argument on the command line.
    `java.util.Collection<java.lang.String>` | `getLongForms()` Get the long forms influencing this switch.
    `java.util.Collection<java.lang.Character>` | `getShortForms()` Get the short one character forms influencing this switch.
    `boolean` | `isSwitchedOn()` Get the value of this switch.
    `boolean` | `isVarLength()` Does this argument or switch have a variable length?
    `Switch` | `viewOff(java.lang.String description)` View the 'off' state as a single switch state.
    `Switch` | `viewOn(java.lang.String description)` View the 'on' state as a single switch state.

    - ### Methods inherited from class de.caff.util.args.AbstractSwitch

      `getDescription`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

    - ### Methods inherited from interface de.caff.util.args.Switch

      `consumeArgument, isOptional, isSwitch, needsArguments`

- - ### Field Detail

    - #### LONG_PREFIX_WITH

          public static final java.lang.String LONG_PREFIX_WITH

      See Also:
        Constant Field Values

    - #### LONG_PREFIX_WITHOUT

          public static final java.lang.String LONG_PREFIX_WITHOUT

      See Also:
        Constant Field Values

    - #### LONG_PREFIX_NO

          public static final java.lang.String LONG_PREFIX_NO

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### SimpleOnOffSwitch

          public SimpleOnOffSwitch(@NotNull
                                   java.lang.Character shortOn,
                                   @NotNull
                                   java.lang.String longOn,
                                   boolean defaultValue,
                                   @NotNull
                                   java.lang.String description)

      Constructor.
      Parameters:
        `shortOn` - the character used for switching on, the switching off character will be automatically done by inverting the case (eg. for `k` it will become `K`), so the character should be in upper or lower case
        `longOn` - the long form used for switching on, the long form for switching off will either be created by prepending `no-` of, if the long form begins with the prefix `with-`, by replacing this prefix with `without-`
        `defaultValue` - default value use when this switch does not appear on the command line
        `description` - description of this switch

  - ### Method Detail

    - #### isVarLength

          public boolean isVarLength()

      Description copied from interface: `SwitchOrArgument`
      Does this argument or switch have a variable length? This is only allowed for the last argument/switch in the command line.
      Returns:
        `true`: this argument or switch consumes the remaining items in the command line
        `false`: this argument or switch just consumes 1 item (for arguments) or 2 items (for switches) from the command line

    - #### viewOn

          @NotNull
          public Switch viewOn(@NotNull
                                        java.lang.String description)

      View the 'on' state as a single switch state.
      Parameters:
        `description` - description of the on state
      Returns:
        switch view of only the on state switches

    - #### viewOff

          @NotNull
          public Switch viewOff(@NotNull
                                         java.lang.String description)

      View the 'off' state as a single switch state.
      Parameters:
        `description` - description of the off state
      Returns:
        switch view of only the off state switches

    - #### getShortForms

          @NotNull
          public java.util.Collection<java.lang.Character> getShortForms()

      Description copied from interface: `Switch`
      Get the short one character forms influencing this switch.

      If the command line switch is `-k`, this method should return a singleton collection with the character `k`.

      Specified by:
        `getShortForms` in interface `Switch`
      Overrides:
        `getShortForms` in class `AbstractSwitch`
      Returns:
        short one character forms, may be empty

    - #### getLongForms

          @NotNull
          public java.util.Collection<java.lang.String> getLongForms()

      Description copied from interface: `Switch`
      Get the long forms influencing this switch.

      The return strings must not include the `--` prefix, and have to consist of characters, digits and the minus sign (`-`.

      So if the command line switch is `--kill-all-idiots`, this method should return a singleton collection with the string `kill-all-idiots`.

      Specified by:
        `getLongForms` in interface `Switch`
      Overrides:
        `getLongForms` in class `AbstractSwitch`
      Returns:
        long switches. may be empty

    - #### getAppearance

          @NotNull
          public java.lang.String getAppearance()

      Description copied from interface: `SwitchOrArgument`
      Get the appearance of this switch or argument on the command line.
      Returns:
        appearance

    - #### found

          public void found(char shortSwitch)

      Description copied from interface: `Switch`
      This switch appears in the command line in the given short form.
      Parameters:
        `shortSwitch` - short form in which this switch appeared

    - #### found

          public void found(@NotNull
                            java.lang.String longSwitch)

      Description copied from interface: `Switch`
      This switch appears in the command line in the given long form.
      Parameters:
        `longSwitch` - long form

    - #### isSwitchedOn

          public boolean isSwitchedOn()

      Get the value of this switch.
      Returns:
        `true`: switched on
        `false`: switched off