diff --git a/src/main/java/org/elasticsearch/common/settings/ImmutableSettings.java b/src/main/java/org/elasticsearch/common/settings/ImmutableSettings.java index 7b25402bb8c..afc14f31098 100644 --- a/src/main/java/org/elasticsearch/common/settings/ImmutableSettings.java +++ b/src/main/java/org/elasticsearch/common/settings/ImmutableSettings.java @@ -324,6 +324,15 @@ public class ImmutableSettings implements Settings { } } + @Override + public String toDelimitedString(char delimiter) { + StringBuilder sb = new StringBuilder(); + for (Map.Entry entry : settings.entrySet()) { + sb.append(entry.getKey()).append("=").append(entry.getValue()).append(delimiter); + } + return sb.toString(); + } + @Override public boolean equals(Object o) { if (this == o) return true; diff --git a/src/main/java/org/elasticsearch/common/settings/Settings.java b/src/main/java/org/elasticsearch/common/settings/Settings.java index b1dce49470f..c5068e0f00a 100644 --- a/src/main/java/org/elasticsearch/common/settings/Settings.java +++ b/src/main/java/org/elasticsearch/common/settings/Settings.java @@ -245,6 +245,11 @@ public interface Settings { */ Version getAsVersion(String setting, Version defaultVersion) throws SettingsException; + /** + * Returns the settings as delimited string. + */ + String toDelimitedString(char delimiter); + /** * A settings builder interface. */ diff --git a/src/test/java/org/elasticsearch/test/unit/common/settings/ImmutableSettingsTests.java b/src/test/java/org/elasticsearch/test/unit/common/settings/ImmutableSettingsTests.java index 8811928639e..417817fec43 100644 --- a/src/test/java/org/elasticsearch/test/unit/common/settings/ImmutableSettingsTests.java +++ b/src/test/java/org/elasticsearch/test/unit/common/settings/ImmutableSettingsTests.java @@ -70,6 +70,7 @@ public class ImmutableSettingsTests { assertThat(settings.get("key1"), equalTo("value1")); assertThat(settings.get("key2"), equalTo("value2")); assertThat(settings.getAsMap().size(), equalTo(2)); + assertThat(settings.toDelimitedString(';'), equalTo("key1=value1;key2=value2;")); settings = settingsBuilder() .loadFromDelimitedString("key1=value1;key2=value2;", ';') @@ -77,6 +78,7 @@ public class ImmutableSettingsTests { assertThat(settings.get("key1"), equalTo("value1")); assertThat(settings.get("key2"), equalTo("value2")); assertThat(settings.getAsMap().size(), equalTo(2)); + assertThat(settings.toDelimitedString(';'), equalTo("key1=value1;key2=value2;")); } }