Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce putAll(Properties) #22

Merged
merged 1 commit into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading