allow to get settings as delimited string

This commit is contained in:
Shay Banon 2013-01-24 12:03:16 +01:00
parent b143822bac
commit c2f35621f6
3 changed files with 16 additions and 0 deletions

View File

@ -324,6 +324,15 @@ public class ImmutableSettings implements Settings {
} }
} }
@Override
public String toDelimitedString(char delimiter) {
StringBuilder sb = new StringBuilder();
for (Map.Entry<String, String> entry : settings.entrySet()) {
sb.append(entry.getKey()).append("=").append(entry.getValue()).append(delimiter);
}
return sb.toString();
}
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (this == o) return true; if (this == o) return true;

View File

@ -245,6 +245,11 @@ public interface Settings {
*/ */
Version getAsVersion(String setting, Version defaultVersion) throws SettingsException; Version getAsVersion(String setting, Version defaultVersion) throws SettingsException;
/**
* Returns the settings as delimited string.
*/
String toDelimitedString(char delimiter);
/** /**
* A settings builder interface. * A settings builder interface.
*/ */

View File

@ -70,6 +70,7 @@ public class ImmutableSettingsTests {
assertThat(settings.get("key1"), equalTo("value1")); assertThat(settings.get("key1"), equalTo("value1"));
assertThat(settings.get("key2"), equalTo("value2")); assertThat(settings.get("key2"), equalTo("value2"));
assertThat(settings.getAsMap().size(), equalTo(2)); assertThat(settings.getAsMap().size(), equalTo(2));
assertThat(settings.toDelimitedString(';'), equalTo("key1=value1;key2=value2;"));
settings = settingsBuilder() settings = settingsBuilder()
.loadFromDelimitedString("key1=value1;key2=value2;", ';') .loadFromDelimitedString("key1=value1;key2=value2;", ';')
@ -77,6 +78,7 @@ public class ImmutableSettingsTests {
assertThat(settings.get("key1"), equalTo("value1")); assertThat(settings.get("key1"), equalTo("value1"));
assertThat(settings.get("key2"), equalTo("value2")); assertThat(settings.get("key2"), equalTo("value2"));
assertThat(settings.getAsMap().size(), equalTo(2)); assertThat(settings.getAsMap().size(), equalTo(2));
assertThat(settings.toDelimitedString(';'), equalTo("key1=value1;key2=value2;"));
} }
} }