Package org.cache2k.config
Class ToggleFeature
- java.lang.Object
-
- org.cache2k.config.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 tofalse
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 Summary
Constructors Constructor Description ToggleFeature()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static void
disable(Cache2kBuilder<?,?> builder, Class<? extends ToggleFeature> featureType)
Disable the feature by removing it from the configuration.protected abstract <K,V>
voiddoEnlist(CacheBuildContext<K,V> ctx)
static <T extends ToggleFeature>
Tenable(Cache2kBuilder<?,?> builder, Class<T> featureType)
Enable the feature in the main configuration.<K,V>
voidenlist(CacheBuildContext<K,V> ctx)
Checks whether enabled and call implementations doEnlist method.boolean
equals(@Nullable Object o)
Identical if it is the same implementation class.static <T extends ToggleFeature>
Textract(Cache2kBuilder<?,?> builder, Class<T> featureType)
Returns the feature instance, if present.int
hashCode()
Hashcode from the implementation class.boolean
isEnabled()
static boolean
isEnabled(Cache2kBuilder<?,?> builder, Class<? extends ToggleFeature> featureType)
Returns true if the feature is enabled.void
setEnable(boolean v)
Alternate setter for spelling flexibility in XML configuration.void
setEnabled(boolean v)
String
toString()
Override if this takes additional parameters.
-
-
-
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.
-
extract
@Nullable public static <T extends ToggleFeature> T extract(Cache2kBuilder<?,?> builder, Class<T> featureType)
Returns the feature instance, if present.
-
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.
-
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.
-
hashCode
public final int hashCode()
Hashcode from the implementation class.
-
-