Class ToggleFeature

  • All Implemented Interfaces:
    Feature, SingleFeature

    public abstract class ToggleFeature
    extends Object
    implements SingleFeature
    Base class for a cache feature that can be enabled or disables and appears only once in the feature set. A feature can be disabled in two ways: Either by setting enabled to false or by removing it from the feature set.

    This allows enablement of features based on the users' preference: A feature can be enabled by default and then disabled per individual cache or just enabled at the individual cache level.

    Author:
    Jens Wilke
    • Constructor Detail

      • ToggleFeature

        public ToggleFeature()
    • Method Detail

      • enable

        public static <T extends ToggleFeature> T enable​(Cache2kBuilder<?,​?> builder,
                                                         Class<T> featureType)
        Enable the feature in the main configuration. If the feature is already existing it is replaced by a newly created one.
        Returns:
        the created feature to set additional parameters
      • disable

        public static void disable​(Cache2kBuilder<?,​?> builder,
                                   Class<? extends ToggleFeature> featureType)
        Disable the feature by removing it from the configuration.
      • isEnabled

        public static boolean isEnabled​(Cache2kBuilder<?,​?> builder,
                                        Class<? extends ToggleFeature> featureType)
        Returns true if the feature is enabled. Meaning, the feature instance is present and enabled.
      • enlist

        public final <K,​V> void enlist​(CacheBuildContext<K,​V> ctx)
        Checks whether enabled and call implementations doEnlist method.
        Specified by:
        enlist in interface Feature
      • doEnlist

        protected abstract <K,​V> void doEnlist​(CacheBuildContext<K,​V> ctx)
      • isEnabled

        public final boolean isEnabled()
      • setEnabled

        public final void setEnabled​(boolean v)
      • setEnable

        public final void setEnable​(boolean v)
        Alternate setter for spelling flexibility in XML configuration.
      • equals

        public final boolean equals​(@Nullable
                                    @Nullable Object o)
        Identical if it is the same implementation class. Relevant for keeping only one feature within the configuration.
        Overrides:
        equals in class Object
      • hashCode

        public final int hashCode()
        Hashcode from the implementation class.
        Overrides:
        hashCode in class Object
      • toString

        public String toString()
        Override if this takes additional parameters.
        Overrides:
        toString in class Object