allow to get settings as delimited string
This commit is contained in:
parent
b143822bac
commit
c2f35621f6
|
@ -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;
|
||||||
|
|
|
@ -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.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -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;"));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue