java.lang.Object
org.elasticsearch.common.settings.Settings
All Implemented Interfaces:
Diffable<Settings>, Writeable, ToXContent, ToXContentFragment

public final class Settings extends Object implements ToXContentFragment, Writeable, Diffable<Settings>
An immutable settings implementation.
  • Field Details

  • Method Details

    • getByPrefix

      public Settings getByPrefix(String prefix)
      A settings that are filtered (and key is removed) with the specified prefix.
    • filter

      public Settings filter(Predicate<String> predicate)
      Returns a new settings object that contains all setting of the current one filtered by the given settings key predicate.
    • getAsSettings

      public Settings getAsSettings(String setting)
      Returns the settings mapped to the given setting name.
    • get

      public String get(String setting)
      Returns the setting value associated with the setting key.
      Parameters:
      setting - The setting key
      Returns:
      The setting value, null if it does not exists.
    • get

      public String get(String setting, String defaultValue)
      Returns the setting value associated with the setting key. If it does not exists, returns the default value provided.
    • getAsFloat

      public Float getAsFloat(String setting, Float defaultValue)
      Returns the setting value (as float) associated with the setting key. If it does not exists, returns the default value provided.
    • getAsDouble

      public Double getAsDouble(String setting, Double defaultValue)
      Returns the setting value (as double) associated with the setting key. If it does not exists, returns the default value provided.
    • getAsInt

      public Integer getAsInt(String setting, Integer defaultValue)
      Returns the setting value (as int) associated with the setting key. If it does not exists, returns the default value provided.
    • getAsLong

      public Long getAsLong(String setting, Long defaultValue)
      Returns the setting value (as long) associated with the setting key. If it does not exists, returns the default value provided.
    • hasValue

      public boolean hasValue(String key)
      Returns true iff the given key has a value in this settings object
    • getAsBoolean

      public Boolean getAsBoolean(String setting, Boolean defaultValue)
      Returns the setting value (as boolean) associated with the setting key. If it does not exists, returns the default value provided.
    • getAsTime

      public TimeValue getAsTime(String setting, TimeValue defaultValue)
      Returns the setting value (as time) associated with the setting key. If it does not exists, returns the default value provided.
    • getAsBytesSize

      public ByteSizeValue getAsBytesSize(String setting, ByteSizeValue defaultValue) throws SettingsException
      Returns the setting value (as size) associated with the setting key. If it does not exists, returns the default value provided.
      Throws:
      SettingsException
    • getAsMemory

      public ByteSizeValue getAsMemory(String setting, String defaultValue) throws SettingsException
      Returns the setting value (as size) associated with the setting key. Provided values can either be absolute values (interpreted as a number of bytes), byte sizes (eg. 1mb) or percentage of the heap size (eg. 12%). If it does not exists, parses the default value provided.
      Throws:
      SettingsException
    • getAsList

      public List<String> getAsList(String key) throws SettingsException
      The values associated with a setting key as an immutable list.

      It will also automatically load a comma separated list under the settingPrefix and merge with the numbered format.

      Parameters:
      key - The setting key to load the list by
      Returns:
      The setting list values
      Throws:
      SettingsException
    • getAsList

      public List<String> getAsList(String key, List<String> defaultValue) throws SettingsException
      The values associated with a setting key as an immutable list.

      If commaDelimited is true, it will automatically load a comma separated list under the settingPrefix and merge with the numbered format.

      Parameters:
      key - The setting key to load the list by
      Returns:
      The setting list values
      Throws:
      SettingsException
    • getAsList

      public List<String> getAsList(String key, List<String> defaultValue, Boolean commaDelimited) throws SettingsException
      The values associated with a setting key as an immutable list.

      It will also automatically load a comma separated list under the settingPrefix and merge with the numbered format.

      Parameters:
      key - The setting key to load the list by
      defaultValue - The default value to use if no value is specified
      commaDelimited - Whether to try to parse a string as a comma-delimited value
      Returns:
      The setting list values
      Throws:
      SettingsException
    • getGroups

      public Map<String,Settings> getGroups(String settingPrefix) throws SettingsException
      Returns group settings for the given setting prefix.
      Throws:
      SettingsException
    • getGroups

      public Map<String,Settings> getGroups(String settingPrefix, boolean ignoreNonGrouped) throws SettingsException
      Returns group settings for the given setting prefix.
      Throws:
      SettingsException
    • getAsGroups

      public Map<String,Settings> getAsGroups() throws SettingsException
      Returns group settings for the given setting prefix.
      Throws:
      SettingsException
    • getAsVersionId

      public <T extends VersionId<T>> T getAsVersionId(String setting, IntFunction<T> parseVersion) throws SettingsException
      Returns a parsed version.
      Throws:
      SettingsException
    • getAsVersionId

      public <T extends VersionId<T>> T getAsVersionId(String setting, IntFunction<T> parseVersion, T defaultVersion) throws SettingsException
      Returns a parsed version.
      Throws:
      SettingsException
    • names

      public Set<String> names()
      Returns:
      The direct keys of this settings
    • toDelimitedString

      public String toDelimitedString(char delimiter)
      Returns the settings as delimited string.
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • readSettingsFromStream

      public static Settings readSettingsFromStream(StreamInput in) throws IOException
      Throws:
      IOException
    • readSettingsDiffFromStream

      public static Diff<Settings> readSettingsDiffFromStream(StreamInput in) throws IOException
      Throws:
      IOException
    • diff

      public Diff<Settings> diff(Settings previousState)
      Description copied from interface: Diffable
      Returns serializable object representing differences between this and previousState
      Specified by:
      diff in interface Diffable<Settings>
    • writeTo

      public void writeTo(StreamOutput out) throws IOException
      Description copied from interface: Writeable
      Write this into the StreamOutput.
      Specified by:
      writeTo in interface Writeable
      Throws:
      IOException
    • builder

      public static Settings.Builder builder()
      Returns a builder to be used in order to build settings.
    • toXContent

      public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params params) throws IOException
      Specified by:
      toXContent in interface ToXContent
      Throws:
      IOException
    • fromXContent

      public static Settings fromXContent(XContentParser parser) throws IOException
      Parsers the generated xcontent from toXContent(XContentBuilder, Params) into a new Settings object. Note this method requires the parser to either be positioned on a null token or on XContentParser.Token.START_OBJECT.
      Throws:
      IOException
    • isEmpty

      public boolean isEmpty()
      Returns true if this settings object contains no settings
      Returns:
      true if this settings object contains no settings
    • size

      public int size()
      Returns the number of settings in this settings object.
    • keySet

      public Set<String> keySet()
      Returns the fully qualified setting names contained in this settings object.
    • toString

      public String toString()
      Overrides:
      toString in class Object