java.lang.Object
ru.vyarus.dropwizard.guice.module.context.option.OptionsInfo

public final class OptionsInfo extends Object
Provides access to used options and values. Contains only options either set (in GuiceBundle) or read (by guicey, bundles or guice services). Instance bound to guice context and available for injection. Also may be accessed through GuiceyConfigurationInfo.getOptions().

NOTE: service just provides info of already used options (consultation only service - for reporting). If option wasn't used then default value will not be returned (error will be thrown). Option value read will not mark option as used. Do not use it for reading option value (for actual option usage): use Options instead.

Most methods accept simple Enum instead of Enum & Option to simplify generic usage: if not allowed enum value will be used methods will throw exceptions. knowsOption(Enum) method may be used to safely check enum value before calling actual data methods.

Since:
11.08.2016
See Also:
  • Constructor Details

    • OptionsInfo

      public OptionsInfo(OptionsSupport support)
      Create info.
      Parameters:
      support - options support
  • Method Details

    • getOptions

      public <T extends Enum & Option> Set<T> getOptions()
      NOTE: as option could be accessed at any time by guice service, so more options could appear over time. As a consequence, it can't be known for sure that option is not used, for example, just after application start.
      Type Parameters:
      T - helper type to define option
      Returns:
      set of all used options (either read or set)
      See Also:
    • getOptionGroups

      public List<Class<Enum>> getOptionGroups()
      In contrast to getOptions() returns only enum types of used options. For example, GuiceyOptions is enum type for core guicey options.
      Returns:
      list of used option enums sorted by name
    • getValue

      public <V> V getValue(Enum option)
      Type Parameters:
      V - value type
      Parameters:
      option - option enum
      Returns:
      current option value (default or defined)
      Throws:
      IllegalArgumentException - if option was not used
    • isUsed

      public boolean isUsed(Enum option)
      Option usage tracked when option read by either bundle or from guice service. Option may be read in any time of application life so used value may change over time (even new options could appear for reporting).
      Parameters:
      option - option enum
      Returns:
      true if option was read, false if option set but never used
      Throws:
      IllegalArgumentException - if option was not used
    • isSet

      public boolean isSet(Enum option)
      All options are set in application (before application start) and will not change after.
      Parameters:
      option - option enum
      Returns:
      true if option was manually defined, false when default value used
      Throws:
      IllegalArgumentException - if option was not used
    • knowsOption

      public boolean knowsOption(Enum option)
      Use this method to check if option is available for reporting (option details methods will fail with exception if not known option will be provided).
      Parameters:
      option - option enum
      Returns:
      true if option registered (was used or set), false otherwise