Skip to content

Commit

Permalink
Introduce putAll(Properties)
Browse files Browse the repository at this point in the history
- This is useful when you need to copy all the values from a `java.util.Properties` to this structure
  • Loading branch information
gastaldi authored and quintesse committed Jul 9, 2024
1 parent 256287d commit 2fd8468
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/main/java/org/codejive/properties/Properties.java
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,18 @@ public List<PropertiesParser.Token> next() {
Spliterators.spliterator(iter, tokens.size(), Spliterator.SORTED), false);
}

/**
* Copies all entries from the <code>java.util.Properties</code> object to this object
*
* @param properties a <code>java.util.Properties</code> object
* @throws NullPointerException if the properties parameter is null
*/
public void putAll(java.util.Properties properties) {
for (Entry<Object, Object> entry : properties.entrySet()) {
put(entry.getKey().toString(), entry.getValue().toString());
}
}

/**
* Returns a <code>java.util.Properties</code> with the same contents as this object. The
* information is a copy, changes to one Properties object will not affect the other.
Expand Down
9 changes: 9 additions & 0 deletions src/test/java/org/codejive/properties/TestProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,15 @@ void testMultiDelim() throws IOException, URISyntaxException {
assertThat(sw.toString()).isEqualTo(readAll(getResource("/test-multidelim.properties")));
}

@Test
void testPutAll() {
Properties p = new Properties();
java.util.Properties ju = new java.util.Properties();
ju.setProperty("foo", "bar");
p.putAll(ju);
assertThat(p.getProperty("foo")).isEqualTo("bar");
}

private Path getResource(String name) throws URISyntaxException {
return Paths.get(getClass().getResource(name).toURI());
}
Expand Down

0 comments on commit 2fd8468

Please sign in to comment.