Skip to content

Commit

Permalink
introduce YAMLMapping.withReplaced()
Browse files Browse the repository at this point in the history
  • Loading branch information
nresare authored and Noa Resare committed Aug 23, 2022
1 parent bb1713f commit af9dc9c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/main/java/com/resare/nryaml/YAMLMapping.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,10 @@ public YAMLMapping combine(YAMLMapping other) {
result.putAll(other);
return new YAMLMapping(result);
}

public YAMLMapping withReplaced(String key, YAMLValue value) {
var result = new HashMap<>(this);
result.put(key, value);
return new YAMLMapping(result);
}
}
8 changes: 8 additions & 0 deletions src/test/java/com/resare/nryaml/YAMLMappingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,12 @@ void testCombine() {
mapping.toBareObject()
);
}

@Test
void testWithReplaced() {
var mapping = YAMLMapping.of("key", YAMLValue.of("first"));
var another = mapping.withReplaced("key", YAMLValue.of("second"));
assertEquals(YAMLMapping.of("key", YAMLValue.of("first")), mapping);
assertEquals(YAMLMapping.of("key", YAMLValue.of("second")), another);
}
}

0 comments on commit af9dc9c

Please sign in to comment.