Skip to content

Commit 2fd8468

Browse files
gastaldiquintesse
authored andcommitted
Introduce putAll(Properties)
- This is useful when you need to copy all the values from a `java.util.Properties` to this structure
1 parent 256287d commit 2fd8468

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/main/java/org/codejive/properties/Properties.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -773,6 +773,18 @@ public List<PropertiesParser.Token> next() {
773773
Spliterators.spliterator(iter, tokens.size(), Spliterator.SORTED), false);
774774
}
775775

776+
/**
777+
* Copies all entries from the <code>java.util.Properties</code> object to this object
778+
*
779+
* @param properties a <code>java.util.Properties</code> object
780+
* @throws NullPointerException if the properties parameter is null
781+
*/
782+
public void putAll(java.util.Properties properties) {
783+
for (Entry<Object, Object> entry : properties.entrySet()) {
784+
put(entry.getKey().toString(), entry.getValue().toString());
785+
}
786+
}
787+
776788
/**
777789
* Returns a <code>java.util.Properties</code> with the same contents as this object. The
778790
* information is a copy, changes to one Properties object will not affect the other.

src/test/java/org/codejive/properties/TestProperties.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,15 @@ void testMultiDelim() throws IOException, URISyntaxException {
691691
assertThat(sw.toString()).isEqualTo(readAll(getResource("/test-multidelim.properties")));
692692
}
693693

694+
@Test
695+
void testPutAll() {
696+
Properties p = new Properties();
697+
java.util.Properties ju = new java.util.Properties();
698+
ju.setProperty("foo", "bar");
699+
p.putAll(ju);
700+
assertThat(p.getProperty("foo")).isEqualTo("bar");
701+
}
702+
694703
private Path getResource(String name) throws URISyntaxException {
695704
return Paths.get(getClass().getResource(name).toURI());
696705
}

0 commit comments

Comments
 (0)