public class Setting<T> extends ToXContentToBytes
AbstractScopedSettings
. This class contains several utility methods that makes it straight forward
to add settings for the majority of the cases. For instance a simple boolean settings can be defined like this:
public static final Setting<Boolean>; MY_BOOLEAN = Setting.boolSetting("my.bool.setting", true, SettingsProperty.NodeScope);
To retrieve the value of the setting a Settings
object can be passed directly to the get(Settings)
method.
final boolean myBooleanValue = MY_BOOLEAN.get(settings);It's recommended to use typed settings rather than string based settings. For example adding a setting for an enum type:
public enum Color {
RED, GREEN, BLUE;
}
public static final Setting<Color> MY_BOOLEAN =
new Setting<>("my.color.setting", Color.RED.toString(), Color::valueOf, SettingsProperty.NodeScope);
Modifier and Type | Class and Description |
---|---|
static class |
Setting.AffixKey
A key that allows for static pre and suffix.
|
static class |
Setting.AffixSetting<T> |
static class |
Setting.GroupKey |
static interface |
Setting.Key |
static class |
Setting.ListKey |
static class |
Setting.Property |
static class |
Setting.SimpleKey |
ToXContent.DelegatingMapParams, ToXContent.MapParams, ToXContent.Params
Modifier and Type | Field and Description |
---|---|
protected java.util.function.Function<Settings,java.lang.String> |
defaultValue |
EMPTY_PARAMS
Constructor and Description |
---|
Setting(Setting.Key key,
java.util.function.Function<Settings,java.lang.String> defaultValue,
java.util.function.Function<java.lang.String,T> parser,
Setting.Property... properties)
Creates a new Setting instance
|
Setting(Setting.Key key,
Setting<T> fallbackSetting,
java.util.function.Function<java.lang.String,T> parser,
Setting.Property... properties)
Creates a new Setting instance
|
Setting(java.lang.String key,
java.util.function.Function<Settings,java.lang.String> defaultValue,
java.util.function.Function<java.lang.String,T> parser,
Setting.Property... properties)
Creates a new Setting instance
|
Setting(java.lang.String key,
Setting<T> fallBackSetting,
java.util.function.Function<java.lang.String,T> parser,
Setting.Property... properties)
Creates a new Setting instance
|
Setting(java.lang.String key,
java.lang.String defaultValue,
java.util.function.Function<java.lang.String,T> parser,
Setting.Property... properties)
Creates a new Setting instance
|
Modifier and Type | Method and Description |
---|---|
static <T> Setting.AffixSetting<T> |
affixKeySetting(java.lang.String prefix,
java.lang.String suffix,
java.util.function.Function<java.lang.String,Setting<T>> delegateFactory)
This setting type allows to validate settings that have the same type and a common prefix and suffix.
|
static Setting<java.lang.Boolean> |
boolSetting(java.lang.String key,
boolean defaultValue,
Setting.Property... properties) |
static Setting<java.lang.Boolean> |
boolSetting(java.lang.String key,
java.util.function.Function<Settings,java.lang.String> defaultValueFn,
Setting.Property... properties) |
static Setting<java.lang.Boolean> |
boolSetting(java.lang.String key,
Setting<java.lang.Boolean> fallbackSetting,
Setting.Property... properties) |
static Setting<ByteSizeValue> |
byteSizeSetting(java.lang.String key,
ByteSizeValue defaultValue,
ByteSizeValue minValue,
ByteSizeValue maxValue,
Setting.Property... properties) |
static Setting<ByteSizeValue> |
byteSizeSetting(java.lang.String key,
ByteSizeValue value,
Setting.Property... properties) |
static Setting<ByteSizeValue> |
byteSizeSetting(java.lang.String key,
java.util.function.Function<Settings,java.lang.String> defaultValue,
ByteSizeValue minValue,
ByteSizeValue maxValue,
Setting.Property... properties) |
static Setting<ByteSizeValue> |
byteSizeSetting(java.lang.String key,
java.util.function.Function<Settings,java.lang.String> defaultValue,
Setting.Property... properties) |
static Setting<ByteSizeValue> |
byteSizeSetting(java.lang.String key,
Setting<ByteSizeValue> fallbackSetting,
Setting.Property... properties) |
void |
diff(Settings.Builder builder,
Settings source,
Settings defaultSettings)
Add this setting to the builder if it doesn't exists in the source settings.
|
static Setting<java.lang.Double> |
doubleSetting(java.lang.String key,
double defaultValue,
double minValue,
Setting.Property... properties) |
boolean |
equals(java.lang.Object o) |
boolean |
exists(Settings settings)
Returns
true iff this setting is present in the given settings object. |
static Setting<java.lang.Float> |
floatSetting(java.lang.String key,
float defaultValue,
float minValue,
Setting.Property... properties) |
static Setting<java.lang.Float> |
floatSetting(java.lang.String key,
float defaultValue,
Setting.Property... properties) |
T |
get(Settings settings)
Returns the settings value.
|
T |
get(Settings primary,
Settings secondary)
Returns the value for this setting but falls back to the second provided settings object
|
Setting<T> |
getConcreteSetting(java.lang.String key) |
T |
getDefault(Settings settings)
Returns the default value for this setting.
|
java.lang.String |
getDefaultRaw(Settings settings)
Returns the default value string representation for this setting.
|
java.lang.String |
getKey()
Returns the settings key or a prefix if this setting is a group setting.
|
java.util.EnumSet<Setting.Property> |
getProperties()
Returns the setting properties
|
java.lang.String |
getRaw(Settings settings)
Returns the raw (string) settings value.
|
Setting.Key |
getRawKey()
Returns the original representation of a setting key.
|
static Setting<Settings> |
groupSetting(java.lang.String key,
java.util.function.Consumer<Settings> validator,
Setting.Property... properties) |
static Setting<Settings> |
groupSetting(java.lang.String key,
Setting.Property... properties) |
int |
hashCode() |
boolean |
hasIndexScope()
Returns
true if this setting has an index scope, otherwise false |
boolean |
hasNodeScope()
Returns
true if this setting has a node scope, otherwise false |
static Setting<java.lang.Integer> |
intSetting(java.lang.String key,
int defaultValue,
int minValue,
int maxValue,
Setting.Property... properties) |
static Setting<java.lang.Integer> |
intSetting(java.lang.String key,
int defaultValue,
int minValue,
Setting.Property... properties) |
static Setting<java.lang.Integer> |
intSetting(java.lang.String key,
int defaultValue,
Setting.Property... properties) |
static Setting<java.lang.Integer> |
intSetting(java.lang.String key,
Setting<java.lang.Integer> fallbackSetting,
int minValue,
Setting.Property... properties) |
boolean |
isDeprecated()
Returns
true if this setting is deprecated, otherwise false |
boolean |
isDynamic()
Returns
true if this setting is dynamically updateable, otherwise false |
boolean |
isFiltered()
Returns
true if this setting must be filtered, otherwise false |
boolean |
isFinal()
Returns
true if this setting is final, otherwise false |
boolean |
isShared()
Returns
true if this setting is shared with more than one other module or plugin, otherwise false |
static <T> Setting<java.util.List<T>> |
listSetting(java.lang.String key,
java.util.function.Function<Settings,java.util.List<java.lang.String>> defaultStringValue,
java.util.function.Function<java.lang.String,T> singleValueParser,
Setting.Property... properties) |
static <T> Setting<java.util.List<T>> |
listSetting(java.lang.String key,
java.util.List<java.lang.String> defaultStringValue,
java.util.function.Function<java.lang.String,T> singleValueParser,
Setting.Property... properties) |
static <T> Setting<java.util.List<T>> |
listSetting(java.lang.String key,
Setting<java.util.List<T>> fallbackSetting,
java.util.function.Function<java.lang.String,T> singleValueParser,
Setting.Property... properties) |
static Setting<java.lang.Long> |
longSetting(java.lang.String key,
long defaultValue,
long minValue,
Setting.Property... properties) |
boolean |
match(java.lang.String toTest)
Returns
true iff the given key matches the settings key or if this setting is a group setting if the
given key is part of the settings group. |
static Setting<ByteSizeValue> |
memorySizeSetting(java.lang.String key,
ByteSizeValue defaultValue,
Setting.Property... properties)
Creates a setting which specifies a memory size.
|
static Setting<ByteSizeValue> |
memorySizeSetting(java.lang.String key,
java.util.function.Function<Settings,java.lang.String> defaultValue,
Setting.Property... properties)
Creates a setting which specifies a memory size.
|
static Setting<ByteSizeValue> |
memorySizeSetting(java.lang.String key,
java.lang.String defaultPercentage,
Setting.Property... properties)
Creates a setting which specifies a memory size.
|
static ByteSizeValue |
parseByteSize(java.lang.String s,
ByteSizeValue minValue,
ByteSizeValue maxValue,
java.lang.String key) |
static int |
parseInt(java.lang.String s,
int minValue,
int maxValue,
java.lang.String key) |
static int |
parseInt(java.lang.String s,
int minValue,
java.lang.String key) |
static long |
parseLong(java.lang.String s,
long minValue,
java.lang.String key) |
static TimeValue |
parseTimeValue(java.lang.String s,
TimeValue minValue,
java.lang.String key) |
static Setting<TimeValue> |
positiveTimeSetting(java.lang.String key,
TimeValue defaultValue,
Setting.Property... properties) |
static <T> Setting.AffixSetting<T> |
prefixKeySetting(java.lang.String prefix,
java.util.function.Function<java.lang.String,Setting<T>> delegateFactory)
This setting type allows to validate settings that have the same type and a common prefix.
|
static Setting<java.lang.String> |
simpleString(java.lang.String key,
Setting.Property... properties) |
static Setting<TimeValue> |
timeSetting(java.lang.String key,
java.util.function.Function<Settings,TimeValue> defaultValue,
TimeValue minValue,
Setting.Property... properties) |
static Setting<TimeValue> |
timeSetting(java.lang.String key,
Setting<TimeValue> fallbackSetting,
Setting.Property... properties) |
static Setting<TimeValue> |
timeSetting(java.lang.String key,
TimeValue defaultValue,
Setting.Property... properties) |
static Setting<TimeValue> |
timeSetting(java.lang.String key,
TimeValue defaultValue,
TimeValue minValue,
Setting.Property... properties) |
XContentBuilder |
toXContent(XContentBuilder builder,
ToXContent.Params params) |
buildAsBytes, buildAsBytes, toString, toString
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
isFragment
protected final java.util.function.Function<Settings,java.lang.String> defaultValue
public Setting(Setting.Key key, java.util.function.Function<Settings,java.lang.String> defaultValue, java.util.function.Function<java.lang.String,T> parser, Setting.Property... properties)
key
- the settings key for this setting.defaultValue
- a default value function that returns the default values string representation.parser
- a parser that parses the string rep into a complex datatype.properties
- properties for this setting like scope, filtering...public Setting(java.lang.String key, java.lang.String defaultValue, java.util.function.Function<java.lang.String,T> parser, Setting.Property... properties)
key
- the settings key for this setting.defaultValue
- a default value.parser
- a parser that parses the string rep into a complex datatype.properties
- properties for this setting like scope, filtering...public Setting(java.lang.String key, java.util.function.Function<Settings,java.lang.String> defaultValue, java.util.function.Function<java.lang.String,T> parser, Setting.Property... properties)
key
- the settings key for this setting.defaultValue
- a default value function that returns the default values string representation.parser
- a parser that parses the string rep into a complex datatype.properties
- properties for this setting like scope, filtering...public Setting(Setting.Key key, Setting<T> fallbackSetting, java.util.function.Function<java.lang.String,T> parser, Setting.Property... properties)
key
- the settings key for this setting.fallbackSetting
- a setting who's value to fallback on if this setting is not definedparser
- a parser that parses the string rep into a complex datatype.properties
- properties for this setting like scope, filtering...public Setting(java.lang.String key, Setting<T> fallBackSetting, java.util.function.Function<java.lang.String,T> parser, Setting.Property... properties)
key
- the settings key for this setting.fallBackSetting
- a setting to fall back to if the current setting is not set.parser
- a parser that parses the string rep into a complex datatype.properties
- properties for this setting like scope, filtering...public final java.lang.String getKey()
Settings
object.
Use get(Settings)
insteadisGroupSetting()
public final Setting.Key getRawKey()
public final boolean isDynamic()
true
if this setting is dynamically updateable, otherwise false
public final boolean isFinal()
true
if this setting is final, otherwise false
public java.util.EnumSet<Setting.Property> getProperties()
Setting.Property
public boolean isFiltered()
true
if this setting must be filtered, otherwise false
public boolean hasNodeScope()
true
if this setting has a node scope, otherwise false
public boolean hasIndexScope()
true
if this setting has an index scope, otherwise false
public boolean isDeprecated()
true
if this setting is deprecated, otherwise false
public boolean isShared()
true
if this setting is shared with more than one other module or plugin, otherwise false
public java.lang.String getDefaultRaw(Settings settings)
settings
- a settings object for settings that has a default value depending on another setting if availablepublic T getDefault(Settings settings)
settings
- a settings object for settings that has a default value depending on another setting if availablepublic boolean exists(Settings settings)
true
iff this setting is present in the given settings object. Otherwise false
public T get(Settings settings)
public void diff(Settings.Builder builder, Settings source, Settings defaultSettings)
builder
- the settings builder to fill the diff intosource
- the source settings object to diffdefaultSettings
- the default settings object to diff againstpublic java.lang.String getRaw(Settings settings)
public final boolean match(java.lang.String toTest)
true
iff the given key matches the settings key or if this setting is a group setting if the
given key is part of the settings group.isGroupSetting()
public final XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params params) throws java.io.IOException
java.io.IOException
public final T get(Settings primary, Settings secondary)
public static Setting<java.lang.Float> floatSetting(java.lang.String key, float defaultValue, Setting.Property... properties)
public static Setting<java.lang.Float> floatSetting(java.lang.String key, float defaultValue, float minValue, Setting.Property... properties)
public static Setting<java.lang.Integer> intSetting(java.lang.String key, int defaultValue, int minValue, int maxValue, Setting.Property... properties)
public static Setting<java.lang.Integer> intSetting(java.lang.String key, int defaultValue, int minValue, Setting.Property... properties)
public static Setting<java.lang.Integer> intSetting(java.lang.String key, Setting<java.lang.Integer> fallbackSetting, int minValue, Setting.Property... properties)
public static Setting<java.lang.Long> longSetting(java.lang.String key, long defaultValue, long minValue, Setting.Property... properties)
public static Setting<java.lang.String> simpleString(java.lang.String key, Setting.Property... properties)
public static int parseInt(java.lang.String s, int minValue, java.lang.String key)
public static int parseInt(java.lang.String s, int minValue, int maxValue, java.lang.String key)
public static long parseLong(java.lang.String s, long minValue, java.lang.String key)
public static TimeValue parseTimeValue(java.lang.String s, TimeValue minValue, java.lang.String key)
public static Setting<java.lang.Integer> intSetting(java.lang.String key, int defaultValue, Setting.Property... properties)
public static Setting<java.lang.Boolean> boolSetting(java.lang.String key, boolean defaultValue, Setting.Property... properties)
public static Setting<java.lang.Boolean> boolSetting(java.lang.String key, Setting<java.lang.Boolean> fallbackSetting, Setting.Property... properties)
public static Setting<java.lang.Boolean> boolSetting(java.lang.String key, java.util.function.Function<Settings,java.lang.String> defaultValueFn, Setting.Property... properties)
public static Setting<ByteSizeValue> byteSizeSetting(java.lang.String key, ByteSizeValue value, Setting.Property... properties)
public static Setting<ByteSizeValue> byteSizeSetting(java.lang.String key, Setting<ByteSizeValue> fallbackSetting, Setting.Property... properties)
public static Setting<ByteSizeValue> byteSizeSetting(java.lang.String key, java.util.function.Function<Settings,java.lang.String> defaultValue, Setting.Property... properties)
public static Setting<ByteSizeValue> byteSizeSetting(java.lang.String key, ByteSizeValue defaultValue, ByteSizeValue minValue, ByteSizeValue maxValue, Setting.Property... properties)
public static Setting<ByteSizeValue> byteSizeSetting(java.lang.String key, java.util.function.Function<Settings,java.lang.String> defaultValue, ByteSizeValue minValue, ByteSizeValue maxValue, Setting.Property... properties)
public static ByteSizeValue parseByteSize(java.lang.String s, ByteSizeValue minValue, ByteSizeValue maxValue, java.lang.String key)
public static Setting<ByteSizeValue> memorySizeSetting(java.lang.String key, ByteSizeValue defaultValue, Setting.Property... properties)
key
- the key for the settingdefaultValue
- the default value for this settingproperties
- properties properties for this setting like scope, filtering...public static Setting<ByteSizeValue> memorySizeSetting(java.lang.String key, java.util.function.Function<Settings,java.lang.String> defaultValue, Setting.Property... properties)
key
- the key for the settingdefaultValue
- a function that supplies the default value for this settingproperties
- properties properties for this setting like scope, filtering...public static Setting<ByteSizeValue> memorySizeSetting(java.lang.String key, java.lang.String defaultPercentage, Setting.Property... properties)
key
- the key for the settingdefaultPercentage
- the default value of this setting as a percentage of the heap memoryproperties
- properties properties for this setting like scope, filtering...public static <T> Setting<java.util.List<T>> listSetting(java.lang.String key, java.util.List<java.lang.String> defaultStringValue, java.util.function.Function<java.lang.String,T> singleValueParser, Setting.Property... properties)
public static <T> Setting<java.util.List<T>> listSetting(java.lang.String key, Setting<java.util.List<T>> fallbackSetting, java.util.function.Function<java.lang.String,T> singleValueParser, Setting.Property... properties)
public static <T> Setting<java.util.List<T>> listSetting(java.lang.String key, java.util.function.Function<Settings,java.util.List<java.lang.String>> defaultStringValue, java.util.function.Function<java.lang.String,T> singleValueParser, Setting.Property... properties)
public static Setting<Settings> groupSetting(java.lang.String key, Setting.Property... properties)
public static Setting<Settings> groupSetting(java.lang.String key, java.util.function.Consumer<Settings> validator, Setting.Property... properties)
public static Setting<TimeValue> timeSetting(java.lang.String key, java.util.function.Function<Settings,TimeValue> defaultValue, TimeValue minValue, Setting.Property... properties)
public static Setting<TimeValue> timeSetting(java.lang.String key, TimeValue defaultValue, TimeValue minValue, Setting.Property... properties)
public static Setting<TimeValue> timeSetting(java.lang.String key, TimeValue defaultValue, Setting.Property... properties)
public static Setting<TimeValue> timeSetting(java.lang.String key, Setting<TimeValue> fallbackSetting, Setting.Property... properties)
public static Setting<TimeValue> positiveTimeSetting(java.lang.String key, TimeValue defaultValue, Setting.Property... properties)
public static Setting<java.lang.Double> doubleSetting(java.lang.String key, double defaultValue, double minValue, Setting.Property... properties)
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public static <T> Setting.AffixSetting<T> prefixKeySetting(java.lang.String prefix, java.util.function.Function<java.lang.String,Setting<T>> delegateFactory)
getConcreteSetting(String)
is used to pull the updater.public static <T> Setting.AffixSetting<T> affixKeySetting(java.lang.String prefix, java.lang.String suffix, java.util.function.Function<java.lang.String,Setting<T>> delegateFactory)
getConcreteSetting(String)
is used to pull the updater.