diff --git a/src/main/java/org/codejive/properties/Properties.java b/src/main/java/org/codejive/properties/Properties.java index 2544a33..3f28fa9 100644 --- a/src/main/java/org/codejive/properties/Properties.java +++ b/src/main/java/org/codejive/properties/Properties.java @@ -773,6 +773,18 @@ public List next() { Spliterators.spliterator(iter, tokens.size(), Spliterator.SORTED), false); } + /** + * Copies all entries from the java.util.Properties object to this object + * + * @param properties a java.util.Properties object + * @throws NullPointerException if the properties parameter is null + */ + public void putAll(java.util.Properties properties) { + for (Entry entry : properties.entrySet()) { + put(entry.getKey().toString(), entry.getValue().toString()); + } + } + /** * Returns a java.util.Properties with the same contents as this object. The * information is a copy, changes to one Properties object will not affect the other. diff --git a/src/test/java/org/codejive/properties/TestProperties.java b/src/test/java/org/codejive/properties/TestProperties.java index 4c51c72..43304e1 100644 --- a/src/test/java/org/codejive/properties/TestProperties.java +++ b/src/test/java/org/codejive/properties/TestProperties.java @@ -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()); }